{"id":75,"date":"2026-06-29T21:03:12","date_gmt":"2026-06-29T13:03:12","guid":{"rendered":"https:\/\/genetop.top\/index.php\/2026\/06\/29\/agent-react-inside\/"},"modified":"2026-06-29T21:03:12","modified_gmt":"2026-06-29T13:03:12","slug":"agent-react-inside","status":"publish","type":"post","link":"https:\/\/genetop.top\/index.php\/2026\/06\/29\/agent-react-inside\/","title":{"rendered":"ReAct Inside \u2014\u2014 \u4ece Message \u5230 State\uff0c\u770b\u61c2 AI Agent \u7684\u5de5\u4f5c\u539f\u7406"},"content":{"rendered":"<blockquote>\n<p>\u5f88\u591a\u4eba\u7b2c\u4e00\u6b21\u63a5\u89e6 ReAct\uff08Reason + Act\uff09\u65f6\uff0c\u4f1a\u4ee5\u4e3a\u5b83\u53ea\u662f\u5728 Prompt \u91cc\u52a0\u4e86 <code>Thought \/ Action \/ Observation<\/code> \u4e09\u4e2a\u5b57\u6bb5\u3002<\/p>\n<p>\u4f46\u5b9e\u9645\u4e0a\uff0cReAct \u7684\u6838\u5fc3\u5e76\u4e0d\u662f Prompt \u683c\u5f0f\uff0c\u800c\u662f <strong>Agent \u7684\u72b6\u6001\u673a\uff08State Machine\uff09<\/strong>\u3002<\/p>\n<p>\u672c\u6587\u4ece\u5de5\u7a0b\u5b9e\u73b0\u7684\u89d2\u5ea6\uff0c\u8bb2\u6e05\u695a ReAct \u5728 LLM \u5185\u90e8\u5230\u5e95\u662f\u600e\u4e48\u8fd0\u8f6c\u7684\uff0c\u4ee5\u53ca\u5b83\u548c\u73b0\u4ee3 Function Calling\u3001Tool Calling \u4e4b\u95f4\u7684\u5173\u7cfb\u3002<\/p>\n<\/blockquote>\n<h1 id=\"react\">\u4e00\u3001\u4ec0\u4e48\u662f ReAct\uff1f<\/h1>\n<p>ReAct\uff08Reason + Act\uff09\u51fa\u81ea 2022 \u5e74\u7684\u8bba\u6587\u300aReAct: Synergizing Reasoning and Acting in Language Models\u300b\uff0c\u4f5c\u8005\u662f Shunyu Yao \u7b49\u4eba\uff0c\u7531\u666e\u6797\u65af\u987f\u5927\u5b66\u4e0e Google Research \u5408\u4f5c\u5b8c\u6210\u3002<\/p>\n<p>\u5b83\u7684\u6838\u5fc3\u601d\u60f3\u5176\u5b9e\u5f88\u7b80\u5355\uff1a<\/p>\n<blockquote>\n<p><strong>\u8ba9 LLM \u5728\u63a8\u7406\uff08Reason\uff09\u7684\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u4ee5\u968f\u65f6\u8c03\u7528\u5916\u90e8\u5de5\u5177\uff08Act\uff09\uff0c\u518d\u62ff\u5de5\u5177\u8fd4\u56de\u7684\u4fe1\u606f\u7ee7\u7eed\u63a8\u7406\u3002<\/strong><\/p>\n<\/blockquote>\n<p>\u6253\u4e2a\u6bd4\u65b9\u3002\u4f20\u7edf LLM \u50cf\u4e00\u4e2a\u95ed\u5377\u8003\u8bd5\u7684\u5b66\u751f\uff0c\u9898\u76ee\u4e00\u7ed9\uff0c\u51ed\u8111\u5b50\u91cc\u8bb0\u4f4f\u7684\u4e1c\u897f\u4e00\u53e3\u6c14\u628a\u7b54\u6848\u5199\u5b8c\uff1a<\/p>\n<pre><code>User\n    \u2502\n    \u25bc\nLLM\n    \u2502\n    \u25bc\nAnswer\n<\/code><\/pre>\n<p>ReAct \u5219\u50cf\u4e00\u4e2a\u5f00\u5377\u3001\u8fd8\u80fd\u4e0a\u7f51\u67e5\u8d44\u6599\u7684\u5b66\u751f\u3002\u9047\u5230\u4e0d\u786e\u5b9a\u7684\u5730\u65b9\uff0c\u4ed6\u4f1a\u5148\u60f3&#8221;\u6211\u5f97\u67e5\u4e00\u4e0b&#8221;\uff0c\u53bb\u7ffb\u4e66\u3001\u67e5\u5929\u6c14\u3001\u7b97\u4e00\u7b14\u8d26\uff0c\u62ff\u5230\u7ed3\u679c\u518d\u63a5\u7740\u5f80\u4e0b\u5199\uff1a<\/p>\n<pre><code>User\n    \u2502\n    \u25bc\nLLM\n    \u2502\nThought      \u2190 \u6211\u8be5\u505a\u4ec0\u4e48\n    \u2502\nAction       \u2190 \u6211\u53bb\u67e5\u5929\u6c14\n    \u2502\nTool         \u2190 \u5de5\u5177\u771f\u6b63\u6267\u884c\n    \u2502\nObservation  \u2190 \u67e5\u5230\u7684\u7ed3\u679c\n    \u2502\nLLM\n    \u2502\nThought      \u2190 \u6839\u636e\u7ed3\u679c\u7ee7\u7eed\u60f3\n    \u2502\nAnswer\n<\/code><\/pre>\n<p>\u5b83\u6700\u5927\u7684\u6539\u53d8\u662f\uff1a<\/p>\n<blockquote>\n<p><strong>\u6a21\u578b\u4e0d\u518d\u4e00\u6b21\u6027\u5410\u51fa\u6700\u7ec8\u7b54\u6848\uff0c\u800c\u662f\u53ef\u4ee5&#8221;\u601d\u8003 \u2192 \u6267\u884c \u2192 \u62ff\u5230\u53cd\u9988 \u2192 \u518d\u601d\u8003&#8221;\u3002<\/strong><\/p>\n<\/blockquote>\n<h1 id=\"_1\">\u4e8c\u3001\u5f88\u591a\u4eba\u6700\u5927\u7684\u8bef\u89e3<\/h1>\n<p>\u51e0\u4e4e\u6240\u6709\u5165\u95e8\u6587\u7ae0\u90fd\u4f1a\u753b\u8fd9\u6837\u4e00\u5f20\u56fe\uff1a<\/p>\n<pre><code>Thought\n   \u2193\nAction\n   \u2193\nObservation\n<\/code><\/pre>\n<p>\u4e8e\u662f\u5f88\u591a\u4eba\u5f97\u51fa\u4e24\u4e2a\u7ed3\u8bba\uff1a<\/p>\n<ul>\n<li>Observation \u662f Action \u7684\u4e00\u90e8\u5206\uff1b<\/li>\n<li>Thought\u3001Action\u3001Observation \u90fd\u53ea\u662f Prompt \u91cc\u7684\u4e0d\u540c\u5b57\u6bb5\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e24\u4e2a\u7ed3\u8bba\u90fd\u4e0d\u51c6\u786e\u3002<\/p>\n<p>\u8981\u8bb2\u6e05\u695a\uff0c\u5f97\u5148\u533a\u5206\u4e24\u4e2a\u5b8c\u5168\u4e0d\u540c\u7684\u6982\u5ff5\uff1a<\/p>\n<ul>\n<li><strong>Message\uff08\u6d88\u606f\uff09<\/strong>\uff1aAgent \u548c\u5916\u754c\u4e4b\u95f4\u771f\u6b63\u4f20\u9012\u7684\u4e1c\u897f\uff0c\u662f\u901a\u4fe1\u534f\u8bae\u3002<\/li>\n<li><strong>State\uff08\u72b6\u6001\uff09<\/strong>\uff1aAgent \u8111\u5b50\u91cc\u7684\u5185\u90e8\u72b6\u6001\uff0c\u63cf\u8ff0\u5b83&#8221;\u60f3\u5230\u54ea\u4e00\u6b65\u4e86&#8221;\u3002<\/li>\n<\/ul>\n<p>\u540e\u9762\u51e0\u8282\uff0c\u6211\u4eec\u5c31\u987a\u7740\u8fd9\u4e24\u4e2a\u6982\u5ff5\u628a\u95ee\u9898\u62c6\u5f00\u3002<\/p>\n<h1 id=\"message-react\">\u4e09\u3001\u4ece Message \u7684\u89d2\u5ea6\u770b ReAct<\/h1>\n<p>\u5047\u8bbe\u7528\u6237\u95ee\u4e86\u4e00\u4e2a\u5f88\u65e5\u5e38\u7684\u95ee\u9898\uff1a<\/p>\n<blockquote>\n<p>\u4e0a\u6d77\u4eca\u5929\u9002\u5408\u8dd1\u6b65\u5417\uff1f<\/p>\n<\/blockquote>\n<p>\u5728\u6574\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u771f\u6b63\u4ea7\u751f\u7684 Message \u662f\u8fd9\u51e0\u6761\uff1a<\/p>\n<pre><code>User Message                \u2190 \u7528\u6237\uff1a\u4e0a\u6d77\u4eca\u5929\u9002\u5408\u8dd1\u6b65\u5417\uff1f\n        \u2502\n        \u25bc\nAssistant Message #1        \u2190 \u6a21\u578b\u8f93\u51fa\n        \u2502\n        \u251c\u2500\u2500 Thought          \u6211\u5f97\u5148\u67e5\u4e00\u4e0b\u5929\u6c14\n        \u2514\u2500\u2500 Action(weather)  \u8c03\u7528 weather(&quot;Shanghai&quot;)\n        \u2502\n        \u25bc\nTool Message                \u2190 \u5de5\u5177\u8fd4\u56de\n        \u2502\n        \u2514\u2500\u2500 Observation      26\u2103\uff0c\u6e7f\u5ea6 90%\uff0c\u6709\u96e8\n        \u2502\n        \u25bc\nAssistant Message #2        \u2190 \u6a21\u578b\u518d\u6b21\u8f93\u51fa\n        \u2502\n        \u251c\u2500\u2500 Thought          \u4e0b\u96e8\u53c8\u6f6e\u6e7f\uff0c\u4e0d\u592a\u9002\u5408\n        \u2514\u2500\u2500 Final Answer     \u4e0d\u592a\u5efa\u8bae\uff0c\u4eca\u5929\u6709\u96e8\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u6709\u4e24\u4e2a\u5173\u952e\u70b9\uff1a<\/p>\n<ul>\n<li><strong>Thought \u548c Action \u901a\u5e38\u5728\u540c\u4e00\u6761 Assistant Message \u91cc<\/strong>\uff0c\u5b83\u4eec\u662f\u6a21\u578b\u4e00\u6b21\u8f93\u51fa\u7684\u4e24\u4e2a\u90e8\u5206\u3002<\/li>\n<li><strong>Observation \u4e0d\u662f\u6a21\u578b\u8f93\u51fa\u7684<\/strong>\uff0c\u5b83\u662f Tool \u8fd4\u56de\u7684\u4e00\u6761\u72ec\u7acb Message\u3002<\/li>\n<\/ul>\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0c\u4ece Message \u7684\u5c42\u9762\u770b\uff0c\u53c2\u4e0e\u5bf9\u8bdd\u7684\u53ea\u6709\u4e09\u7c7b\u89d2\u8272\uff1aUser\u3001Assistant\u3001Tool\u3002<\/p>\n<h1 id=\"observation\">\u56db\u3001\u4e3a\u4ec0\u4e48 Observation \u5fc5\u987b\u72ec\u7acb\u6210\u4e00\u6761\u6d88\u606f\uff1f<\/h1>\n<p>\u5148\u8bf4\u4e00\u4e2a\u5bb9\u6613\u6df7\u6dc6\u7684\u70b9\uff1a\u4ece<strong>\u5185\u5bb9<\/strong>\u4e0a\u770b\uff0cObservation \u786e\u5b9e\u5c31\u662f Action \u7684\u8fd4\u56de\u503c\u3002<\/p>\n<p>\u6bd4\u5982\u6a21\u578b\u53d1\u51fa\u52a8\u4f5c\uff1a<\/p>\n<pre><code>Action: weather(&quot;Shanghai&quot;)\n<\/code><\/pre>\n<p>\u5de5\u5177\u6267\u884c\u540e\u8fd4\u56de\uff1a<\/p>\n<pre><code>26\u2103\nHumidity: 90%\nRain: true\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u8fd4\u56de\uff0c\u5c31\u662f Observation\u3002<\/p>\n<p>\u90a3\u65e2\u7136\u5185\u5bb9\u4e0a\u662f\u4e00\u56de\u4e8b\uff0c\u8bba\u6587\u4e3a\u4ec0\u4e48\u8fd8\u8981\u628a Observation \u5355\u72ec\u62ce\u51fa\u6765\uff1f<\/p>\n<p>\u5173\u952e\u4e0d\u5728\u5185\u5bb9\uff0c\u800c\u5728 <strong>\u6765\u6e90<\/strong>\uff1a<\/p>\n<pre><code>Assistant\n    \u2502\n    \u2514\u2500\u2500 Action       \u6765\u81ea\u6a21\u578b\uff08\u6a21\u578b&quot;\u60f3\u8981&quot;\u505a\u4ec0\u4e48\uff09\n\nTool\n    \u2502\n    \u2514\u2500\u2500 Observation  \u6765\u81ea\u5916\u90e8\u4e16\u754c\uff08\u771f\u5b9e\u53d1\u751f\u4e86\u4ec0\u4e48\uff09\n<\/code><\/pre>\n<p>Action \u6765\u81ea\u6a21\u578b\uff0cObservation \u6765\u81ea\u771f\u5b9e\u73af\u5883\uff0c\u4e8c\u8005\u7edd\u5bf9\u4e0d\u80fd\u7531\u540c\u4e00\u4e2a\u89d2\u8272\u751f\u6210\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u8f83\u771f\uff1f\u56e0\u4e3a\u5982\u679c Observation \u4e5f\u7531\u6a21\u578b\u81ea\u5df1\u5199\uff0c\u6a21\u578b\u5c31\u80fd<strong>\u5047\u88c5\u5de5\u5177\u5df2\u7ecf\u6267\u884c\u6210\u529f<\/strong>\uff0c\u7f16\u9020\u4e00\u4e2a\u6839\u672c\u6ca1\u53d1\u751f\u7684\u7ed3\u679c\u3002<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5047\u8bbe\u8fd9\u662f\u6a21\u578b\u81ea\u5df1\u4e00\u53e3\u6c14\u5199\u51fa\u6765\u7684\uff1a<\/p>\n<pre><code>Action:\nSearch(&quot;Apple CEO&quot;)\n\nObservation:\nTim Cook\n<\/code><\/pre>\n<p>\u5982\u679c Observation \u4e5f\u662f\u6a21\u578b\u751f\u6210\u7684\uff0c\u90a3\u5b83\u5b8c\u5168\u53ef\u4ee5\u778e\u7f16 \u2014\u2014 \u54ea\u6015\u641c\u7d22\u538b\u6839\u6ca1\u6267\u884c\uff0c\u5b83\u4e5f\u80fd&#8221;\u67e5\u5230&#8221;\u4e00\u4e2a\u540d\u5b57\uff0c\u751a\u81f3\u7f16\u51fa\u4e00\u4e2a\u9519\u8bef\u7b54\u6848\u3002<\/p>\n<p>\u6240\u4ee5\u73b0\u4ee3 Agent \u4e00\u5b9a\u4f1a\u628a\u5de5\u5177\u7684\u771f\u5b9e\u8fd4\u56de\uff0c\u4f5c\u4e3a\u4e00\u6761<strong>\u72ec\u7acb Message<\/strong> \u63d2\u56de\u4e0a\u4e0b\u6587\u3002\u8fd9\u6837\u6a21\u578b\u624d\u88ab\u8feb\u9762\u5bf9\u771f\u5b9e\u7ed3\u679c\uff0c\u800c\u4e0d\u662f\u81ea\u8bf4\u81ea\u8bdd\u3002<\/p>\n<h1 id=\"thought-action\">\u4e94\u3001\u4e3a\u4ec0\u4e48 Thought \u548c Action \u53c8\u8981\u5206\u5f00\uff1f<\/h1>\n<p>\u8fd9\u662f\u53e6\u4e00\u4e2a\u5bb9\u6613\u7ed5\u6655\u7684\u5730\u65b9\u3002<\/p>\n<p>\u65e2\u7136 Thought \u548c Action \u5728\u540c\u4e00\u6761 Assistant Message \u91cc\uff1a<\/p>\n<pre><code>Assistant Message\n    Thought\n    Action\n<\/code><\/pre>\n<p>\u8bba\u6587\u4e3a\u4ec0\u4e48\u8fd8\u8981\u628a\u5b83\u4eec\u62c6\u5f00\u8bb2\uff1f<\/p>\n<p>\u539f\u56e0\u8fd8\u662f\u56de\u5230\u90a3\u4e24\u4e2a\u6982\u5ff5\uff1a<\/p>\n<ul>\n<li><strong>Message \u662f\u901a\u4fe1\u534f\u8bae<\/strong> \u2014\u2014 \u63cf\u8ff0&#8221;\u5bf9\u5916\u53d1\u51fa\u4e86\u4ec0\u4e48&#8221;\u3002<\/li>\n<li><strong>Thought \/ Action \u662f Agent \u7684\u5185\u90e8\u72b6\u6001<\/strong> \u2014\u2014 \u63cf\u8ff0&#8221;\u8111\u5b50\u91cc\u5728\u5e72\u4ec0\u4e48&#8221;\u3002<\/li>\n<\/ul>\n<p>\u5b83\u4eec\u8bf4\u7684\u662f\u4e24\u4ef6\u4e8b\u3002Thought \u548c Action \u5206\u522b\u5bf9\u5e94\u51b3\u7b56\u7684\u4e24\u4e2a\u9636\u6bb5\uff1a<\/p>\n<pre><code>Thought:  \u6211\u8981\u77e5\u9053\u5929\u6c14          \u2190 Decision\uff08\u51b3\u5b9a\u505a\u4ec0\u4e48\uff09\n   \u2193\nAction:   weather(&quot;Shanghai&quot;)   \u2190 \u6a21\u578b\u63d0\u51fa\u7684\u6267\u884c\u6307\u4ee4\n<\/code><\/pre>\n<p>\u7528\u4e00\u53e5\u8bdd\u533a\u5206\uff1a<\/p>\n<ul>\n<li>Thought \u662f&#8221;\u6211\u51b3\u5b9a\u4e0b\u4e00\u6b65\u505a\u4ec0\u4e48&#8221;\uff1b<\/li>\n<li>Action \u662f&#8221;\u6211\u771f\u6b63\u53d1\u51fa\u7684\u6267\u884c\u6307\u4ee4&#8221;\u3002<\/li>\n<\/ul>\n<p>\u8bba\u6587\u771f\u6b63\u60f3\u8868\u8fbe\u7684\uff0c\u662f <strong>LLM \u5982\u4f55\u4e00\u6b65\u6b65\u505a\u51fa\u51b3\u7b56<\/strong>\uff0c\u800c\u4e0d\u662f API \u957f\u4ec0\u4e48\u6837\u3002\u6240\u4ee5\u5b83\u5728\u6982\u5ff5\u4e0a\u628a\u51b3\u7b56\uff08Thought\uff09\u548c\u6267\u884c\uff08Action\uff09\u5206\u5f00\u63cf\u8ff0\u3002<\/p>\n<h2 id=\"action\">\u4e00\u4e2a\u5e38\u88ab\u5ffd\u7565\u7684\u7ec6\u8282\uff1aAction \u5176\u5b9e\u8de8\u4e86\u4e24\u4e2a\u89d2\u8272<\/h2>\n<p>\u8fd9\u91cc\u8fd8\u6709\u4e00\u5c42\u5f88\u591a\u4eba\u6ca1\u6ce8\u610f\u5230\u7684\u4e1c\u897f\uff1a<strong>Action \u5e76\u4e0d\u662f\u4e00\u4e2a\u5355\u4e00\u52a8\u4f5c\uff0c\u5b83\u5185\u90e8\u53c8\u5206\u6210\u4e24\u534a\u3002<\/strong><\/p>\n<ul>\n<li>\u7b2c\u4e00\u534a\uff1a<strong>LLM \u63d0\u51fa\u52a8\u4f5c<\/strong>\u3002\u6a21\u578b\u53ea\u662f\u8f93\u51fa\u4e00\u6bb5&#8221;\u6211\u60f3\u8c03\u7528 <code>weather(\"Shanghai\")<\/code>&#8220;\u7684\u610f\u56fe\uff0c\u5b83\u672c\u8eab\u5e76\u4e0d\u4f1a\u3001\u4e5f\u6ca1\u80fd\u529b\u771f\u6b63\u53bb\u67e5\u5929\u6c14\u3002<\/li>\n<li>\u7b2c\u4e8c\u534a\uff1a<strong>Agent \u6267\u884c\u52a8\u4f5c<\/strong>\u3002Agent \u8fd0\u884c\u65f6\uff08\u4e5f\u5c31\u662f\u6211\u4eec\u5199\u7684\u90a3\u6bb5\u4ee3\u7801\/\u6846\u67b6\uff09\u89e3\u6790\u8fd9\u6bb5\u610f\u56fe\uff0c\u771f\u6b63\u53bb\u8c03\u7528\u5929\u6c14 API\u3001\u8dd1\u6570\u636e\u5e93\u67e5\u8be2\u3001\u6267\u884c shell \u547d\u4ee4\u3002<\/li>\n<\/ul>\n<p>\u800c <strong>Observation\uff0c\u5c31\u662f\u7b2c\u4e8c\u534a&#8221;\u6267\u884c&#8221;\u4e4b\u540e\u62ff\u56de\u6765\u7684\u7ed3\u679c<\/strong>\u3002<\/p>\n<p>\u7528\u89d2\u8272\u628a\u6574\u6761\u94fe\u8def\u4e32\u8d77\u6765\u4f1a\u66f4\u6e05\u695a\uff1a<\/p>\n<pre><code>LLM     \u2502  Thought         \u6211\u5f97\u67e5\u5929\u6c14\n        \u2502  Action(intent)  \u6211&quot;\u60f3&quot;\u8c03\u7528 weather(&quot;Shanghai&quot;)   \u2190 \u53ea\u662f\u63d0\u51fa\n        \u25bc\nAgent   \u2502  \u6267\u884c Action      \u771f\u6b63\u53bb\u8c03 weather API             \u2190 \u771f\u6b63\u5e72\u6d3b\n        \u2502  Observation     26\u2103\uff0c\u6709\u96e8                         \u2190 \u6267\u884c\u7ed3\u679c\n        \u25bc\nLLM     \u2502  Thought         \u6709\u96e8\uff0c\u4e0d\u9002\u5408\n<\/code><\/pre>\n<p>\u6240\u4ee5&#8221;Action \u2192 Observation&#8221;\u4e25\u683c\u6765\u8bf4\u4e0d\u662f\u6a21\u578b\u4e00\u4e2a\u4eba\u5b8c\u6210\u7684\uff1a\u6a21\u578b\u8d1f\u8d23<strong>\u63d0\u51fa<\/strong>\uff0cAgent \u8d1f\u8d23<strong>\u6267\u884c\u5e76\u53d6\u56de\u7ed3\u679c<\/strong>\u3002\u8fd9\u4e5f\u6b63\u597d\u547c\u5e94\u7b2c\u56db\u8282\u2014\u2014Observation \u5fc5\u987b\u72ec\u7acb\uff0c\u56e0\u4e3a\u5b83\u6765\u81ea Agent \u7684\u771f\u5b9e\u6267\u884c\uff0c\u800c\u4e0d\u662f\u6a21\u578b\u7684\u60f3\u8c61\u3002<\/p>\n<h2 id=\"action-function-calling\">Action \u662f\u903b\u8f91\u6982\u5ff5\uff0c\u4e0d\u7b49\u4e8e function calling<\/h2>\n<p>\u8fd8\u6709\u4e00\u70b9\u8981\u5f3a\u8c03\uff1a<strong>Action \u662f\u8bba\u6587\u91cc\u7684\u903b\u8f91\u6982\u5ff5\uff0c\u5b83\u5e76\u6ca1\u6709\u88ab&#8221;\u710a\u6b7b&#8221;\u6210 AI message \u91cc\u7684\u67d0\u4e2a function call \u5b57\u6bb5\u3002<\/strong><\/p>\n<p>\u8bba\u6587\u4e2d\u7684 Action\uff0c\u672c\u8d28\u662f&#8221;Agent \u51b3\u5b9a\u5e76\u6267\u884c\u4e00\u6b21\u5bf9\u5916\u64cd\u4f5c&#8221;\u8fd9\u4e2a\u62bd\u8c61\u884c\u4e3a\u3002\u5b83\u53ef\u4ee5\u6709\u5f88\u591a\u79cd\u843d\u5730\u65b9\u5f0f\uff1a<\/p>\n<ul>\n<li>\u65e9\u671f\u662f\u8ba9\u6a21\u578b\u6309\u683c\u5f0f\u8f93\u51fa\u4e00\u884c\u6587\u672c\uff0c\u6bd4\u5982 <code>Search[Apple CEO]<\/code>\uff0c\u518d\u7531 Agent \u7528\u6b63\u5219\u89e3\u6790\u540e\u6267\u884c\uff1b<\/li>\n<li>\u73b0\u5728\u4e3b\u6d41\u662f function calling \/ tool calling\uff0c\u6a21\u578b\u76f4\u63a5\u5410\u51fa\u7ed3\u6784\u5316\u7684 <code>tool_calls<\/code>\uff1b<\/li>\n<li>\u4e5f\u53ef\u4ee5\u662f\u6a21\u578b\u8f93\u51fa\u4e00\u6bb5\u4ee3\u7801\uff0c\u7531 Agent \u4e22\u8fdb\u6c99\u7bb1\u91cc\u8dd1\uff08Code Act\uff09\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u90fd\u662f\u540c\u4e00\u4e2a Action \u6982\u5ff5\u7684\u4e0d\u540c<strong>\u5de5\u7a0b\u5b9e\u73b0<\/strong>\u3002function calling \u53ea\u662f\u76ee\u524d\u6700\u6d41\u884c\u7684\u90a3\u4e00\u79cd\uff0c\u800c\u4e0d\u662f Action \u7684\u5b9a\u4e49\u672c\u8eab\u3002\u628a&#8221;Action&#8221;\u548c&#8221;function calling&#8221;\u753b\u7b49\u53f7\uff0c\u6070\u6070\u662f\u53ea\u770b\u5230\u4e86 Prompt\/Message \u5c42\uff0c\u6ca1\u770b\u5230\u80cc\u540e\u7684 State \u5c42\u3002<\/p>\n<h1 id=\"state-react\">\u516d\u3001State \u624d\u662f ReAct \u7684\u771f\u6b63\u6838\u5fc3<\/h1>\n<p>\u7406\u89e3\u4e86\u4e0a\u9762\u4e24\u8282\uff0c\u5c31\u80fd\u770b\u51fa\uff1a\u771f\u6b63\u7684 ReAct\uff0c\u672c\u8d28\u662f\u4e00\u4e2a<strong>\u72b6\u6001\u673a<\/strong>\u3002<\/p>\n<pre><code>Thought\n   \u2502\n   \u25bc\nAction\n   \u2502\n   \u25bc\nObservation\n   \u2502\n   \u25bc\nThought\n   \u2502\n   \u25bc\nAction\n   \u2502\n   \u25bc\nObservation\n   \u2502\n   \u25bc\n  ...\n<\/code><\/pre>\n<p>\u5982\u679c\u5199\u6210\u4ee3\u7801\uff0c\u5927\u81f4\u662f\u8fd9\u6837\u4e00\u4e2a\u5faa\u73af\uff1a<\/p>\n<pre><code class=\"language-python\">while not finished:\n    thought = llm(history)            # LLM\uff1a\u51b3\u7b56 + \u63d0\u51fa\u52a8\u4f5c\n    action = choose_tool(thought)     # \u53d6\u51fa\u6a21\u578b\u60f3\u8c03\u7528\u7684\u5de5\u5177\n    observation = run(action)         # Agent\uff1a\u771f\u6b63\u6267\u884c\uff0c\u62ff\u56de\u7ed3\u679c\n    history.append(observation)       # \u62fc\u56de\u4e0a\u4e0b\u6587\uff0c\u8fdb\u5165\u4e0b\u4e00\u8f6e\n<\/code><\/pre>\n<p>\u56db\u4e2a\u8981\u7d20\u5404\u53f8\u5176\u804c\uff1a<\/p>\n<ul>\n<li><strong>Thought<\/strong>\uff1aAgent \u5f53\u524d\u7684\u51b3\u7b56\uff1b<\/li>\n<li><strong>Action<\/strong>\uff1aAgent \u8bf7\u6c42\u6267\u884c\u7684\u52a8\u4f5c\uff1b<\/li>\n<li><strong>Observation<\/strong>\uff1a\u73af\u5883\u7ed9\u56de\u6765\u7684\u53cd\u9988\uff1b<\/li>\n<li><strong>History<\/strong>\uff1a\u4e0d\u65ad\u7d2f\u79ef\u7684\u4e0a\u4e0b\u6587\u3002<\/li>\n<\/ul>\n<p>\u6574\u4e2a\u5faa\u73af\u53cd\u590d\u8fdb\u884c\uff0c\u76f4\u5230\u6a21\u578b\u8ba4\u4e3a\u53ef\u4ee5\u6536\u5c3e\uff0c\u8f93\u51fa\u6700\u7ec8\u7b54\u6848\u3002<\/p>\n<h1 id=\"function-calling-thought\">\u4e03\u3001\u73b0\u4ee3 Function Calling \u91cc\uff0cThought \u53bb\u54ea\u4e86\uff1f<\/h1>\n<p>\u5982\u679c\u4f60\u7528\u8fc7 OpenAI\u3001Claude\u3001Gemini \u7684\u5de5\u5177\u8c03\u7528\uff0c\u4f1a\u53d1\u73b0\u5b83\u4eec\u5176\u5b9e<strong>\u4e0d\u518d\u8f93\u51fa<\/strong>\u8fd9\u6837\u7684\u6587\u672c\uff1a<\/p>\n<pre><code>Thought:\n...\n\nAction:\n...\n<\/code><\/pre>\n<p>\u800c\u662f\u76f4\u63a5\u5410\u51fa\u7ed3\u6784\u5316\u7684\u5de5\u5177\u8c03\u7528\uff1a<\/p>\n<pre><code class=\"language-json\">{\n    &quot;tool_calls&quot;: [\n        {\n            &quot;function&quot;: &quot;weather&quot;,\n            &quot;arguments&quot;: {\n                &quot;city&quot;: &quot;Shanghai&quot;\n            }\n        }\n    ]\n}\n<\/code><\/pre>\n<p>\u7a0b\u5e8f\u6267\u884c\u5de5\u5177\u540e\uff0c\u628a\u7ed3\u679c\u4f5c\u4e3a\u4e00\u6761 tool \u6d88\u606f\u585e\u56de\u53bb\uff1a<\/p>\n<pre><code class=\"language-json\">{\n    &quot;role&quot;: &quot;tool&quot;,\n    &quot;content&quot;: &quot;26\u2103, humidity 90%, rain&quot;\n}\n<\/code><\/pre>\n<p>\u6700\u540e\u518d\u8c03\u4e00\u6b21 LLM \u5f97\u5230\u6700\u7ec8\u7b54\u6848\uff1a<\/p>\n<pre><code class=\"language-text\">User\n   \u2193\nAssistant(tool_call)\n   \u2193\nTool(result)\n   \u2193\nAssistant(final answer)\n<\/code><\/pre>\n<p>\u6574\u4e2a\u8fc7\u7a0b\u91cc\uff0c\u5df2\u7ecf\u770b\u4e0d\u5230 Thought \u4e86\u3002<\/p>\n<p>\u4f46\u8fd9\u4e0d\u4ee3\u8868 Thought \u6d88\u5931\u4e86\uff1a<\/p>\n<blockquote>\n<p><strong>Thought \u6ca1\u6709\u6d88\u5931\uff0c\u53ea\u662f\u4ece&#8221;\u663e\u5f0f\u5199\u5728 Prompt \u91cc&#8221;\u53d8\u6210\u4e86&#8221;\u6a21\u578b\u5185\u90e8\u7684\u9690\u5f0f\u63a8\u7406\uff08Hidden Reasoning\uff09&#8221;\u3002<\/strong><\/p>\n<\/blockquote>\n<p>\u73b0\u4ee3\u6a21\u578b\u901a\u5e38\u4e0d\u4f1a\u628a\u8fd9\u6bb5\u63a8\u7406\u8fc7\u7a0b\u76f4\u63a5\u66b4\u9732\u7ed9\u5f00\u53d1\u8005\uff08\u63a8\u7406\u6a21\u578b\u4f1a\u628a\u5b83\u653e\u8fdb\u5355\u72ec\u7684 reasoning \u5b57\u6bb5\uff09\u3002\u51b3\u7b56\u8fd9\u4e00\u6b65\u4f9d\u7136\u5b58\u5728\uff0c\u53ea\u662f\u85cf\u5230\u4e86\u6a21\u578b\u5185\u90e8\u3002<\/p>\n<h1 id=\"react-inside-llm\">\u516b\u3001ReAct Inside\uff1a\u7ad9\u5728 LLM \u5185\u90e8\u770b\u5168\u6d41\u7a0b<\/h1>\n<p>\u5982\u679c\u628a\u89c6\u89d2\u5207\u5230 LLM \u5185\u90e8\uff0c\u6574\u4e2a\u6d41\u7a0b\u53ef\u4ee5\u753b\u6210\u8fd9\u6837\uff1a<\/p>\n<pre><code>                +----------------+\n                | User Message   |\n                +--------+-------+\n                         |\n                         \u25bc\n              +-------------------+\n              | Internal Reasoning|\n              | (Thought)         |\n              +--------+----------+\n                       |\n                       \u25bc\n              +-------------------+\n              | Tool Selection    |\n              | (Action)          |\n              +--------+----------+\n                       |\n                       \u25bc\n              +-------------------+\n              | Tool Execution    |\n              +--------+----------+\n                       |\n                       \u25bc\n              +-------------------+\n              | Observation       |\n              | (Tool Message)    |\n              +--------+----------+\n                       |\n                       \u25bc\n              +-------------------+\n              | Internal Reasoning|\n              | (Thought)         |\n              +--------+----------+\n                       |\n                       \u25bc\n                 Final Answer\n<\/code><\/pre>\n<p>\u771f\u6b63\u5728\u5faa\u73af\u7684\uff0c\u662f\u8fd9\u4e09\u4e2a\u52a8\u4f5c\uff1a<\/p>\n<pre><code>Reason \u2192 Act \u2192 Observe \u2192 Reason \u2192 ...\n<\/code><\/pre>\n<p>\u800c\u4e0d\u662f\u5f88\u591a\u4eba\u4ee5\u4e3a\u7684\uff1a<\/p>\n<pre><code>Prompt \u2192 Prompt \u2192 Prompt \u2192 ...\n<\/code><\/pre>\n<p>\u6362\u53e5\u8bdd\u8bf4\uff0c\u5faa\u73af\u7684\u4e3b\u4f53\u662f<strong>\u72b6\u6001\u7684\u6d41\u8f6c<\/strong>\uff0c\u800c\u4e0d\u662f\u4e00\u6bb5\u6bb5\u6587\u672c\u683c\u5f0f\u7684\u5806\u53e0\u3002<\/p>\n<h1 id=\"react_1\">\u4e5d\u3001\u7528\u4e09\u4e2a\u5c42\u6b21\u7406\u89e3 ReAct<\/h1>\n<p>\u628a\u524d\u9762\u7684\u5185\u5bb9\u6536\u4e00\u4e0b\uff0c\u53ef\u4ee5\u4ece\u4e09\u4e2a\u5c42\u6b21\u6765\u770b ReAct\u3002<\/p>\n<p>\u7b2c\u4e00\u5c42\u662f <strong>Prompt<\/strong>\u3002\u8bba\u6587\u91cc\u7684 <code>Thought \/ Action \/ Observation<\/code>\uff0c\u53ea\u662f\u4e3a\u4e86\u65b9\u4fbf\u628a\u63a8\u7406\u8f68\u8ff9\u5c55\u793a\u51fa\u6765\uff0c\u662f\u7ed9\u4eba\u770b\u7684&#8221;\u5c55\u793a\u683c\u5f0f&#8221;\u3002<\/p>\n<p>\u7b2c\u4e8c\u5c42\u662f <strong>Message<\/strong>\u3002\u73b0\u4ee3 Agent \u771f\u6b63\u4ea4\u6362\u7684\u6d88\u606f\u53ea\u6709\u4e09\u7c7b\uff1aUser\u3001Assistant\u3001Tool\u3002\u8fd9\u662f\u843d\u5230 API \u4e0a\u7684&#8221;\u901a\u4fe1\u534f\u8bae&#8221;\u3002<\/p>\n<p>\u7b2c\u4e09\u5c42\u662f <strong>State<\/strong>\uff0c\u4e5f\u662f\u771f\u6b63\u7684\u6838\u5fc3\u3002\u5b83\u63cf\u8ff0\u7684\u662f Agent \u5185\u90e8\u7684\u72b6\u6001\u6d41\u8f6c\uff1a<\/p>\n<pre><code>Decision\uff08\u51b3\u7b56\uff09\n   \u2193\nExecution\uff08\u6267\u884c\uff09\n   \u2193\nEnvironment Feedback\uff08\u73af\u5883\u53cd\u9988\uff09\n   \u2193\nDecision\uff08\u518d\u51b3\u7b56\uff09\n<\/code><\/pre>\n<p>\u8fd9\u5957\u72b6\u6001\u673a\uff0c\u624d\u662f ReAct \u7684\u672c\u8d28\u3002<\/p>\n<h1 id=\"_2\">\u5341\u3001\u603b\u7ed3<\/h1>\n<p>\u4e00\u53e5\u8bdd\u603b\u7ed3 ReAct\uff1a<\/p>\n<blockquote>\n<p><strong>ReAct \u4e0d\u662f\u4e00\u79cd Prompt \u6a21\u677f\uff0c\u800c\u662f\u4e00\u79cd Agent \u7684\u72b6\u6001\u673a\u3002<\/strong><\/p>\n<\/blockquote>\n<p>\u7406\u89e3\u5b83\uff0c\u5173\u952e\u662f\u5206\u6e05\u4e09\u4e2a\u5c42\u6b21\uff1a<\/p>\n<ul>\n<li><strong>Prompt \u5c42<\/strong>\uff1a<code>Thought \/ Action \/ Observation<\/code>\uff0c\u53ea\u662f\u7528\u6765\u8868\u8fbe\u63a8\u7406\u8fc7\u7a0b\u7684\u5c55\u793a\u683c\u5f0f\u3002<\/li>\n<li><strong>Message \u5c42<\/strong>\uff1a<code>User \/ Assistant \/ Tool<\/code>\uff0c\u662f\u5b9e\u9645\u7684 API \u901a\u4fe1\u534f\u8bae\u3002<\/li>\n<li><strong>State \u5c42<\/strong>\uff1a<code>Thought \u2192 Action \u2192 Observation<\/code>\uff0c\u662f Agent \u771f\u6b63\u7684\u5185\u90e8\u72b6\u6001\u673a\u3002<\/li>\n<\/ul>\n<p>\u73b0\u4ee3 Function Calling \u867d\u7136\u4e0d\u518d\u663e\u5f0f\u8f93\u51fa Thought\uff0c\u4f46\u5e95\u5c42\u4f9d\u7136\u9075\u5faa\u540c\u6837\u7684\u72b6\u6001\u8f6c\u6362\uff1a<\/p>\n<pre><code>Reason \u2192 Act \u2192 Observe \u2192 Reason \u2192 ...\n<\/code><\/pre>\n<p>\u6240\u4ee5\u53ef\u4ee5\u8fd9\u6837\u7406\u89e3\u4e8c\u8005\u7684\u5173\u7cfb\uff1a<\/p>\n<blockquote>\n<p><strong>Function Calling \u662f ReAct \u7684\u5de5\u7a0b\u5b9e\u73b0\uff1bReAct \u662f Function Calling \u7684\u8bbe\u8ba1\u601d\u60f3\u3002<\/strong><\/p>\n<\/blockquote>\n<p>\u5982\u679c\u89c9\u5f97\u8fd9\u7bc7\u6587\u7ae0\u5bf9\u4f60\u6709\u5e2e\u52a9\uff0c\u6b22\u8fce<strong>\u70b9\u8d5e\u3001\u6536\u85cf\u52a0\u5173\u6ce8<\/strong>\u3002\u540e\u7eed\u6301\u7eed\u5206\u4eab\u66f4\u591a\u6709\u4ef7\u503c\u7684\u5185\u5bb9\u3002\u4f60\u7684\u652f\u6301\u662f\u6211\u521b\u4f5c\u7684\u6700\u5927\u52a8\u529b\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f88\u591a\u4eba\u7b2c\u4e00\u6b21\u63a5\u89e6 ReAct\uff08Reason + Act\uff09\u65f6\uff0c\u4f1a\u4ee5\u4e3a\u5b83\u53ea\u662f\u5728 Prompt \u91cc\u52a0\u4e86 Though [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[130,132,128,71,127,131,129],"class_list":["post-75","post","type-post","status-publish","format-standard","hentry","category-agent","tag-agent","tag-ai-agent","tag-function-calling","tag-llm","tag-react","tag-thought-action-observation","tag-tool-calling"],"_links":{"self":[{"href":"https:\/\/genetop.top\/index.php\/wp-json\/wp\/v2\/posts\/75","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/genetop.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/genetop.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/genetop.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/genetop.top\/index.php\/wp-json\/wp\/v2\/comments?post=75"}],"version-history":[{"count":0,"href":"https:\/\/genetop.top\/index.php\/wp-json\/wp\/v2\/posts\/75\/revisions"}],"wp:attachment":[{"href":"https:\/\/genetop.top\/index.php\/wp-json\/wp\/v2\/media?parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/genetop.top\/index.php\/wp-json\/wp\/v2\/categories?post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/genetop.top\/index.php\/wp-json\/wp\/v2\/tags?post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}