ChatPaper.aiChatPaper

모나딕 컨텍스트 엔지니어링

Monadic Context Engineering

December 27, 2025
저자: Yifan Zhang, Mengdi Wang
cs.AI

초록

대규모 언어 모델(LLM)의 확산은 복잡한 추론과 도구 사용이 가능한 자율 에이전트로의 전환을 촉진하고 있습니다. 그러나 현재의 에이전트 아키텍처는 종종 명령형의 임시적 패턴으로 구성되어 있습니다. 이로 인해 상태 관리, 오류 처리, 동시성 처리의 어려움으로 인한 취약한 시스템이 발생합니다. 본 논문은 펑터(Functor), 어플리케이티브 펑터(Applicative Functor), 모나드(Monad)의 대수적 구조를 활용하여 에이전트 설계에 형식적인 기반을 제공하는 새로운 아키텍처 패러다임인 모나딕 컨텍스트 엔지니어링(MCE)을 소개합니다. MCE는 에이전트 워크플로우를 상태 전파, 단락 오류 처리, 비동기 실행과 같은 공통 관심사가 추상화의 대수적 속성에 의해 내재적으로 관리되는 계산적 컨텍스트로 취급합니다. 우리는 모나드가 어떻게 강력한 순차적 구성을 가능하게 하는지, 어플리케이티브가 어떻게 병렬 실행을 위한 원칙적인 구조를 제공하는지, 그리고 결정적으로 모나드 트랜스포머(Monad Transformer)가 이러한 기능들의 체계적인 조합을 어떻게 가능하게 하는지 보여줍니다. 이러한 계층적 접근 방식을 통해 개발자는 단순하고 독립적으로 검증 가능한 구성 요소로부터 복잡하고 견고하며 효율적인 AI 에이전트를 구축할 수 있습니다. 우리는 또한 메타프로그래밍을 통해 하위 에이전트 워크플로우를 동적으로 생성하고 관리하는 생성적 오케스트레이션을 위해 MCE를 활용하는 메타 에이전트(Meta-Agent)를 설명하기 위해 이 프레임워크를 확장합니다. 프로젝트 페이지: https://github.com/yifanzhang-pro/monadic-context-engineering.
English
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. Project Page: https://github.com/yifanzhang-pro/monadic-context-engineering.
PDF70December 31, 2025