{"id":33101,"date":"2025-07-22T18:16:44","date_gmt":"2025-07-22T10:16:44","guid":{"rendered":"https:\/\/www.kdjingpai.com\/?p=33101"},"modified":"2025-07-22T18:39:51","modified_gmt":"2025-07-22T10:39:51","slug":"12-factor-agentsai-5","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/en\/12-factor-agentsai-5\/","title":{"rendered":"\u300a12-Factor Agents\u300b4. \u5de5\u5177\u53ea\u662f\u7ed3\u6784\u5316\u8f93\u51fa"},"content":{"rendered":"<p>\u5de5\u5177\u65e0\u9700\u590d\u6742\u3002\u5176\u6838\u5fc3\u53ea\u662f\u6765\u81ea\u4f60\u7684\u5927\u8bed\u8a00\u6a21\u578b (LLM) \u7684\u7ed3\u6784\u5316\u8f93\u51fa\uff0c\u7528\u4e8e\u89e6\u53d1\u786e\u5b9a\u6027\u4ee3\u7801\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-33102\" title=\"\u300a12-Factor Agents\u300b4. \u5de5\u5177\u53ea\u662f\u7ed3\u6784\u5316\u8f93\u51fa-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/07\/cee34bf8d8b8e6e.jpg\" alt=\"\u300a12-Factor Agents\u300b4. \u5de5\u5177\u53ea\u662f\u7ed3\u6784\u5316\u8f93\u51fa-1\" width=\"2560\" height=\"1440\" \/><\/p>\n<p>\u4f8b\u5982\uff0c\u5047\u8bbe\u4f60\u6709\u4e24\u4e2a\u5de5\u5177\u00a0<code>CreateIssue<\/code>\u00a0\u548c\u00a0<code>SearchIssues<\/code>\u3002\u8981\u6c42\u4e00\u4e2a\u5927\u8bed\u8a00\u6a21\u578b (LLM) \u201c\u4f7f\u7528\u591a\u4e2a\u5de5\u5177\u4e4b\u4e00\u201d\uff0c\u5176\u5b9e\u5c31\u662f\u8981\u6c42\u5b83\u8f93\u51fa\u4e00\u4e2a\u6211\u4eec\u53ef\u4ee5\u89e3\u6790\u4e3a\u4ee3\u8868\u8fd9\u4e9b\u5de5\u5177\u7684\u5bf9\u8c61\u7684 JSON\u3002<\/p>\n<pre><code>class Issue:\r\ntitle: str\r\ndescription: str\r\nteam_id: str\r\nassignee_id: str\r\nclass CreateIssue:\r\nintent: \"create_issue\"\r\nissue: Issue\r\nclass SearchIssues:\r\nintent: \"search_issues\"\r\nquery: str\r\nwhat_youre_looking_for: str\r\n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u6a21\u5f0f\u5f88\u7b80\u5355\uff1a<\/p>\n<ol>\n<li>\u5927\u8bed\u8a00\u6a21\u578b (LLM) \u8f93\u51fa\u7ed3\u6784\u5316\u7684 JSON<\/li>\n<li>\u786e\u5b9a\u6027\u4ee3\u7801\u6267\u884c\u76f8\u5e94\u7684\u64cd\u4f5c (\u4f8b\u5982\u8c03\u7528\u5916\u90e8 API)<\/li>\n<li>\u6355\u83b7\u7ed3\u679c\u5e76\u53cd\u9988\u5230\u4e0a\u4e0b\u6587\u4e2d<\/li>\n<\/ol>\n<p>\u8fd9\u5728\u5927\u8bed\u8a00\u6a21\u578b (LLM) \u7684\u51b3\u7b56\u548c\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u64cd\u4f5c\u4e4b\u95f4\u521b\u5efa\u4e86\u6e05\u6670\u7684\u5206\u79bb\u3002LLM \u51b3\u5b9a\u505a\u4ec0\u4e48\uff0c\u4f46\u4f60\u7684\u4ee3\u7801\u63a7\u5236\u5982\u4f55\u505a\u3002\u4ec5\u4ec5\u56e0\u4e3a LLM \u201c\u8c03\u7528\u4e86\u4e00\u4e2a\u5de5\u5177\u201d \u5e76\u4e0d\u610f\u5473\u7740\u4f60\u6bcf\u6b21\u90fd\u5fc5\u987b\u4ee5\u76f8\u540c\u7684\u65b9\u5f0f\u53bb\u6267\u884c\u4e00\u4e2a\u7279\u5b9a\u7684\u76f8\u5e94\u51fd\u6570\u3002<\/p>\n<p>\u5982\u679c\u4f60\u8fd8\u8bb0\u5f97\u6211\u4eec\u4e0a\u9762\u7684 switch \u8bed\u53e5<\/p>\n<pre><code>if nextStep.intent == 'create_payment_link':\r\nstripe.paymentlinks.create(nextStep.parameters)\r\nreturn # \u6216\u8005\u4efb\u4f55\u4f60\u60f3\u8981\u7684\u64cd\u4f5c\uff0c\u89c1\u4e0b\u6587\r\nelif nextStep.intent == 'wait_for_a_while': \r\n# \u505a\u4e00\u4e9b\u5355\u5b50 (monadic) \u64cd\u4f5c\u4e4b\u7c7b\u7684\r\nelse: #... \u6a21\u578b\u6ca1\u6709\u8c03\u7528\u6211\u4eec\u5df2\u77e5\u7684\u5de5\u5177\r\n# \u505a\u4e9b\u522b\u7684\u4e8b\u60c5\r\n<\/code><\/pre>\n<p><strong>\u6ce8\u610f<\/strong>: \u5173\u4e8e\u201c\u666e\u901a\u63d0\u793a (plain prompting)\u201d\u3001\u201c\u5de5\u5177\u8c03\u7528 (tool calling)\u201d\u4e0e\u201cJSON \u6a21\u5f0f (JSON mode)\u201d\u7684\u4f18\u70b9\u4ee5\u53ca\u5404\u81ea\u7684\u6027\u80fd\u6743\u8861\uff0c\u5df2\u7ecf\u6709\u5f88\u591a\u8ba8\u8bba\u3002\u6211\u4eec\u5f88\u5feb\u4f1a\u63d0\u4f9b\u4e00\u4e9b\u76f8\u5173\u8d44\u6e90\u7684\u94fe\u63a5\uff0c\u4f46\u8fd9\u91cc\u4e0d\u6df1\u5165\u63a2\u8ba8\u3002\u8bf7\u53c2\u9605\u00a0<a href=\"https:\/\/www.boundaryml.com\/blog\/schema-aligned-parsing\">\u63d0\u793a vs JSON \u6a21\u5f0f vs \u51fd\u6570\u8c03\u7528 vs \u7ea6\u675f\u751f\u6210 vs SAP<\/a>\u3001<a href=\"https:\/\/www.vellum.ai\/blog\/when-should-i-use-function-calling-structured-outputs-or-json-mode#:~:text=We%20don%27t%20recommend%20using%20JSON,always%20use%20Structured%20Outputs%20instead\">\u6211\u5e94\u8be5\u4f55\u65f6\u4f7f\u7528\u51fd\u6570\u8c03\u7528\u3001\u7ed3\u6784\u5316\u8f93\u51fa\u6216 JSON \u6a21\u5f0f\uff1f<\/a>\u00a0\u548c\u00a0<a href=\"https:\/\/docs.llamaindex.ai\/en\/stable\/examples\/llm\/openai_json_vs_function_calling\/\">OpenAI JSON vs \u51fd\u6570\u8c03\u7528<\/a>\u3002<\/p>\n<p>\u201c\u4e0b\u4e00\u6b65\u201d\u53ef\u80fd\u4e0d\u50cf\u201c\u8fd0\u884c\u4e00\u4e2a\u7eaf\u51fd\u6570\u5e76\u8fd4\u56de\u7ed3\u679c\u201d\u90a3\u6837\u539f\u5b50\u5316\u3002\u5f53\u4f60\u5c06\u201c\u5de5\u5177\u8c03\u7528\u201d\u770b\u4f5c\u4ec5\u4ec5\u662f\u6a21\u578b\u8f93\u51fa\u4e00\u4e2a\u63cf\u8ff0\u786e\u5b9a\u6027\u4ee3\u7801\u5e94\u8be5\u505a\u4ec0\u4e48\u7684 JSON \u65f6\uff0c\u4f60\u5c31\u80fd\u89e3\u9501\u6781\u5927\u7684\u7075\u6d3b\u6027\u3002\u5c06\u8fd9\u4e00\u70b9\u4e0e\u00a0<a href=\"https:\/\/www.kdjingpai.com\/12-factor-agentsai-9\/\">\u8981\u7d20 8\uff1a\u638c\u63a7\u4f60\u7684\u63a7\u5236\u6d41<\/a>\u00a0\u7ed3\u5408\u8d77\u6765\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5de5\u5177\u65e0\u9700\u590d\u6742\u3002\u5176\u6838\u5fc3\u53ea\u662f\u6765\u81ea\u4f60\u7684\u5927\u8bed\u8a00\u6a21\u578b (LLM) \u7684\u7ed3\u6784\u5316\u8f93\u51fa\uff0c\u7528\u4e8e\u89e6\u53d1\u786e\u5b9a\u6027\u4ee3\u7801\u3002 \u4f8b\u5982\uff0c\u5047\u8bbe\u4f60\u6709\u4e24\u4e2a\u5de5\u5177\u00a0CreateIssue\u00a0\u548c\u00a0SearchIssues\u3002\u8981\u6c42\u4e00\u4e2a\u5927\u8bed\u8a00\u6a21\u578b (LLM) \u201c\u4f7f\u7528\u591a\u4e2a\u5de5\u5177\u4e4b\u4e00\u201d\uff0c\u5176\u5b9e\u5c31\u662f\u8981\u6c42\u5b83\u8f93&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-33101","post","type-post","status-publish","format-standard","hentry","category-kecheng"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts\/33101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/comments?post=33101"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts\/33101\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/media?parent=33101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/categories?post=33101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/tags?post=33101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}