{"id":26,"date":"2026-11-08T13:16:04","date_gmt":"2026-11-08T13:16:04","guid":{"rendered":"http:\/\/blog.antpython.net\/?p=26"},"modified":"2026-11-08T13:16:04","modified_gmt":"2026-11-08T13:16:04","slug":"agent-%e8%ae%b0%e5%bf%86%e3%80%81%e8%a7%84%e5%88%92%e4%b8%8e%e5%a4%9a%e6%ad%a5%e4%bb%bb%e5%8a%a1%ef%bc%9a%e4%bb%8e-demo-%e5%88%b0%e5%8f%af%e9%9d%a0%e7%b3%bb%e7%bb%9f","status":"publish","type":"post","link":"http:\/\/blog.antpython.net\/?p=26","title":{"rendered":"Agent \u8bb0\u5fc6\u3001\u89c4\u5212\u4e0e\u591a\u6b65\u4efb\u52a1\uff1a\u4ece Demo \u5230\u53ef\u9760\u7cfb\u7edf"},"content":{"rendered":"<p>Demo \u91cc Agent\u300c\u770b\u8d77\u6765\u5f88\u806a\u660e\u300d\uff0c\u4e0a\u7ebf\u540e\u5374\u5e38\u7ffb\u8f66\uff1a\u5fd8\u4e0a\u4e0b\u6587\u3001\u6b7b\u5faa\u73af\u8c03\u5de5\u5177\u3001\u4e2d\u9014\u8dd1\u504f\u3002\u8981\u628a Demo \u505a\u6210\u53ef\u9760\u7cfb\u7edf\uff0c\u5f97\u8865\u9f50<strong>\u8bb0\u5fc6\u3001\u89c4\u5212\u3001\u7ea6\u675f<\/strong>\u4e09\u5757\u3002<\/p>\n<h2>\u8bb0\u5fc6\u5206\u5c42<\/h2>\n<ul>\n<li><strong>\u77ed\u671f\u8bb0\u5fc6<\/strong>\uff1a\u5f53\u524d\u4f1a\u8bdd messages<\/li>\n<li><strong>\u60c5\u666f\u8bb0\u5fc6<\/strong>\uff1a\u5411\u91cf\u5e93\u5b58\u5386\u53f2\u5bf9\u8bdd\u6458\u8981<\/li>\n<li><strong>\u957f\u671f\u504f\u597d<\/strong>\uff1a\u7528\u6237\u8bbe\u7f6e\u3001\u6743\u9650\u3001\u5e38\u7528\u5de5\u5177<\/li>\n<\/ul>\n<pre><code># \u4f1a\u8bdd\u8fc7\u957f\u65f6\u505a\u6458\u8981\u538b\u7f29\nif token_count(messages) &gt; 6000:\n    summary = summarize(messages[:-4])\n    messages = [{\"role\": \"system\", \"content\": summary}] + messages[-4:]\n<\/code><\/pre>\n<h2>\u89c4\u5212\uff1a\u5148\u62c6\u4efb\u52a1\u518d\u6267\u884c<\/h2>\n<pre><code>plan_prompt = \"\"\"\n\u628a\u7528\u6237\u76ee\u6807\u62c6\u6210\u6700\u591a 5 \u4e2a\u53ef\u6267\u884c\u6b65\u9aa4\uff0c\u8f93\u51fa JSON \u6570\u7ec4\u3002\n\u7528\u6237\u76ee\u6807\uff1a{goal}\n\"\"\"\nsteps = parse_json(llm(plan_prompt))\nfor step in steps:\n    observe = run_agent_step(step)\n    # \u6bcf\u6b65\u6821\u9a8c\uff0c\u5931\u8d25\u5219\u91cd\u89c4\u5212\n<\/code><\/pre>\n<h2>\u53ef\u9760\u6027\u62a4\u680f<\/h2>\n<ol>\n<li>\u6700\u5927\u6b65\u6570 \/ \u6700\u5927\u5de5\u5177\u8c03\u7528\u6b21\u6570<\/li>\n<li>\u5de5\u5177\u767d\u540d\u5355\u4e0e\u53c2\u6570\u6821\u9a8c<\/li>\n<li>\u5173\u952e\u5199\u64cd\u4f5c\u4e8c\u6b21\u786e\u8ba4\uff08\u4eba\u5de5 in-the-loop\uff09<\/li>\n<li>\u5b8c\u6574 trace\uff1a\u6bcf\u4e00\u6b65\u8f93\u5165\u3001\u5de5\u5177\u3001\u8f93\u51fa\u90fd\u843d\u65e5\u5fd7<\/li>\n<\/ol>\n<h2>\u8bc4\u4f30\u600e\u4e48\u505a<\/h2>\n<p>\u51c6\u5907 30\uff5e50 \u4e2a\u771f\u5b9e\u4efb\u52a1\u96c6\uff1a\u6210\u529f\u6807\u51c6\u3001\u5141\u8bb8\u5de5\u5177\u3001\u671f\u671b\u6700\u7ec8\u7b54\u6848\u3002\u6bcf\u6b21\u6539 Prompt\/\u5de5\u5177\u90fd\u56de\u5f52\u4e00\u904d\u3002\u6ca1\u6709\u8bc4\u4f30\u96c6\uff0cAgent \u4f18\u5316\u53ea\u80fd\u9760\u611f\u89c9\u3002<\/p>\n<p>\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1a<strong>Agent \u7684\u6838\u5fc3\u4e0d\u662f\u66f4\u4f1a\u804a\uff0c\u800c\u662f\u53ef\u63a7\u5730\u5b8c\u6210\u4efb\u52a1\u3002<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Demo \u91cc Agent\u300c\u770b\u8d77\u6765\u5f88\u806a\u660e\u300d\uff0c\u4e0a\u7ebf\u540e\u5374\u5e38\u7ffb\u8f66\uff1a\u5fd8\u4e0a\u4e0b\u6587\u3001\u6b7b\u5faa\u73af\u8c03\u5de5\u5177\u3001\u4e2d\u9014\u8dd1\u504f\u3002\u8981\u628a Demo \u505a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-26","post","type-post","status-publish","format-standard","hentry","category-agent-dev"],"_links":{"self":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/posts\/26","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=26"}],"version-history":[{"count":0,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/posts\/26\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}