我花了 4 天时间创建一个 code agent, 核心代码不到 200 行。
试用:npm install -g wscode-cli ,github 仓库在: https://github.com/mileswangs/wscode-cli
下面讲一下关键逻辑
关键 1: loop + tool use
关键 2: llm 通过工具调用(成功或失败都行)获取信息,以字符串形式传递
这看起来很无聊,但深刻且普遍:传统编程报错会 throw {err: stackoverflow}, llm 时代编程会 return ‘have a error: stackoverflow’
举个例子:我们需要约束以绝对路径访问文件,当 llm 调用相对路径的时候会收到 tool 返回的Path must be within the root directory这个字符串,llm 看到这个失败信息后会更改工具使用姿势

