Back to home

Compare

Comparing: 14,000 Lines of Python Expose AI Code Agent's Black Box & 1.4 万行 Python 拆解 AI 编程 Agent — 黑箱正在被打开

AEN
MyCodeAgentClaude CodeCode Agent·

14,000 Lines of Python Expose AI Code Agent's Black Box

This week we noticed a long technical article circulating in the Chinese developer community: a developer wrote a local code agent called MyCodeAgent in 14,000 lines of Python, without using a development framework like LangChain, and laid bare in the source code the three-layer core logic that is normally hidden away. Our judgment: the black box of AI coding tools is being opened.

What This Is

The core of the article is breaking down an "AI Code Agent" into a three-stage pipeline.

The first stage is the CLI entry (command-line interface), responsible for parsing arguments and deciding the run mode—whether to run once and exit, or stay open like a chat session waiting for you to type. The second stage is dependency assembly, stringing components together in a fixed order: Config → LLM (large model) → Tools → Agent. Get the order wrong and everything downstream breaks.

The third stage is the ReAct main loop (a "think-then-act" loop): the model first reads the user's input, then judges whether to call external tools (read files, execute commands), feeds the results back into the context, and lets the model continue to judge—until the model believes it can output an answer or is forcibly interrupted.

One easy-to-miss but critical detail: in interactive mode it uses prompt_toolkit (a CLI input-handling library) to read keyboard input, with the up/down arrows navigating input history—the same stack Claude Code uses. Products that look magical and "AI" on the surface rely heavily on battle-tested Python CLI libraries underneath.

Industry View

Supportive voices argue that this "framework-free" code gives enterprise IT departments, for the first time, the ability to audit what AI tools are actually doing—before, with LangChain, when something broke you could only guess; now every layer can be paused with breakpoints and debugged.

But opposing opinions are equally sharp: a senior architect commented in our reader group, "Reading the code doesn't mean knowing how to run it well." The "completion-gate check" (verifying whether the model is truly ready to output an answer) inside the ReAct loop is extremely subtle—the model saying "I'm done" and actually being done are frequently two different things, and exposing the code does not automatically improve reliability. Another risk: exposing internal logic pushes products into homogeneous competition—everyone ends up using the prompt_toolkit + rich (terminal-output beautification library) combo, so the contest devolves into raw model cost and latency.

Impact on Regular People

For enterprise IT: CTOs and procurement teams evaluating AI coding tools now have a reference point—they can ask vendors "how does your completion-gate check work," instead of just listening to sales pitches.

For individual professionals: non-technical managers don't need to learn the code in the short term, but they do need to recognize a basic fact: today's AI coding assistants are essentially "scripts that loop-call large models," not some form of mysterious intelligence. Don't mythologize them in budgeting and workflow planning.

For consumer market: the emergence of open-source "anatomy" versions means pricing pressure on comparable commercial products will grow—subscription tools like Cursor and Claude Code will find it increasingly hard to justify further price hikes next year.

Source: juejin.cn
BZH
MyCodeAgentClaude CodeCode Agent·

1.4 万行 Python 拆解 AI 编程 Agent — 黑箱正在被打开

本周我们注意到一篇技术长文在中文开发者社区流传:一位开发者用 1.4 万行 Python 写了一个叫 MyCodeAgent 的本地编程 Agent,没用 LangChain 这类开发框架封装,把通常被藏起来的三层核心逻辑全部摊在源码里。我们的判断是:AI 编程工具的黑箱正在被打开。

这是什么

文章的核心是把"AI 编程 Agent"拆成三段管道。

第一段叫 CLI 入口(命令行界面),负责解析参数和决定运行模式——是跑一次就退出,还是像聊天一样持续等你敲字。第二段叫依赖组装,按 Config → LLM(大模型)→ 工具 → Agent 的固定顺序把零件串起来,顺序错了后面就全错。

第三段叫 ReAct 主循环(一种"思考-行动"循环):模型先读用户输入,再判断要不要调用外部工具(读文件、执行命令),调完就把结果塞回上下文让模型继续判断,直到模型认为可以输出答案或被强制打断。

一个不起眼但关键的细节:交互模式下用 prompt_toolkit(处理命令行输入的库)读键盘,按上下键能翻历史输入——和 Claude Code 用的是同一套技术栈。市面上看起来很"AI"的产品,底层大量依赖成熟的 Python 命令行工具库。

行业怎么看

支持的声音认为,这种"无框架"代码让企业 IT 部门第一次有能力审计 AI 工具到底在做什么——以前用 LangChain,出了问题只能猜;现在每一层都能打断点调试。

但反对意见同样尖锐:一位资深架构师在我们的读者群里留言,"看得懂不等于能用好"。ReAct 循环里的"完成门检查"(判断模型是否真的可以输出答案)非常微妙,模型说"我搞定了"和实际搞定经常是两回事,把代码摊开并不会自动提高可靠性。另一个风险是,暴露内部逻辑反而让各家产品陷入同质化竞争——大家都用 prompt_toolkit + rich(美化终端输出的库)这套组合,最后比拼的还是模型本身的成本和延迟。

对普通人的影响

企业 IT:CTO 和采购部门评估 AI 编程工具时,多了一个可参照的对象——可以问供应商"你的完成门检查怎么做",而不是只听销售讲故事。

个人职场:非技术管理者短期不用学,但需要意识到一个事实:现在的 AI 编程助手本质是"循环调用大模型的脚本",不是某种神秘智慧,预算和流程安排不必神化它。

消费市场:开源解剖版本出现,意味着同类商业产品的定价压力会增大——Cursor、Claude Code 这类订阅工具,明年继续涨价的理由会越来越弱。

Source: juejin.cn