{"id":10021430,"date":"2026-08-22T06:59:58","date_gmt":"2026-08-21T22:59:58","guid":{"rendered":"https:\/\/itmax.cn\/?p=10021430"},"modified":"2026-08-22T06:59:58","modified_gmt":"2026-08-21T22:59:58","slug":"%e5%ae%9e%e6%88%98%e4%bb%8e%e9%9b%b6%e5%bc%80%e5%a7%8b%e6%9e%84%e5%bb%ba%e4%b8%80%e4%b8%aacoding-agent%ef%bc%9aviolin-%ef%bd%9c%e5%be%97%e7%89%a9%e6%8a%80%e6%9c%af","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10021430","title":{"rendered":"\u5b9e\u6218\u4ece\u96f6\u5f00\u59cb\u6784\u5efa\u4e00\u4e2aCoding Agent\uff1aViolin \uff5c\u5f97\u7269\u6280\u672f"},"content":{"rendered":"<h2>\u4e00\u3001\u80cc\u666f<\/h2>\n<p>\u4ece 24 \u5e74\u51ac\u5929\u5f00\u59cb\uff0c\u5404\u7c7b coding agent \u5c42\u51fa\u4e0d\u7a77\u2014\u2014\u4ece Gemini CLI \u7684\u8d77\u6b65\uff0c\u5230 Claude Code \u7684\u5c1d\u8bd5\uff0c\u518d\u5230\u5982\u4eca Codex\u3001OpenCode\u3001PI\u3001Qoder \u7b49\u767e\u82b1\u9f50\u653e\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124029\" alt=\"\" title=\"\"><\/p>\n<p>\u77ed\u77ed\u4e00\u5e74\u591a\u7684\u65f6\u95f4\uff0cagent \u4ece\u5927\u6a21\u578b\u7684\u4e00\u4e2a\u9644\u5c5e\u54c1\uff0c\u9010\u6e10\u6f14\u53d8\u6210\u6a21\u578b\u80fd\u529b\u7684\u653e\u5927\u5668\uff0c\u6210\u4e3a AI \u5de5\u7a0b\u5316\u7684\u5173\u952e\u8f7d\u4f53\u3002\u5e02\u9762\u4e0a\u5404\u7c7b\u4e1a\u52a1 agent\u2014\u2014\u5ba2\u670d\u3001\u6570\u636e\u5206\u6790\u3001\u5de5\u4f5c\u6d41\u7f16\u6392\u7b49\u2014\u2014\u8ffd\u6839\u6eaf\u6e90\uff0c\u57fa\u672c\u90fd\u662f coding agent \u7684\u6cdb\u5316\u53d8\u79cd\u3002<\/p>\n<p>\u7406\u89e3\u4e86 coding agent \u7684\u6784\u5efa\u539f\u7406\uff0c\u4e5f\u5c31\u638c\u63e1\u4e86\u7406\u89e3\u5176\u4ed6 agent \u7684\u4e00\u628a\u94a5\u5319\u3002\u7b14\u8005\u5bf9\u6bcf\u5929\u90fd\u5728\u4f7f\u7528\u7684 agent \u539f\u7406\u5f88\u611f\u5174\u8da3\uff0c\u4e8e\u662f\u51b3\u5b9a\u81ea\u5df1\u5199\u4e00\u4e2a\uff1aviolin\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124030\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h2>\u4e8c\u3001\u6548\u679c\u9884\u89c8<\/h2>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124031\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u867d\u7136\u6709\u70b9\u4e11\uff0c\u4f46\u662f\u57fa\u672c\u7684\u529f\u80fd\uff08\u591a\u6a21\u6001\u3001skill\u3001\u63d2\u4ef6\uff09\u5df2\u7ecf\u5b8c\u5907\u4e86\u3002<\/p>\n<h2>\u4e09\u3001\u6574\u4f53\u67b6\u6784<\/h2>\n<p>Violin \u7684\u67b6\u6784\u8bbe\u8ba1\u6df1\u5ea6\u501f\u9274\u4e86 Pi \u7684\u8bbe\u8ba1\u7406\u5ff5\u3002Pi \u4f5c\u4e3a\u4e00\u4e2a TypeScript \u5b9e\u73b0\u7684 AI coding agent\uff0c\u5176\u6700\u7a81\u51fa\u7684\u7279\u70b9\u662f\u7b80\u6d01\u800c\u53ef\u6269\u5c55\u7684\u67b6\u6784\u2014\u2014\u4e09\u5c42\u5206\u79bb\uff08\u6a21\u578b\u9002\u914d\u5c42 \/ \u5185\u6838\u5c42 \/ \u4ea7\u54c1\u5c42\uff09\u3001EventBus \u4e8b\u4ef6\u9a71\u52a8\u3001\u5de5\u5177\u6ce8\u518c\u8868\u548c\u63d2\u4ef6\u7cfb\u7edf\uff0c\u6bcf\u4e2a\u6a21\u5757\u5404\u53f8\u5176\u804c\u4e14\u677e\u8026\u5408\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124032\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u66f4\u96be\u5f97\u7684\u662f\uff0cPi \u7684\u4ee3\u7801\u5b8c\u5168\u5f00\u6e90\uff0c\u8fd9\u4e0d\u4ec5\u8ba9 Violin \u6709\u4e86\u4e00\u4e2a\u624e\u5b9e\u7684\u53c2\u8003\u84dd\u672c\uff0c\u4e5f\u8ba9\u5b83\u672c\u8eab\u6210\u4e3a\u4e00\u4e2a\u6781\u4f73\u7684 Agent \u5de5\u7a0b\u5b66\u4e60\u8303\u672c\uff1a\u4ee3\u7801\u7ed3\u6784\u6e05\u6670\u3001\u6ce8\u91ca\u8be6\u5c3d\u3001\u6bcf\u5c42\u804c\u8d23\u660e\u786e\u3002\u60f3\u8981\u5b66\u4e60 Pi \u67b6\u6784\u7684\uff0c\u5f3a\u70c8\u63a8\u8350\u8fd9\u4e2a\u9879\u76ee\uff1ahow-pi-agent-works\u3002<\/p>\n<p>\u53ef\u4ee5\u8bf4\uff0c\u8bfb\u61c2\u4e86 Pi \u7684\u67b6\u6784\uff0c\u5c31\u7406\u89e3\u4e86\u73b0\u4ee3 AI coding agent \u7684\u6838\u5fc3\u8bbe\u8ba1\u6a21\u5f0f\u3002Violin \u5728\u4fdd\u6301\u8fd9\u4e00\u67b6\u6784\u7cbe\u9ad3\u7684\u540c\u65f6\uff0c\u7528 Zig \u66ff\u6362\u4e86 TypeScript\uff0c\u5728\u5185\u5b58\u5b89\u5168\u548c\u6027\u80fd\u4e0a\u505a\u4e86\u8fdb\u4e00\u6b65\u7684\u63a2\u7d22\u3002<\/p>\n<p><strong>Violin agent \u7684\u67b6\u6784\u5982\u4e0b\uff1a<\/strong><\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124033\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><strong>Why Zig?<\/strong><\/p>\n<p>Violin \u7684\u67b6\u6784\u8bbe\u8ba1\u6df1\u5ea6\u501f\u9274\u4e86 Pi \u7684\u4e09\u5c42\u5206\u79bb\u548c EventBus \u65b9\u6848\uff0c\u4f46\u5728\u5b9e\u73b0\u8bed\u8a00\u4e0a\u505a\u4e86\u5b8c\u5168\u4e0d\u540c\u7684\u9009\u62e9\u3002\u65e2\u7136\u6bcf\u4e00\u5c42\u901a\u8fc7\u63a5\u53e3\uff08\u6216\u7f51\u7edc\u534f\u8bae\uff09\u89e3\u8026\uff0c\u90a3\u4e48\u4e0d\u540c\u5c42\u7528\u4e0d\u540c\u8bed\u8a00\u5b9e\u73b0\u662f\u5b8c\u5168\u53ef\u884c\u7684\u2014\u2014\u4e0d\u9700\u8981\u4e5f\u4e0d\u53ef\u80fd\u300c\u5168\u90e8\u7528\u4e00\u79cd\u8bed\u8a00\u5199\u5b8c\u300d\u3002<\/p>\n<p>Violin \u7684\u5206\u5de5\u662f\uff1aAgent Loop\u3001\u6a21\u578b\u9002\u914d\u3001\u4f1a\u8bdd\u7ba1\u7406\u7b49\u5e95\u5c42\u5f15\u64ce\u7528 Zig \u5b9e\u73b0\uff0c\u8ffd\u6c42\u6781\u81f4\u7684\u6027\u80fd\u548c\u5185\u5b58\u53ef\u63a7\u6027\uff1b\u800c Client \u7aef\u7528 Python \u5b9e\u73b0\uff0c\u5229\u7528 Python \u7684\u751f\u6001\u5feb\u901f\u642d\u5efa\u7ec8\u7aef\u4ea4\u4e92 UI\u3002<\/p>\n<p>\u4e24\u8005\u901a\u8fc7 TCP + JSON line \u534f\u8bae\u901a\u4fe1\uff0cServer \u4e0d\u5173\u5fc3 Client \u7528\u4ec0\u4e48\u8bed\u8a00\u5199\u7684\u3002\u7b14\u8005\u7684\u6280\u672f\u6808\u6070\u597d\u662f Zig + Python\uff0c\u4e0d\u4f1a JS\u3001\u4e0d\u719f\u6089 Rust\uff0c\u4f46\u8fd9\u4e2a\u7ec4\u5408\u6b63\u597d\u8986\u76d6\u4e86\u300c\u5f15\u64ce\u300d\u548c\u300c\u754c\u9762\u300d\u4e24\u7aef\uff0c\u5206\u5de5\u6e05\u695a\uff0c\u5404\u53d6\u6240\u957f\u3002<\/p>\n<h3>\u6bcf\u5c42\u4e3a\u4ec0\u4e48\u5b58\u5728<\/h3>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124034\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h4>ai\uff1a\u628a\u4f9b\u5e94\u5546\u62cd\u5e73<\/h4>\n<p>\u4e0d\u540c\u6a21\u578b API \u5bf9\u5de5\u5177\u8c03\u7528\u3001\u63a8\u7406\u5185\u5bb9\u3001\u7f13\u5b58\u3001\u9519\u8bef\u3001OAuth\u3001\u6d41\u5f0f\u534f\u8bae\u7684\u8868\u8fbe\u90fd\u4e0d\u540c\u3002Violin \u628a\u8fd9\u4e9b\u5dee\u5f02\u7edf\u4e00\u6210 Message\u3001Tool\u3001AssistantMessageEvent \u548c streamSimple()\u3002<\/p>\n<p>\u8fd9\u6837\u4e0a\u5c42 Agent Loop \u4e0d\u9700\u8981\u77e5\u9053\u300c\u8fd9\u662f Anthropic \u7684 tool_use\uff0c\u8fd8\u662f OpenAI Responses \u7684 function call\u300d\u3002\u5b83\u53ea\u5173\u5fc3\u7edf\u4e00\u540e\u7684 toolCall \u5185\u5bb9\u5757\u3002<\/p>\n<h4>agent-core\uff1a\u53ea\u7ba1 Agent \u8fd0\u884c\u65f6<\/h4>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124035\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h4>product\uff1a\u628a Agent \u53d8\u6210\u53ef\u7528\u4ea7\u54c1<\/h4>\n<p>\u5199\u4e00\u4e2a Agent Loop \u4e0d\u96be\uff0c\u96be\u7684\u662f\u628a\u5b83\u53d8\u6210\u6bcf\u5929\u80fd\u7528\u7684\u5f00\u53d1\u5de5\u5177\u3002\u4ea7\u54c1\u5c42\u8d1f\u8d23\u8fd9\u4e9b\u300c\u9ebb\u70e6\u4f46\u5173\u952e\u300d\u7684\u4e8b\u60c5\uff1a<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124036\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h4>server\uff1a\u628a Agent \u80fd\u529b\u5305\u88c5\u4e3a\u4e00\u4e2aTCP Server<\/h4>\n<p>\u4e3a\u4e86\u8ba9\u5ba2\u6237\u7aef\u5b9e\u73b0\u4e0e\u8bed\u8a00\u65e0\u5173\uff0c\u6211\u4eec\u9700\u8981\u5c06 agent \u80fd\u529b\u5305\u88c5\u4e3a\u4e00\u5957\u901a\u4fe1\u534f\u8bae + \u4e00\u4e2a TCPServer\u3002TCPServer \u6d41\u5f0f\u901a\u4fe1 + \u5168\u53cc\u5de5\uff0c\u5929\u751f\u9002\u5408\u8fd9\u4e2a\u573a\u666f\u3002<\/p>\n<h2>\u56db\u3001\u5206\u5c42\u5b9e\u73b0\u4ecb\u7ecd<\/h2>\n<h3>Agent Loop\uff08\u4e00\u5207\u7684\u6838\u5fc3\uff09<\/h3>\n<p>Agent Loop \u662f\u4ec0\u4e48\uff1f\u4e00\u4e2a while \u5faa\u73af\uff0c\u5728\u300c\u95ee\u6a21\u578b\u300d\u548c\u300c\u6267\u884c\u5de5\u5177\u300d\u4e4b\u95f4\u6765\u56de\u5207\u6362\uff0c\u76f4\u5230\u6a21\u578b\u7ed9\u51fa\u6700\u7ec8\u7b54\u6848\u3002\u5b83\u4e0d\u5173\u5fc3\u6a21\u578b\u662f OpenAI \u8fd8\u662f Anthropic\uff0c\u4e0d\u5173\u5fc3\u5de5\u5177\u662f\u8bfb\u6587\u4ef6\u8fd8\u662f\u8dd1\u547d\u4ee4\uff0c\u53ea\u5173\u5fc3\u4e24\u4ef6\u4e8b\uff1a\u6a21\u578b\u8981\u4e0d\u8981\u8c03\u5de5\u5177\uff1f\u5982\u679c\u8981\uff0c\u8c03\u5b8c\u7ee7\u7eed\u95ee\uff1b\u5982\u679c\u4e0d\u8981\uff0c\u7ed3\u675f\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124037\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u8fd9\u662f Agent Loop \u7684\u6838\u5fc3\u4ee3\u7801\uff08\u7b80\u5316\u540e\uff09\uff1a<\/p>\n<pre><code>while (turn &lt; max_turns) : (turn += 1) {\n   \/\/ 1. \u8c03\u6a21\u578b\n   const assistant = try model.complete(.{\n       .messages = messages.items,\n       .tools = tool_registry.definitions(),\n   });\n\n   \/\/ 2. \u68c0\u67e5\u662f\u5426\u6709\u5de5\u5177\u8c03\u7528\n   const has_tool_calls = assistant.toolCalls().len &gt; 0;\n\n   \/\/ 3. \u6ca1\u6709 \u2192 \u7ed3\u675f\uff1b\u6709 \u2192 \u9010\u4e2a\u6267\u884c\u5de5\u5177\n   if (!has_tool_calls) break;\n\n   for (assistant.content) |block| {\n       if (block == .tool_call) {\n           const result = tool_registry.execute(tc.name, tc.args);\n           messages.append(result);  \/\/ \u56de\u5199\u7ed9\u6a21\u578b\n       }\n   }\n}<\/code><\/pre>\n<p><strong>\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li><strong>\u4e3a\u4ec0\u4e48\u8981\u6709 max_turns <\/strong>\u2014 \u6a21\u578b\u53ef\u80fd\u9677\u5165\u65e0\u9650\u5de5\u5177\u5faa\u73af\uff0c\u4e0a\u9650\u662f\u5b89\u5168\u9600\u3002<\/li>\n<li><strong>\u4e3a\u4ec0\u4e48\u5de5\u5177\u7ed3\u679c\u8981 append \u56de messages<\/strong> \u2014 \u6a21\u578b\u9700\u8981\u770b\u5230\u7ed3\u679c\u624d\u80fd\u51b3\u5b9a\u4e0b\u4e00\u6b65\u3002<\/li>\n<li><strong>\u4e3a\u4ec0\u4e48 tools \u5b9a\u4e49\u8981\u4f20\u8fdb complete()<\/strong> \u2014 \u6a21\u578b\u8981\u63d0\u524d\u77e5\u9053\u6709\u54ea\u4e9b\u5de5\u5177\u53ef\u7528\u3002<\/li>\n<\/ul>\n<p>\u5f53\u7136\u4e0d\u7ba1\u662f LLM \u8c03\u7528\u8fd8\u662f\u5de5\u5177\u8c03\u7528\uff0c\u90fd\u6709\u5931\u8d25\u7684\u53ef\u80fd\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u5728 AgentLoop \u8fd9\u4e00\u5c42\u52a0\u5165\u91cd\u8bd5\u673a\u5236\u3002\u9996\u5148\u6211\u4eec\u9700\u8981\u533a\u5206\u9519\u8bef\u79cd\u7c7b\uff0c\u662f\u4e0d\u662f\u4e00\u4e2a\u53ef\u4ee5\u91cd\u8bd5\u7684\u9519\u8bef\uff0cViolin \u4e2d\u505a\u4e86\u7b80\u5355\u5206\u7c7b\uff1a<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124038\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>Agent Loop \u53ea\u5173\u5fc3\u300c\u5faa\u73af\u300d\uff0c\u4e0d\u5173\u5fc3\u6d88\u606f\u4ece\u54ea\u91cc\u6765\u3001\u6267\u884c\u7ed3\u679c\u5b58\u5230\u54ea\u91cc\u3002\u8fd9\u4e9b\u300c\u5faa\u73af\u4e4b\u5916\u300d\u7684\u4e8b\u2014\u2014\u4f1a\u8bdd\u5386\u53f2\u7684\u52a0\u8f7d\u548c\u4fdd\u5b58\u3001\u4e0a\u4e0b\u6587\u538b\u7f29\u540e\u7684\u91cd\u8bd5\u3001Arena \u5185\u5b58\u7ba1\u7406\u2014\u2014\u7531\u4e0a\u4e00\u5c42\u4ea7\u54c1\u5c42\uff08product\/agent.zig\uff09\u5c01\u88c5\u3002<\/p>\n<p>agent.zig \u8c03\u7528 loop.run() \u65f6\u4f20\u5165\u5386\u53f2\u6d88\u606f\uff0cloop \u8fd4\u56de\u540e\u5b83\u8d1f\u8d23\u628a\u65b0\u6d88\u606f\u6301\u4e45\u5316\u5230 Session\uff0c\u5e76\u5728 ContextOverflow \u65f6\u622a\u65ad\u4e0a\u4e0b\u6587\u91cd\u8bd5\u3002<\/p>\n<h3>AI \u6a21\u578b\u9002\u914d\u5c42\uff08Agent Loop \u8c03\u7528\u7684\u662f\u8c01\uff09<\/h3>\n<p>\u6a21\u578b\u9002\u914d\u5c42\u7684\u804c\u8d23\u53ea\u6709\u4e00\u53e5\u8bdd\uff1a\u628a\u4e0d\u540c LLM Provider \u7684 API \u5dee\u5f02\u5c01\u88c5\u5728\u4e00\u4e2a Model.complete() \u63a5\u53e3\u540e\u9762\u3002Agent Loop \u53ea\u8ba4\u8fd9\u4e2a\u63a5\u53e3\uff0c\u4e0d\u5173\u5fc3\u80cc\u540e\u662f OpenAI \u8fd8\u662f Anthropic\u3002<\/p>\n<p><strong>\u7b80\u5316\u540e\u7684\u6838\u5fc3\u903b\u8f91\uff08\u4f2a\u4ee3\u7801\uff09\uff1a<\/strong><\/p>\n<pre><code>interface ModelAdapter {\n    complete(input: CompleteInput) -&gt; AssistantMessage\n    name() -&gt; string\n}\n\n\/\/ \u6bcf\u4e2a Provider \u5b9e\u73b0\u8fd9\u4e2a\u63a5\u53e3\uff1a\n\/\/ OpenAIAdapter      \u2014 \u8c03\u7528 \/chat\/completions\n\/\/ AnthropicAdapter   \u2014 \u8c03\u7528 \/v1\/messages\n\nstruct CompleteInput {\n    system_prompt: string,\n    messages: Message[],\n    tools: ToolDefinition[],\n    max_tokens: int,\n    temperature: float,\n    stream_callback: optional callback,  \/\/ \u6d41\u5f0f\u8f93\u51fa\n}<\/code><\/pre>\n<p>\u5b9e\u9645 Zig \u5b9e\u73b0\u4f7f\u7528\u51fd\u6570\u6307\u9488\u8868\uff08Zig \u6ca1\u6709 trait \u548c\u865a\u51fd\u6570\uff0c\u7528\u51fd\u6570\u6307\u9488\u5b9e\u73b0\u591a\u6001\uff09\uff0c\u6bcf\u4e2a\u9002\u914d\u5668\u63d0\u4f9b\u4e09\u4e2a\u51fd\u6570\u6307\u9488\uff08complete\u3001name\u3001deinit\uff09\uff0c\u901a\u8fc7\u7edf\u4e00\u63a5\u53e3\u8c03\u7528\u3002\u9002\u914d\u5668\u5185\u90e8\u72b6\u6001\uff08\u5982 base_url\/api_key\uff09\u901a\u8fc7\u7c7b\u578b\u64e6\u9664\u7684\u6307\u9488\u5728\u56de\u8c03\u4e2d\u8fd8\u539f\u3002<\/p>\n<p><strong>Violin \u9002\u914d\u4e86\u76ee\u524d\u6700\u6d41\u884c\u7684 2 \u79cd LLM \u534f\u8bae\uff1a<\/strong><\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124039\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4e24\u4e2a\u9002\u914d\u5668\u4ee3\u7801\u91cf\u5dee\u4e0d\u591a\uff08531 vs 558 \u884c\uff09\uff0c\u56e0\u4e3a\u5b83\u4eec\u5404\u81ea\u8981\u5904\u7406 JSON \u5e8f\u5217\u5316\u3001HTTP \u8bf7\u6c42\u3001SSE \u6d41\u5f0f\u89e3\u6790\u3001\u9519\u8bef\u6620\u5c04\u3002<strong>\u5dee\u5f02\u4e3b\u8981\u5728\uff1a<\/strong> \u8bf7\u6c42\u4f53\u683c\u5f0f\u4e0d\u540c\uff08OpenAI \u7528 messages[]\uff0cAnthropic \u7528 content[]\uff09\u3002\u5de5\u5177\u8c03\u7528\u7684\u7ed3\u6784\u4e0d\u540c\uff08OpenAI \u662f tool_calls[]\uff0cAnthropic \u662f content[] \u4e2d\u7684 tool_use block\uff09\u3002\u6d41\u5f0f\u534f\u8bae\u4e0d\u540c\uff08OpenAI \u7528 data: \u884c\uff0cAnthropic \u7528 event: \u884c\uff09\u3002<\/p>\n<p>LLM \u751f\u6210\u4e00\u4e2a\u56de\u7b54\u53ef\u80fd\u9700\u8981\u51e0\u79d2\u751a\u81f3\u5341\u51e0\u79d2\u3002\u5982\u679c\u7b49\u5168\u90e8\u751f\u6210\u5b8c\u518d\u8fd4\u56de\uff0c\u7528\u6237\u53ea\u80fd\u5e72\u7b49\u3002\u4e3a\u4e86\u5ba2\u6237\u7aef\u4f53\u9a8c\u7684\u6d41\u7545\uff0c\u76ee\u524d\u4e3b\u6d41 Agent \u90fd\u91c7\u7528\u4e86\u6d41\u5f0f\u8f93\u51fa\uff0c\u8fd9\u4e2a\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6848\u662f\u6d41\u5f0f\uff08SSE\uff09\u3002<\/p>\n<pre><code>\/\/ \u6a21\u578b\u9002\u914d\u5668\u5728\u6536\u5230 SSE \u7684\u6bcf\u4e2a chunk \u65f6\uff0c\u8c03\u7528 stream_callback\n\/\/ Agent Loop \u6536\u5230\u56de\u8c03\u540e\uff0c\u7acb\u5373\u901a\u8fc7 EventBus \u53d1\u5c04 message_update \u4e8b\u4ef6\n\/\/ Client \u6536\u5230\u4e8b\u4ef6\u540e\uff0c\u5b9e\u65f6\u8ffd\u52a0\u5230\u7ec8\u7aef\u663e\u793a\n\npub const StreamCallback = *const fn (ctx, chunk: StreamChunk) bool;<\/code><\/pre>\n<p>Violin \u6ca1\u6709\u5185\u7f6e\u4efb\u4f55\u6a21\u578b\uff0c\u5168\u90e8\u4ece ~\/.violin\/agent\/models.json \u4e2d\u52a0\u8f7d\u6a21\u578b\u914d\u7f6e\uff0c\u518d\u7531\u5ba2\u6237\u7aef\u51b3\u5b9a\u4f7f\u7528\u54ea\u4e2a\u6a21\u578b\uff1a<\/p>\n<pre><code>{\n&quot;providers&quot;: {\n   &quot;openai&quot;: {\n     &quot;base_url&quot;: &quot;https:\/\/api.openai.com\/v1&quot;,\n     &quot;api&quot;: &quot;openai-completions&quot;,\n     &quot;api_key&quot;: &quot;$OPENAI_API_KEY&quot;,\n     &quot;models&quot;: [\n       { &quot;id&quot;: &quot;gpt-4o&quot;, &quot;name&quot;: &quot;GPT-4o&quot;, &quot;contextWindow&quot;: 128000 }\n     ]\n   }\n }\n}<\/code><\/pre>\n<h3>Tool System\uff08Agent Loop\u7684\u624b\u548c\u811a\uff09<\/h3>\n<p>\u6a21\u578b\u9002\u914d\u5c42\u8ba9 Agent Loop \u53ef\u4ee5\u8c03\u4efb\u4f55\u6a21\u578b\uff0c\u5de5\u5177\u7cfb\u7edf\u8ba9 Agent Loop \u53ef\u4ee5\u505a\u4efb\u4f55\u4e8b\u3002<\/p>\n<p><strong>\u5de5\u5177\u7684\u5b9a\u4e49\uff1a<\/strong><\/p>\n<pre><code>pub const Tool = struct {\n  name: []const u8,\n  description: []const u8,\n  parameters: []const u8,  \/\/ JSON Schema\n  execute: ToolExecuteFn,\n};\n<\/code><\/pre>\n<p>Violin \u5185\u7f6e\u4e86 6 \u4e2a\u57fa\u672c\u5de5\u5177\uff0c\u548c Pi \u7684\u8bbe\u8ba1\u4fdd\u6301\u4e00\u81f4\uff1a<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124040\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4e3a\u4e86\u65b9\u4fbf\u7ba1\u7406\u8fd9\u4e9b tools\uff0cViolin \u4e2d\u5b9e\u73b0\u4e86\u4e00\u4e2a\u5de5\u5177\u6ce8\u518c\u8868\uff08\u4f2a\u4ee3\u7801\uff09\uff1a\u5b9e\u9645 Zig \u5b9e\u73b0\u4f7f\u7528 HashMap \u5b58\u50a8\u5de5\u5177\uff0c\u6309\u540d\u79f0\u5feb\u901f\u67e5\u627e\u3002definitions() \u5c06\u5de5\u5177\u5217\u8868\u7f16\u7801\u4e3a\u6a21\u578b\u53ef\u8bc6\u522b\u7684 JSON Schema \u683c\u5f0f\u3002<\/p>\n<pre><code>\/\/ \u7b80\u5316\u540e\u7684\u5de5\u5177\u6ce8\u518c\u8868\u903b\u8f91\uff1a\nclassToolRegistry:\n    tools: Map&lt;string, Tool&gt;\n\n    funcregister(name, description, execute_fn):\n        tools[name] = Tool(name, description, execute_fn)\n\n    func get(name) -&gt; Tool:\n        return tools[name]\n\n    func definitions() -&gt; ToolDefinition[]:\n        \/\/ \u8fd4\u56de\u6240\u6709\u5de5\u5177\u5b9a\u4e49\uff0c\u53d1\u9001\u7ed9\u6a21\u578b\n        return [t.definition() for t in tools.values()]\n\n    func execute(name, args) -&gt; ToolResult:\n        tool = tools[name]\n        return tool.execute(args)<\/code><\/pre>\n<h3>Product\u5c42\uff08\u5faa\u73af\u4e4b\u5916\u7684\u4e8b\uff09<\/h3>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124041\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h4>agent.zig \u2014 \u80f6\u6c34\u5c42\uff0c\u4f46\u6700\u5173\u952e<\/h4>\n<p>product\/agent.zig \u53ea\u6709 123 \u884c\uff0c\u5374\u662f\u628a\u6574\u4e2a\u9879\u76ee\u300c\u7c98\u8d77\u6765\u300d\u7684\u90a3\u5c42\u3002\u5b83\u505a\u7684\u4e8b\u60c5\u5f88\u7b80\u5355\uff1a<\/p>\n<ul>\n<li>\u4ece Session \u52a0\u8f7d\u5386\u53f2\u6d88\u606f\u3002<\/li>\n<li>\u4f20\u7ed9 loop.run () \u6267\u884c\u3002<\/li>\n<li>loop \u8fd4\u56de\u540e\uff0c\u628a\u6240\u6709\u65b0\u6d88\u606f\u4fdd\u5b58\u5230 Session\u3002<\/li>\n<li>\u5982\u679c loop \u629b\u4e86 ContextOverflow\uff0c\u8c03\u7528 compaction \u538b\u7f29\u540e\u91cd\u8bd5\u3002<\/li>\n<\/ul>\n<p><strong>\u5c55\u793a\u6838\u5fc3\u903b\u8f91\uff08\u7b80\u5316\uff09\uff1a<\/strong><\/p>\n<pre><code>\/\/ \u7b80\u5316\u540e\u7684 agent.run() \u903b\u8f91\uff1a\nfunc run(config, user_input) -&gt; AgentResult:\n    history = load_history(config.session)\n\n    while True:\n        loop_result = loop.run(\n            model=config.model,\n            initial_messages=history,\n            input=user_input\n        )\n\n        if loop_result == ContextOverflow:\n            compact_session()     \/\/ \u538b\u7f29\u5386\u53f2\uff0c\u4fdd\u7559\u5173\u952e\u4fe1\u606f\n            continue              \/\/ \u538b\u7f29\u540e\u91cd\u8bd5\n\n        \/\/ \u4fdd\u5b58\u65b0\u6d88\u606f\u5230\u4f1a\u8bdd\n        for msg in loop_result.new_messages:\n            session.appendMessage(msg)\n\n        return AgentResult(text=loop_result.final_text)<\/code><\/pre>\n<h4>session.zig \u2014 \u5bf9\u8bdd\u7684\u300c\u8bb0\u5fc6\u300d<\/h4>\n<p>\u6ca1\u6709 Session\uff0cAgent \u6bcf\u6b21\u5bf9\u8bdd\u90fd\u662f\u300c\u5931\u5fc6\u300d\u7684\u3002\u5b58\u50a8\u683c\u5f0f\uff1aJSONL\uff0c\u6bcf\u884c\u4e00\u4e2a\u72ec\u7acb JSON \u5bf9\u8c61\u3002\u7b2c\u4e00\u884c\u662f\u4f1a\u8bdd\u5934\uff08id, created_at, cwd\uff09\uff0c\u540e\u7eed\u6bcf\u884c\u662f\u4e00\u6761\u6d88\u606f\u3002<\/p>\n<pre><code>{&quot;id&quot;:&quot;sess_001&quot;,&quot;created_at&quot;:1717234567,&quot;cwd&quot;:&quot;\/project&quot;,&quot;model&quot;:&quot;gpt-4o&quot;}\n{&quot;id&quot;:1,&quot;parent_id&quot;:null,&quot;timestamp&quot;:1,&quot;role&quot;:&quot;user&quot;,&quot;content&quot;:&quot;\u5e2e\u6211\u8bfb README.md&quot;}\n{&quot;id&quot;:2,&quot;parent_id&quot;:1,&quot;timestamp&quot;:2,&quot;role&quot;:&quot;assistant&quot;,&quot;content&quot;:&quot;\u6211\u6765\u5e2e\u4f60\u8bfb...&quot;}<\/code><\/pre>\n<p>violin \u4e3a\u4e86\u7ba1\u7406 Session\uff0c\u6dfb\u52a0\u4e00\u4e2a SessionStore \u7684\u6570\u636e\u7ed3\u6784<\/p>\n<pre><code>\/\/ \u7b80\u5316\u540e\u7684 SessionStore \u6570\u636e\u7ed3\u6784\uff1a\nclassSessionStore:\n    file_path: string          \/\/ JSONL \u6587\u4ef6\u8def\u5f84\n    entries: Map&lt;id, Entry&gt;    \/\/ \u6d88\u606f\u7d22\u5f15\uff0c\u652f\u6301\u968f\u673a\u8bbf\u95ee\n    leaf_id: int | null        \/\/ \u5f53\u524d\u53f6\u5b50\u8282\u70b9\uff08\u6700\u65b0\u6d88\u606f\uff09\n    next_id: int               \/\/ \u81ea\u589e ID\uff0c\u7528\u4e8e\u751f\u6210\u65b0\u6d88\u606f ID\n    header: SessionHeader      \/\/ \u4f1a\u8bdd\u5934\u4fe1\u606f<\/code><\/pre>\n<p>\u5b9e\u9645 Zig \u5b9e\u73b0\u4f7f\u7528 ArenaAllocator \u7edf\u4e00\u7ba1\u7406\u5185\u5b58\uff08\u6240\u6709\u5206\u914d\u6765\u81ea arena\uff0cdeinit \u65f6\u4e00\u6b21\u6027\u91ca\u653e\uff09\uff0c\u7701\u53bb\u9010\u6761 free \u7684\u9ebb\u70e6\u3002<\/p>\n<p><strong>\u6838\u5fc3\u65b9\u6cd5\u5982\u4e0b\uff1a<\/strong><\/p>\n<p><strong>\u6d88\u606f\u6301\u4e45\u5316 writeEntry \u7684\u6838\u5fc3\u903b\u8f91\uff08\u4f2a\u4ee3\u7801\uff09\uff1a<\/strong><\/p>\n<pre><code>\/\/ \u7b80\u5316\u540e\u7684\u6d88\u606f\u6301\u4e45\u5316\u903b\u8f91\uff1a\nfunc writeEntry(entry):\n    json_line = serialize_to_json(entry) + &quot;\/n&quot;\n    \/\/ \u5199\u5165\u4e34\u65f6\u6587\u4ef6\uff0c\u7136\u540e\u8ffd\u52a0\u5230\u4f1a\u8bdd\u6587\u4ef6\n    \/\/ \u7528\u4e34\u65f6\u6587\u4ef6\u65b9\u5f0f\uff0c\u907f\u514d\u5904\u7406\u7279\u6b8a\u5b57\u7b26\u7684\u9ebb\u70e6\n    write_temp_file(json_line)\n    append_to_session_file(temp_file)<\/code><\/pre>\n<p><strong>\u8ffd\u52a0\u6d88\u606f\uff08\u4f2a\u4ee3\u7801\uff09\uff1a<\/strong><\/p>\n<pre><code>\/\/ \u7b80\u5316\u540e\u7684\u8ffd\u52a0\u6d88\u606f\u903b\u8f91\uff1a\nfunc appendMessage(message) -&gt; entry_id:\n    id = next_id++\n    entry = Entry(\n        id: id,\n        parent_id: current_leaf_id,  \/\/ \u6302\u5728\u5f53\u524d\u6d88\u606f\u540e\u9762\n        timestamp: now(),\n        message: message\n    )\n    entries[id] = entry\n    leaf_id = id                     \/\/ \u65b0\u6d88\u606f\u6210\u4e3a\u6700\u65b0\u6d88\u606f\n    writeEntry(entry)                \/\/ \u6301\u4e45\u5316\u5230 JSONL \u6587\u4ef6\n    return id<\/code><\/pre>\n<h4>session \u4ece\u6587\u4ef6\u6062\u590d\uff08\u4f2a\u4ee3\u7801\uff09\uff1a<\/h4>\n<pre><code>\/\/ \u7b80\u5316\u540e\u7684\u4f1a\u8bdd\u6062\u590d\u903b\u8f91\uff1a\nfunc load():\n    if not file_exists(file_path):\n        createSession()       \/\/ \u6587\u4ef6\u4e0d\u5b58\u5728\uff0c\u65b0\u5efa\u4f1a\u8bdd\n        return\n\n    for each line in read_lines(file_path):\n        if is_first_line:\n            header = parse_header(line)  \/\/ \u9996\u884c = \u4f1a\u8bdd\u5934\n            is_first_line = false\n        else:\n            entry = parse_entry(line)    \/\/ \u540e\u7eed\u884c = \u6d88\u606f\n            if entry is valid:\n                entries[entry.id] = entry\n            else:\n                log_warn(&quot;\u8df3\u8fc7\u635f\u574f\u7684\u6d88\u606f&quot;)  \/\/ \u635f\u574f\u884c\u8df3\u8fc7\uff0c\u4e0d\u5d29<\/code><\/pre>\n<p><strong>\u4e0e Pi \u7684\u5bf9\u6bd4\uff1a<\/strong> Pi \u7684 Session \u4e5f\u662f JSONL + \u6811\u7ed3\u6784\uff0c\u652f\u6301\u4e86\u6811\u5f62\u5bf9\u8bdd\u7ed3\u6784\uff0c\u652f\u6301\u5206\u652f fork \u548c\u56de\u6eda\uff0cViolin \u7ee7\u627f\u4e86\u8fd9\u4e9b\u80fd\u529b\u3002<\/p>\n<h4>compaction.zig \u2014 \u5bf9\u8bdd\u7684\u300c\u8111\u5bb9\u91cf\u7ba1\u7406\u300d<\/h4>\n<p>\u5f53 token \u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u628a\u65e7\u6d88\u606f\u538b\u7f29\u6210\u4e00\u6761\u6458\u8981\uff0c\u4fdd\u7559\u6700\u8fd1 N \u6761\u6d88\u606f\u3002Agent \u5c42\u7684\u91cd\u8bd5\u5faa\u73af\u4f1a\u68c0\u67e5\u538b\u7f29\u7ed3\u679c\u5e76\u91cd\u65b0\u6267\u884c loop\u3002<\/p>\n<p>LLM \u6709\u4e0a\u4e0b\u6587\u7a97\u53e3\u9650\u5236\uff0c\u4e00\u4e2a Coding Agent \u7684\u5bf9\u8bdd\u53ef\u80fd\u6301\u7eed\u51e0\u5341\u8f6e\uff0c\u7d2f\u79ef\u6570\u5343 token\u3002\u5982\u679c\u4e0d\u505a\u5904\u7406\uff0c\u65e9\u671f\u6d88\u606f\u4f1a\u88ab\u7a97\u53e3\u622a\u65ad\uff0c\u6a21\u578b\u300c\u5fd8\u8bb0\u300d\u4e86\u4e4b\u524d\u7684\u4e0a\u4e0b\u6587\u3002\u5f53 token \u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u628a\u65e7\u6d88\u606f\u538b\u7f29\u6210\u4e00\u6761\u6458\u8981\uff0c\u4fdd\u7559\u6700\u8fd1\u7684\u6d88\u606f\u4e0d\u53d8\u3002<\/p>\n<pre><code>\u538b\u7f29\u524d:\n[\u6d88\u606f1] [\u6d88\u606f2] [\u6d88\u606f3] ... [\u6d88\u606fN-10] [\u6d88\u606fN-9] ... [\u6d88\u606fN]\n\n\u538b\u7f29\u540e:\n[\u6458\u8981: \u4e4b\u524d\u8ba8\u8bba\u7684\u8981\u70b9] [\u6d88\u606fN-9] [\u6d88\u606fN-8] ... [\u6d88\u606fN]<\/code><\/pre>\n<p><strong>\u6838\u5fc3\u8bbe\u8ba1\uff1a<\/strong><\/p>\n<p><strong>Token \u9884\u7b97<\/strong><\/p>\n<pre><code>\/\/ \u4e0d\u5f15\u5165 tokenizer\uff0c\u7528 \u5b57\u7b26\u6570\/4 \u8fd1\u4f3c\u3002\u591f\u7528\u5c31\u884c\u2014\u2014\u538b\u7f29\u51b3\u7b56\u4e0d\u9700\u8981\u7cbe\u786e\u5230\u4e2a\u4f4d\u6570\u3002\npub fn estimateTokens(text: []const u8) usize {\n   return text.len \/ 4;\n}<\/code><\/pre>\n<p><strong>-\u89e6\u53d1\u6761\u4ef6<\/strong><\/p>\n<pre><code>func needsCompaction(messages, config) -&gt; bool:\n    return estimateMessagesTokens(messages) &gt; config.max_tokens\n\u9ed8\u8ba4\u9608\u503c 100K token\uff0c\u4fdd\u7559\u6700\u8fd1 10 \u6761\u6d88\u606f\uff0c\u6458\u8981\u76ee\u6807\u957f\u5ea6 500 token\u3002<\/code><\/pre>\n<p><strong>\u6458\u8981\u751f\u6210<\/strong><\/p>\n<pre><code>\u628a\u65e7\u6d88\u606f\u62fc\u63a5\u6210\u6587\u672c\uff0c\u8c03\u7528\u6a21\u578b\u751f\u6210\u6458\u8981\uff1a\n[user]: \u5e2e\u6211\u5199\u4e00\u4e2a HTTP \u670d\u52a1\u5668\n[assistant]: \u53ef\u4ee5\u7528 Zig \u7684 std.http...\n[tool_call]: write_file(&quot;server.zig&quot;, ...)\n[tool_result]: \u6587\u4ef6\u5df2\u5199\u5165\n\n---&gt;\n\u7528\u6237\u8981\u6c42\u7f16\u5199 HTTP \u670d\u52a1\u5668\uff0c\u52a9\u624b\u4f7f\u7528 Zig \u6807\u51c6\u5e93\u521b\u5efa\u4e86 server.zig\uff0c\u5b9e\u73b0\u4e86\u57fa\u672c\u7684\u8bf7\u6c42\u5904\u7406\u3002\n<\/code><\/pre>\n<p><strong>violin \u7684\u538b\u7f29\u7cfb\u7edf\u5206\u6210\u4e86 2 \u5c42\uff1a<\/strong><\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124042\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h4>resources.zig \u2014 \u8d44\u6e90\u52a0\u8f7d\u300c\u4e3aAgent\u6ce8\u5165\u7075\u9b42\u300d<\/h4>\n<p>Resources \u4ece\u6587\u4ef6\u7cfb\u7edf\u52a0\u8f7d\u9879\u76ee\u89c4\u5219\uff08AGENTS.md\uff09\u548c\u6280\u80fd\uff08SKILL.md\uff09\uff0c\u89e3\u6790 frontmatter\uff0c\u683c\u5f0f\u5316\u4e3a system prompt \u6ce8\u5165\u7ed9 LLM\uff0c\u8ba9\u6a21\u578b\u77e5\u9053\u5b83\u6709\u54ea\u4e9b\u5de5\u5177\u548c\u80fd\u529b\u53ef\u7528\u3002ResourceLoader \u8d1f\u8d23\u4ece\u6587\u4ef6\u7cfb\u7edf\u52a0\u8f7d\u4e09\u7c7b\u8d44\u6e90\uff0c\u683c\u5f0f\u5316\u4e3a system prompt \u4f9b LLM \u4f7f\u7528\uff1a<\/p>\n<ul>\n<li><strong>\u9879\u76ee\u89c4\u5219<\/strong> \u2014 AGENTS.md\/ CLAUDE.md\u3002<\/li>\n<li><strong>\u6280\u80fd<\/strong> \u2014 .agent\/skills\/ \u4e0b\u7684 SKILL.md \u6587\u4ef6\u3002<\/li>\n<\/ul>\n<p><strong>\u6570\u636e\u7ed3\u6784\uff08\u4f2a\u4ee3\u7801\uff09\u5982\u4e0b\uff1a<\/strong><\/p>\n<pre><code>\/\/ \u7b80\u5316\u540e\u7684\u6570\u636e\u7ed3\u6784\uff1a\nstruct Skill {\n    name: string           \/\/ \u6280\u80fd\u540d\u79f0\n    description: string    \/\/ \u6280\u80fd\u63cf\u8ff0\n    filePath: string       \/\/ SKILL.md \u6587\u4ef6\u8def\u5f84\n    source: enum           \/\/ &quot;global&quot; \u6216 &quot;project&quot;\n    content: string        \/\/ SKILL.md \u539f\u6587\n}\n\nstruct Resources {\n    rules: ProjectRules\n    skills: Skill[]\n    cwd: string\n}<\/code><\/pre>\n<p><strong>\u8d44\u6e90\u7684\u641c\u7d22\u8def\u5f84\u5982\u4e0b\uff1a<\/strong><\/p>\n<pre><code>\u9879\u76ee\u89c4\u5219\uff08\u4f18\u5148\u7ea7\u4ece\u9ad8\u5230\u4f4e\uff09:\n {cwd}\/AGENTS.md\n {cwd}\/CLAUDE.md\n ~\/.violin\/agent\/AGENTS.md\n ~\/.violin\/agent\/CLAUDE.md\n\n\u6280\u80fd\uff08\u9879\u76ee\u5148\uff0c\u5168\u5c40\u540e\uff0c\u540c\u540d\u51b2\u7a81\u65f6\u9879\u76ee\u8d62\uff09:\n {cwd}\/.agent\/skills\/*\/SKILL.md\n {cwd}\/.agents\/skills\/*\/SKILL.md\n ~\/.violin\/agent\/skills\/*\/SKILL.md\n\nloadAll()\n \u251c\u2500 loadProjectRules()\n \u2502   \u251c\u2500 \u5c1d\u8bd5 {cwd}\/AGENTS.md\n \u2502   \u251c\u2500 \u5c1d\u8bd5 {cwd}\/CLAUDE.md\n \u2502   \u251c\u2500 \u5c1d\u8bd5 ~\/.violin\/agent\/AGENTS.md\n \u2502   \u2514\u2500 \u5c1d\u8bd5 ~\/.violin\/agent\/CLAUDE.md\n \u2502\n \u2514\u2500 loadSkills()\n     \u251c\u2500 \u626b\u63cf {cwd}\/.agent\/skills\/*\/SKILL.md\n     \u251c\u2500 \u626b\u63cf {cwd}\/.agents\/skills\/*\/SKILL.md\n     \u2514\u2500 \u626b\u63cf ~\/.violin\/agent\/skills\/*\/SKILL.md\n         \u2514\u2500 \u540c\u540d\u51b2\u7a81\u65f6\u62a5\u544a diagnostic\uff0c\u8df3\u8fc7<\/code><\/pre>\n<p>SKILL.md \u6587\u4ef6\u90fd\u4f1a\u643a\u5e26\u4e00\u4e2a YAML frontmatter\uff0cviolin \u4f1a\u89e3\u6790\u8fd9\u90e8\u5206\u5185\u5bb9\uff0c\u5e76\u6784\u5efa\u6210\u4e00\u4e2a XML \u6570\u636e\uff0c\u6700\u7ec8\u4f1a\u6ce8\u5165\u5230\u7cfb\u7edf\u63d0\u793a\u8bcd\u4e2d\uff1a<\/p>\n<pre><code>&lt;available_skills&gt;\n    &lt;skill&gt;\n      &lt;name&gt;basedpyright&lt;\/name&gt;\n      &lt;description&gt;Python static type checking&lt;\/description&gt;\n      &lt;location&gt;\/path\/to\/skill\/SKILL.md&lt;\/location&gt;\n    &lt;\/skill&gt;\n&lt;\/available_skills&gt;<\/code><\/pre>\n<h3>Event System\uff08\u63d2\u4ef6\u5b9e\u73b0\u7684\u57fa\u7840\uff09<\/h3>\n<p>Agent Loop \u5728\u8dd1\uff0c\u4f46\u5916\u754c\u600e\u4e48\u77e5\u9053\u5b83\u8dd1\u5230\u4e86\u54ea\u4e00\u6b65\uff1f\u2014\u2014 \u4e8b\u4ef6\u7cfb\u7edf\u5c31\u662f\u7b54\u6848\u3002Agent Loop \u6bcf\u505a\u4e00\u4ef6\u4e8b\uff08\u5f00\u59cb\u4e00\u8f6e\u3001\u751f\u6210\u4e00\u4e2a token\u3001\u8c03\u4e00\u4e2a\u5de5\u5177\uff09\uff0c\u5c31\u5f80 EventBus \u4e0a\u53d1\u4e00\u4e2a\u4e8b\u4ef6\u3002\u8c01\u5173\u5fc3\u8fd9\u4e2a\u4e8b\u4ef6\uff0c\u8c01\u5c31\u6ce8\u518c\u56de\u8c03\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124043\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u63d2\u4ef6\u7684\u4f18\u52bf\u5728\u4e8e\u5373\u63d2\u5373\u7528\u3001\u52a8\u6001\u52a0\u8f7d\uff0c\u521a\u5f00\u59cb\u8003\u8651\u6709\u5982\u4e0b\u7684\u65b9\u6848\uff1a<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124044\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u6700\u7ec8\u6211\u9009\u4e86 Lua\u3002\u4e0d\u662f\u56e0\u4e3a Lua \u662f\u6700\u597d\u7684\u8bed\u8a00\uff0c\u800c\u662f\u56e0\u4e3a\u5b83\u662f\u6700\u5c0f\u7684\u5bf9\u7684\u90a3\u4e00\u4e2a\u3002500KB \u7684\u8fd0\u884c\u65f6\uff0c20 \u5e74 proven \u7684\u5d4c\u5165\u573a\u666f\uff08\u4ece WoW \u5230 Redis \u5230 Nginx\uff09\uff0c\u4e00 C \u51fd\u6570\u5c31\u80fd\u8c03 \u2014 \u5bf9 Zig \u9879\u76ee\u6765\u8bf4\uff0c\u8fd9\u662f\u8def\u5f84\u6700\u77ed\u7684\u9009\u62e9\u3002<\/p>\n<p><strong>\u63d2\u4ef6\u7cfb\u7edf\u7684\u67b6\u6784\u5982\u4e0b\uff1a<\/strong><\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124045\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u6838\u5fc3\u673a\u5236\u975e\u5e38\u7b80\u5355\uff1aEventBus \u6709\u4e09\u4e2a\u56de\u8c03\u69fd\uff08agent \/session\/compaction\uff09\uff0cinstall () \u628a\u539f\u56de\u8c03\u4fdd\u5b58\u4e0b\u6765\uff0c\u6362\u6210\u81ea\u5df1\u7684 dispatch \u5305\u88c5\u51fd\u6570\u3002\u5148\u6267\u884c\u539f\u56de\u8c03\uff08\u5199 socket \u6d41\u5f0f\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\uff09\uff0c\u518d\u904d\u5386\u6240\u6709\u5df2\u6ce8\u518c\u7684 Lua \u63d2\u4ef6\uff0c\u9010\u4e2a\u8c03\u7528\u5bf9\u5e94\u7684 hook \u51fd\u6570\u3002<\/p>\n<p><strong>\u63d2\u4ef6\u957f\u4ec0\u4e48\u6837\u5b50\uff1f<\/strong><\/p>\n<pre><code>-- ~\/.violin\/plugins\/bash-guard.lua\nreturn {\n    name = &quot;bash-guard&quot;,\n    version = &quot;0.2.0&quot;,\n    description = &quot;\u62e6\u622a\u5371\u9669 bash \u547d\u4ee4\uff0c\u81ea\u52a8\u52a0\u5b89\u5168\u524d\u7f00&quot;,\n\n    -- tool_start\uff1a\u6267\u884c\u5de5\u5177\u524d\u62e6\u622a\n    on_tool_start = function(event)if event.tool_name == &quot;bash&quot; then-- \u963b\u6b62\u5371\u9669\u547d\u4ee4if event.arguments:find(&quot;rm -rf&quot;, 1, true) thenreturn { action = &quot;block&quot;, reason = &quot;\u5371\u9669\u547d\u4ee4\u5df2\u963b\u6b62&quot; }\n            end-- \u4fee\u6539\u547d\u4ee4\uff08\u52a0\u5b89\u5168\u524d\u7f00\uff09return { action = &quot;modify&quot;, arguments = &quot;set -e; &quot; .. event.arguments }\n        end-- \u4e0d return = allowend,\n\n    -- tool_end\uff1a\u4fee\u6539\u5de5\u5177\u6267\u884c\u7ed3\u679c\n    on_tool_end = function(event)if event.tool_name == &quot;bash&quot; and event.is_error thenreturn { action = &quot;modify&quot;, content = &quot;\u9519\u8bef\u5df2\u81ea\u52a8\u5904\u7406&quot;, is_error = false }\n        endend,\n\n    -- context\uff1a\u5728 LLM \u8c03\u7528\u524d\u6ce8\u5165\u7cfb\u7edf\u6307\u4ee4\n    on_context = function(event)return { action = &quot;modify&quot;, inject_text = &quot;\u4f7f\u7528 bash \u65f6\u6ce8\u610f\u5b89\u5168&quot;, inject_role = &quot;system&quot; }\n    end,\n\n    -- agent_start\uff1a\u963b\u6b62 agent \u542f\u52a8\n    on_agent_start = function(event)-- \u5728\u67d0\u4e9b\u6761\u4ef6\u4e0b\u963b\u6b62 agent \u542f\u52a8-- return { action = &quot;block&quot;, reason = &quot;\u5f53\u524d\u4e0d\u5141\u8bb8\u6267\u884c&quot; }end,\n\n    -- session_before_compact\uff1a\u963b\u6b62\u624b\u52a8\u538b\u7f29\n    on_session_before_compact = function(event)if event.reason == &quot;manual&quot; thenreturn { action = &quot;block&quot;, reason = &quot;\u7981\u6b62\u624b\u52a8\u538b\u7f29&quot; }\n        endend,\n}<\/code><\/pre>\n<h3>\u7f51\u7edc\u5c42\uff08\u5ba2\u6237\u7aef\u5b9e\u73b0\u7684\u57fa\u7840\uff09<\/h3>\n<p>\u7f51\u7edc\u5c42\u5b9a\u4e49\u4e86 Violin \u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u7aef\u4e4b\u95f4\u5982\u4f55\u901a\u4fe1 \u2014\u2014 \u5ba2\u6237\u7aef\u53d1\u4e00\u6761\u6d88\u606f\uff0c\u670d\u52a1\u7aef\u628a\u601d\u8003\u8fc7\u7a0b\u3001\u5de5\u5177\u8c03\u7528\u3001\u6700\u7ec8\u56de\u7b54\u4e00\u6761\u6761\u63a8\u9001\u7ed9\u5ba2\u6237\u7aef\uff0c\u5c31\u50cf\u770b\u4e00\u4e2a\u4eba\u8fb9\u60f3\u8fb9\u505a\u8fb9\u8bf4\u7684\u76f4\u64ad\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124046\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><strong>\u4e3a\u4ec0\u4e48\u662f C\/S \u67b6\u6784\uff1f<\/strong> \u5927\u591a\u6570 Coding Agent \u662f\u4e00\u4f53\u5f0f\u7684 \u2014\u2014Agent \u5f15\u64ce\u76f4\u63a5\u5d4c\u5165\u7f16\u8f91\u5668\u6216 CLI \u5de5\u5177\u91cc\uff0c\u542f\u52a8\u3001\u52a0\u8f7d\u6a21\u578b\u3001\u6267\u884c\u5de5\u5177\u3001\u7ba1\u7406\u4f1a\u8bdd\u90fd\u5728\u4e00\u4e2a\u8fdb\u7a0b\u91cc\u5b8c\u6210\u3002<\/p>\n<p>Violin \u9009\u62e9\u4e86\u524d\u540e\u7aef\u5206\u79bb\uff1a<\/p>\n<pre><code>\u4e00\u4f53\u5f0f:  [agent + UI + \u4f1a\u8bdd]  \u2014 \u4e00\u4e2a\u8fdb\u7a0b\uff0c\u8dd1\u5728\u672c\u5730\n\nViolin:  [Zig \u670d\u52a1\u7aef (daemon)]  \u2190TCP\/JSON-lines\u2192  [Python TUI \u5ba2\u6237\u7aef]\n                               \u4e5f\u53ef\u4ee5\u63a5\u5176\u4ed6\u5ba2\u6237\u7aef<\/code><\/pre>\n<p>\u8fd9\u4e2a\u8bbe\u8ba1\u9009\u62e9\u4e5f\u662f\u53d7\u5230\u4e86 ACP \u534f\u8bae\u7684\u542f\u53d1\uff0cACP \u534f\u8bae\u590d\u6742\u5ea6\u8f83\u9ad8\uff0c\u800c\u4e14 zig \u6ca1\u6709\u5f88\u597d\u7684 ACP \u5b9e\u73b0\u4f9d\u8d56\uff0cviolin \u4f5c\u4e3a\u4e00\u4e2a toy \u9879\u76ee\uff0c\u9009\u62e9\u4e86\u6700\u5c0f\u6700\u5bb9\u6613\u7684\u65b9\u5f0f \u2014\u2014<strong>TCP + JSON LINES<\/strong>\u3002<\/p>\n<p>\u6211\u5728\u9879\u76ee\u4e2d\u7ef4\u62a4\u4e86\u4e00\u4e2a\u8be6\u7ec6\u7684\u901a\u4fe1\u534f\u8bae\u8bf4\u660e\uff0c\u5982\u679c\u7528\u6237\u60f3\u7528\u5176\u4ed6\u8bed\u8a00\u5b9e\u73b0\u5ba2\u6237\u7aef\uff0c\u53ea\u9700\u8981\u628a\u901a\u4fe1\u534f\u8bae\u4ea4\u7ed9 AI \u5373\u53ef vibe \u51fa\u4e00\u4e2a\u65b0\u7684\u5ba2\u6237\u7aef\u3002<\/p>\n<p>\u53d7\u5230\u7bc7\u5e45\u9650\u5236\uff0c\u6211\u53ea\u7b80\u5355\u4ecb\u7ecd\u51e0\u4e2a\u6838\u5fc3\u534f\u8bae\uff1a<\/p>\n<h4>\u63e1\u624b<\/h4>\n<pre><code>\u5ba2\u6237\u7aef \u2192 \u670d\u52a1\u7aef:\n{&quot;type&quot;:&quot;handshake&quot;,&quot;cwd&quot;:&quot;\/home\/user\/project\/violin&quot;}\n\n\u670d\u52a1\u7aef \u2192 \u5ba2\u6237\u7aef:\n{&quot;type&quot;:&quot;models_result&quot;,&quot;models&quot;:[...],&quot;default&quot;:&quot;deepseek-v4-flash&quot;}\n{&quot;type&quot;:&quot;skills_result&quot;,&quot;global_skills&quot;:[...],&quot;project_skills&quot;:[...]}\ncwd \u7528\u4e8e\u52a0\u8f7d\u9879\u76ee\u6280\u80fd {cwd}\/.agent\/skills\/ \u548c\u6ce8\u5165\u7cfb\u7edf\u63d0\u793a\u8bcd\u3002<\/code><\/pre>\n<h4>\u804a\u5929\u8bf7\u6c42<\/h4>\n<pre><code>\u5ba2\u6237\u7aef \u2192 \u670d\u52a1\u7aef:\n{&quot;type&quot;:&quot;chat&quot;,&quot;content&quot;:&quot;\u5217\u51fa\u76ee\u5f55\u4e0b\u6587\u4ef6&quot;,&quot;model&quot;:&quot;deepseek-v4-flash&quot;}<\/code><\/pre>\n<p>\u53ef\u9009\u5b57\u6bb5\uff1asession_id\u3001temperature\u3001max_tokens\u3001system_prompt\u3001images\u3002<\/p>\n<h4>\u4e8b\u4ef6\u6d41<\/h4>\n<p>\u670d\u52a1\u7aef\u5904\u7406 chat \u8bf7\u6c42\u65f6\uff0c\u6d41\u5f0f\u63a8\u9001\u4e8b\u4ef6\u3002Violin \u8bbe\u8ba1\u4e86 8 \u4e2a\u4e8b\u4ef6\u7c7b\u578b\u6765\u5b8c\u5584\u5bf9\u8bdd\u9700\u6c42\uff1a<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124047\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u5b8c\u6574\u4e8b\u4ef6\u6d41\u793a\u4f8b\uff1a<\/p>\n<pre><code>\/\/ Client \u53d1\u9001\n\u2192 {&quot;type&quot;:&quot;chat&quot;,&quot;content&quot;:&quot;\u5e2e\u6211\u8bfb README.md&quot;}\/\/ Server \u5f00\u59cb\u6d41\u5f0f\u8fd4\u56de\n\u2190 {&quot;type&quot;:&quot;turn_start&quot;,&quot;session_id&quot;:&quot;sess_001&quot;,&quot;model&quot;:{&quot;id&quot;:&quot;gpt-4o&quot;,&quot;provider&quot;:&quot;openai&quot;,&quot;label&quot;:&quot;GPT-4o&quot;},&quot;context&quot;:{&quot;tokens&quot;:5400,&quot;window&quot;:128000,&quot;usage_pct&quot;:4.2}}\n\n\u2190 {&quot;type&quot;:&quot;delta&quot;,&quot;text&quot;:&quot;\u6211\u6765&quot;}\n\u2190 {&quot;type&quot;:&quot;delta&quot;,&quot;text&quot;:&quot;\u5e2e\u4f60&quot;}\n\u2190 {&quot;type&quot;:&quot;delta&quot;,&quot;text&quot;:&quot;\u8bfb&quot;}\n\n\u2190 {&quot;type&quot;:&quot;tool_start&quot;,&quot;name&quot;:&quot;read_file&quot;,&quot;args&quot;:{&quot;path&quot;:&quot;README.md&quot;}}\/\/ ... \u7b49\u5f85\u5de5\u5177\u6267\u884c ...\n\u2190 {&quot;type&quot;:&quot;tool_end&quot;,&quot;name&quot;:&quot;read_file&quot;,&quot;ok&quot;:true,&quot;output&quot;:&quot;# Violin\/n...&quot;}\n\n\u2190 {&quot;type&quot;:&quot;delta&quot;,&quot;text&quot;:&quot;\u6587\u4ef6&quot;}\n\u2190 {&quot;type&quot;:&quot;delta&quot;,&quot;text&quot;:&quot;\u5185\u5bb9\u662f\uff1a&quot;}\n\u2190 {&quot;type&quot;:&quot;delta&quot;,&quot;text&quot;:&quot;Violin\u662f\u4e00\u4e2aAI\u52a9\u624b&quot;}\n\n\u2190 {&quot;type&quot;:&quot;turn_end&quot;,&quot;turn&quot;:0,&quot;usage&quot;:{&quot;input_tokens&quot;:5400,&quot;output_tokens&quot;:18,&quot;cost_usd&quot;:0.0115}}\n\n\u2190 {&quot;type&quot;:&quot;result&quot;,&quot;text&quot;:&quot;\u6211\u6765\u5e2e\u4f60\u8bfb...&quot;,&quot;turns&quot;:1,&quot;aborted&quot;:false,&quot;session_id&quot;:&quot;sess_001&quot;,&quot;usage_total&quot;:{&quot;input_tokens&quot;:5400,&quot;output_tokens&quot;:18,&quot;cost_usd&quot;:0.0115}}<\/code><\/pre>\n<h4>Python Client \u5b9e\u73b0<\/h4>\n<p>\u6709\u4e86\u4e0a\u4e00\u8282\u7f51\u7edc\u534f\u8bae\u7684\u94fa\u57ab\uff0c\u6211\u4eec\u53ef\u4ee5\u5199\u4e00\u4e2a\u7b80\u5355\u7684 Violin Python \u5ba2\u6237\u7aef\u3002Python Client \u7684\u6838\u5fc3\u662f\u4e00\u4e2a async TCP \u8fde\u63a5 + \u4e8b\u4ef6\u5206\u53d1\u5668\uff1a<\/p>\n<pre><code>classViolinClient:\n&quot;&quot;&quot;Async Violin protocol client (no UI, just I\/O).&quot;&quot;&quot;\n\ndef__init__(self, host=&quot;127.0.0.1&quot;, port=9877):\n        self.reader = None\n        self.writer = None\n        self.models = []\n        self.session_id = &quot;&quot;\n\n# \u56de\u8c03\u2014\u2014UI \u5c42\u6ce8\u518c\u8fd9\u4e9b\uff0c\u5b9e\u73b0\u4e0e\u5c55\u793a\u5206\u79bb\n        self.on_delta = None\n        self.on_tool_start = None\n        self.on_tool_end = None\n        self.on_result = None\n        ...\n\nasyncdefconnect(self, retries=3):\n&quot;&quot;&quot;TCP \u8fde\u63a5 \u2192 handshake \u2192 \u6536 models_result + skills_result&quot;&quot;&quot;\nfor i inrange(retries):\ntry:\n                r, w = await asyncio.open_connection(*self.addr)\n                self.reader = r\n                self.writer = w\nawait self._send({&quot;type&quot;: &quot;handshake&quot;, &quot;cwd&quot;: os.getcwd()})\n                msg = await self._read_msg()\nif msg and msg.get(&quot;type&quot;) == &quot;models_result&quot;:\n                    self.models = msg.get(&quot;models&quot;, [])\nreturnTrue\nexcept ConnectionRefusedError:\nawait asyncio.sleep(0.5 * (2 ** i))\nreturnFalse\n\nasyncdefhandle_messages(self, state):\n&quot;&quot;&quot;\u4e8b\u4ef6\u5206\u53d1\u2014\u2014\u8bfb socket \u2192 \u6309 type \u8c03\u7528\u5bf9\u5e94\u56de\u8c03&quot;&quot;&quot;\nwhileTrue:\n            msg = await self._read_msg()\n            mt = msg.get(&quot;type&quot;, &quot;&quot;)\nif mt == &quot;delta&quot;:\n                state[&quot;full_text&quot;] += msg.get(&quot;text&quot;, &quot;&quot;)\nif self.on_delta:\n                    self.on_delta(msg[&quot;text&quot;])\nelif mt == &quot;tool_start&quot;:\nif self.on_tool_start:\n                    self.on_tool_start(msg[&quot;name&quot;], msg[&quot;args&quot;])\nelif mt == &quot;result&quot;:\n                self.session_id = msg.get(&quot;session_id&quot;, self.session_id)\nif self.on_result:\n                    self.on_result(msg[&quot;text&quot;], msg.get(&quot;usage_total&quot;, {}))\nreturn msg[&quot;text&quot;]\nelif mt == &quot;error&quot;:\nif self.on_error:\n                    self.on_error(msg[&quot;msg&quot;])\nreturn&quot;&quot;\nelif mt == &quot;ping&quot;:\nawait self._send({&quot;type&quot;: &quot;pong&quot;})\nreturn state[&quot;full_text&quot;]<\/code><\/pre>\n<h2>\u56db\u3001\u603b\u7ed3<\/h2>\n<p>\u6574\u4e2a\u9879\u76ee\u505a\u4e0b\u6765\uff0c\u6700\u5927\u7684\u611f\u53d7\u662f\uff1acoding agent \u7684\u6838\u5fc3\u6ca1\u6709\u4ec0\u4e48\u9b54\u6cd5\u3002\u5265\u5f00\u5404\u79cd\u82b1\u54e8\u7684 UI \u548c\u529f\u80fd\uff0c\u5e95\u5c42\u5c31\u662f\u4e00\u4e2a while \u5faa\u73af \u2014\u2014 \u95ee\u6a21\u578b\u3001\u62ff\u7ed3\u679c\u3001\u8981\u4e0d\u8981\u8c03\u5de5\u5177\u3001\u8c03\u5b8c\u518d\u95ee\u3002Violin \u7684\u6bcf\u4e00\u5c42\u90fd\u662f\u5728\u7ed9\u8fd9\u4e2a\u5faa\u73af\u6253\u8865\u4e01\uff1a<\/p>\n<ul>\n<li>\u6a21\u578b\u9002\u914d\u5c42\u89e3\u51b3 &#8220;\u95ee\u8c01&#8221;\u3002<\/li>\n<li>\u5de5\u5177\u7cfb\u7edf\u89e3\u51b3 &#8220;\u80fd\u5e72\u561b&#8221;\u3002<\/li>\n<li>\u8d44\u6e90\u5c42\u89e3\u51b3 &#8220;\u8bb0\u4e0d\u8bb0\u5f97\u4f4f\u3001SKILL \u5728\u54ea&#8221;\u3002<\/li>\n<li>\u63d2\u4ef6\u89e3\u51b3 &#8220;\u80fd\u529b\u6269\u5145&#8221;\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e2a\u73a9\u5177\u8ddd\u79bb\u4e00\u4e2a\u6210\u719f\u7684 Coding Agent \u8fd8\u6709\u4e00\u5806\u6ca1\u586b\u7684\u5751\uff1abuildJson \u91cc tools \u53c2\u6570\u8fd8\u6ca1\u5e8f\u5217\u5316\uff0c\u6a21\u578b\u6839\u672c\u6536\u4e0d\u5230\u5de5\u5177\u5b9a\u4e49\u3002\u63d2\u4ef6\u6ca1\u6709\u6743\u9650\u9694\u79bb\uff0cLua \u80fd\u5e72\u4efb\u4f55\u4e8b\u3002ACP \u534f\u8bae\u4e5f\u6ca1\u63a5\uff0c\u6682\u65f6\u53ea\u80fd\u81ea\u5df1\u8ddf\u81ea\u5df1\u73a9\u3002\u4f46\u4f5c\u4e3a\u4e00\u4e2a\u4ece\u96f6\u642d\u8d77\u6765\u7684 toy agent\uff0c\u8fd9\u4e2a\u9879\u76ee\u7684\u76ee\u7684\u4ece\u6765\u4e0d\u662f\u4ea4\u4ed8\u4e00\u4e2a\u5546\u7528\u4ea7\u54c1\uff0c\u800c\u662f\u9a8c\u8bc1\u4e00\u4e2a\u5224\u65ad\uff1a\u7406\u89e3\u4e86 coding agent \u7684\u6784\u5efa\u539f\u7406\uff0c\u4e5f\u5c31\u638c\u63e1\u4e86\u7406\u89e3\u5176\u4ed6 agent \u7684\u4e00\u628a\u94a5\u5319\u3002<\/p>\n<p>\u8fd9\u4e2a\u5224\u65ad\u5728\u6784\u5efa\u8fc7\u7a0b\u4e2d\u4e0d\u65ad\u88ab\u9a8c\u8bc1 \u2014\u2014 \u6a21\u578b\u7684\u7edf\u4e00\u9002\u914d\u3001\u5de5\u5177\u7684\u6ce8\u518c\u4e0e\u8c03\u5ea6\u3001\u4f1a\u8bdd\u7684\u6301\u4e45\u5316\u4e0e\u6062\u590d\u3001\u4e0a\u4e0b\u6587\u7684\u538b\u7f29\u4e0e\u4fdd\u7559\u3001\u63d2\u4ef6\u7684\u6ce8\u5165\u4e0e\u62e6\u622a\uff0c\u8fd9\u4e9b\u770b\u4f3c\u5404\u4e0d\u76f8\u5e72\u7684\u95ee\u9898\uff0c\u5e95\u5c42\u90fd\u6536\u655b\u5230\u540c\u4e00\u4e2a\u5faa\u73af\uff1a\u95ee\u6a21\u578b\u3001\u8c03\u5de5\u5177\u3001\u518d\u95ee\u3002\u5ba2\u670d agent \u7684\u4f1a\u8bdd\u7ba1\u7406\u3001\u6570\u636e\u5206\u6790 agent \u7684\u5de5\u5177\u94fe\u7f16\u6392\u3001\u5de5\u4f5c\u6d41 agent \u7684\u72b6\u6001\u673a\u8bbe\u8ba1 \u2014\u2014 \u8ffd\u6839\u6eaf\u6e90\uff0c\u90fd\u662f\u8fd9\u4e2a\u5faa\u73af\u5728\u4e0d\u540c\u573a\u666f\u4e0b\u7684\u53d8\u5f62\u3002<\/p>\n<p>\u5269\u4e0b\u90a3\u4e9b\u6ca1\u586b\u7684\u5751\uff0c\u65e2\u662f\u9879\u76ee\u5f53\u524d\u7684\u8fb9\u754c\uff0c\u4e5f\u662f\u4e0b\u4e00\u6bb5\u63a2\u7d22\u7684\u8d77\u70b9\u3002\u628a\u4e00\u4e2a toy \u9879\u76ee\u4e00\u8def\u8865\u5230\u80fd\u771f\u6b63\u843d\u5730\uff0c\u8fc7\u7a0b\u672c\u8eab\u5c31\u662f\u6700\u597d\u7684\u5b66\u4e60\u65b9\u5f0f\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048124048\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h2>\u5f80\u671f\u56de\u987e<\/h2>\n<p>1.<a href=\"https:\/\/segmentfault.com\/a\/1190000048094670\" target=\"_blank\" rel=\"noopener noreferrer\">AI Native \u4ea4\u6613\u6838\u5fc3\u7cfb\u7edf\u7684\u7814\u53d1\u8303\u5f0f\uff5c\u5f97\u7269\u6280\u672f<\/a><\/p>\n<p>2.<a href=\"https:\/\/segmentfault.com\/a\/1190000048085921\" target=\"_blank\" rel=\"noopener noreferrer\">\u63a8\u8350\u7cfb\u7edf\u4f53\u9a8c\u7684\u6570\u5b57\u5316\u7a81\u7834\uff1a\u5f97\u7269\u81ea\u52a8\u5316\u8bc4\u6d4b\u5e73\u53f0\u7684\u6280\u672f\u5b9e\u8df5\uff5cAICon \u6587\u7ae0\u6574\u7406 <\/a><\/p>\n<p>3.<a href=\"https:\/\/segmentfault.com\/a\/1190000048065163\" target=\"_blank\" rel=\"noopener noreferrer\">RAG \u6838\u5fc3\u6982\u5ff5\u4e0e\u539f\u7406\uff1aChunking\u3001Embedding\u3001\u76f8\u4f3c\u5ea6\u3001HNSW \u4e0e\u591a\u8def\u53ec\u56de\uff5c\u5f97\u7269\u6280\u672f<\/a><\/p>\n<p>4.<a href=\"https:\/\/segmentfault.com\/a\/1190000048031882\" target=\"_blank\" rel=\"noopener noreferrer\">\u4ece&#8221;\u673a\u68b0\u5e94\u7b54&#8221;\u5230&#8221;\u670d\u52a1\u4f19\u4f34&#8221;\uff1a\u5f97\u7269\u9ad8\u53ef\u63a7\u667a\u80fd\u5ba2\u670d\u7684 Agent \u5de5\u7a0b\u5b9e\u8df5\uff5cAICon \u6f14\u8bb2\u6574\u7406<\/a><\/p>\n<p>5.<a href=\"https:\/\/segmentfault.com\/a\/1190000048023688\" target=\"_blank\" rel=\"noopener noreferrer\">\u5f97\u7269\u63a8\u8350\u7cfb\u7edf\u8bca\u65ad Agent\uff1a\u4ece \u201c\u8c03\u63a5\u53e3\u201d \u5230 \u201c\u4f1a\u601d\u8003\u201d\uff5cAICon \u6f14\u8bb2\u6574\u7406<\/a><\/p>\n<h2>\u6587 \/ \u9152\u7c73<\/h2>\n<p>\u5173\u6ce8\u5f97\u7269\u6280\u672f\uff0c\u6bcf\u5468\u56db\u66f4\u65b0\u6280\u672f\u5e72\u8d27<\/p>\n<p>\u8981\u662f\u89c9\u5f97\u6587\u7ae0\u5bf9\u4f60\u6709\u5e2e\u52a9\u7684\u8bdd\uff0c\u6b22\u8fce\u8bc4\u8bba\u8f6c\u53d1\u70b9\u8d5e\uff5e<\/p>\n<p>\u672a\u7ecf\u5f97\u7269\u6280\u672f\u8bb8\u53ef\u4e25\u7981\u8f6c\u8f7d\uff0c\u5426\u5219\u4f9d\u6cd5\u8ffd\u7a76\u6cd5\u5f8b\u8d23\u4efb\u3002<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000048124022\">https:\/\/segmentfault.com\/a\/1190000048124022<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u80cc\u666f \u4ece 24 \u5e74\u51ac\u5929\u5f00\u59cb\uff0c\u5404\u7c7b coding agent \u5c42\u51fa\u4e0d\u7a77\u2014\u2014\u4ece Gemini CLI \u7684\u8d77\u6b65\uff0c [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10021430","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021430","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10021430"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021430\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10021430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10021430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10021430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}