你能写出最简洁的代理编码器是什么?
What Is the Most Minimal Agentic Coder You Can Write?

原始链接: https://benhouston3d.com/blog/minimal-agentic-coder

自主编码,即AI代理自主进行编码、执行和调试,正在改变软件开发。mycoder-mini是一个简洁的200行TypeScript实现,可在GitHub上找到,它演示了核心原理。它利用Anthropic的Claude 3基于简单的循环生成shell命令:接收目标,查询Claude,执行命令,然后重复直到完成。虽然它受到同步执行、缺乏浏览器集成以及仅依赖shell命令的限制,但mycoder-mini提供了一个功能性清晰的自主编码基础演示。它仅通过CLI命令执行任务。这个简化的自主编码器为学习和实验更复杂的自主系统提供了一个引人入胜且易于上手的起点。

Hacker News 最新 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 你能写出最简化的自主编码程序吗? (benhouston3d.com) bhouston 2小时前 11 分 | 隐藏 | 过去 | 收藏 | 2 条评论 bhouston 21分钟前 [–] (Hacker News 真的是乱套了,我提交这个不是2小时前,而是上周——参见这里:https://news.ycombinator.com/submitted?id=bhouston 但现在它却在首页,显示3个赞,说是2小时前的。不管怎样,我就这么接受吧。) 回复 bryanlarsen 1分钟前 | 父级 [–] 这很可能意味着有人在2小时前提交了你的网址。HN 将重复提交转换为赞。 回复 加入我们,参加6月16日至17日在旧金山举办的AI创业学校! 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请YC | 联系我们 搜索:

原文

Agentic coding has recently gained traction as an innovative approach where autonomous software agents leverage advanced Large Language Models (LLMs) to perform tasks traditionally done by developers. These agents can autonomously write code, execute commands, and debug software, dramatically enhancing developer productivity. But what's the simplest way you can create a functional agentic coder?

I explored this challenge and built mycoder-mini, an extremely minimal agentic coder in just around 200 lines of TypeScript code. The entire codebase is available in this GitHub repository, specifically within the single TypeScript file here.

How Does mycoder-mini Work?

At its core, mycoder-mini leverages an LLM (specifically, Anthropic's Claude 3) to generate shell commands based on a user's prompt. Here's the essence of its functionality in code:

const runAgentLoop = async (initialPrompt: string) => { const tools = [shellCommandSchema, finishedSchema]; const systemPrompt = `You are an AI agent that can run shell ` + `commands to accomplish tasks. Use provided tools to ` + `complete the user's task. Call the finished tool ` + `when done.`; let messages = [{ role: 'user', content: initialPrompt }]; while (true) { const response = await anthropic.messages.create({ model: 'claude-3-7-sonnet-20250219', messages, systemPrompt, tools }); messages.push({ role: 'assistant', content: response.content }); for (const block of response.content) { if (block.type === 'tool_use') { if (block.name === 'shellCommand') { const result = await shellCommand(block.input.command); messages.push({ role: 'user', content: [ { type: 'tool_result', tool_use_id: block.id, content: JSON.stringify(result) } ] }); } else if (block.name === 'finished') { return; } } } } };

In this simplified loop, the agent:

  • Receives an initial goal from the user.
  • Queries Claude 3.7 for commands.
  • Executes shell commands returned by the model.
  • Continues this loop until the task is marked as completed.

Limitations of the Minimal Approach

Despite its simplicity and functionality, mycoder-mini comes with notable limitations:

  • Synchronous Execution: Commands are executed synchronously, which means it can't handle asynchronous processes, long-running CLI tools, or interactive shell sessions.
  • No Browser Integration: It lacks browser automation capabilities, preventing interactions with web pages or dynamic data retrieval through browsing.
  • Limited Toolset: It relies exclusively on shell commands, limiting it to tasks achievable purely through CLI.

Even with these constraints, mycoder-mini demonstrates the foundational principles of agentic coding clearly and concisely.

Try It Yourself

The complete implementation is accessible on GitHub. Whether for learning, experimentation, or expanding into more sophisticated agentic systems, mycoder-mini is a compelling starting point.

联系我们 contact @ memedata.com