arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2512.22431cs.AIcs.CLcs.FL
收藏

单子上下文工程

Monadic Context Engineering

IIIS, Tsinghua University(清华大学人工智能研究院)

Yifan Zhang, Yang Yuan, Mengdi Wang, Andrew Chi-Chih Yao

AI总结:

本文提出Monadic Context Engineering,利用函子、应用函子和单子的代数结构,为智能体设计提供形式基础,通过分层方法构建高效可靠的AI智能体。

摘要:

大语言模型的普及推动了能够复杂推理和工具使用的自主智能体的发展。然而,当前智能体架构多采用命令式、随意的模式,导致系统脆弱,存在状态管理、错误处理和并发性的难题。本文引入Monadic Context Engineering(MCE),一种新的架构范式,利用函子、应用函子和单子的代数结构,为智能体设计提供形式基础。MCE将智能体工作流视为计算上下文,通过代数属性内在管理交叉切分关注点,如状态传播、短路错误处理和异步执行。我们展示了单子如何实现稳健的顺序组合,应用函子如何为并行执行提供原则性结构,以及关键的单子转换器如何系统地组合这些能力。这种分层方法使开发者能够从简单的、独立验证的组件构建复杂、稳健和高效的AI智能体。我们进一步扩展此框架以描述元智能体,它们利用MCE进行生成性编排,通过元编程动态创建和管理子智能体工作流。

英文摘要:

The proliferation of Large Language Models (LLMs) has catalyzed a shift towards autonomous agents capable of complex reasoning and tool use. However, current agent architectures are frequently constructed using imperative, ad hoc patterns. This results in brittle systems plagued by difficulties in state management, error handling, and concurrency. This paper introduces Monadic Context Engineering (MCE), a novel architectural paradigm leveraging the algebraic structures of Functors, Applicative Functors, and Monads to provide a formal foundation for agent design. MCE treats agent workflows as computational contexts where cross-cutting concerns, such as state propagation, short-circuiting error handling, and asynchronous execution, are managed intrinsically by the algebraic properties of the abstraction. We demonstrate how Monads enable robust sequential composition, how Applicatives provide a principled structure for parallel execution, and crucially, how Monad Transformers allow for the systematic composition of these capabilities. This layered approach enables developers to construct complex, resilient, and efficient AI agents from simple, independently verifiable components. We further extend this framework to describe Meta-Agents, which leverage MCE for generative orchestration, dynamically creating and managing sub-agent workflows through metaprogramming.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑