arXiv:2409.16120cs.SEcs.AI2024-09被引 5

让AI Agent通过代码持续进化,自动管理运行上下文。

MOSS: Enabling Code-Driven Evolution and Context Management for AI Agents

  • 用动态上下文管理确保代码与环境一致
  • 支持变量隔离和运行时完整性,提升多轮交互效率
  • 适合需要自主演化的智能体开发者

基于大语言模型(LLMs)的AI智能体开发面临真正图灵完备性和自适应代码驱动演化的挑战。现有方法常独立生成代码而忽略运行时上下文,过度依赖LLM记忆,导致效率低下且难以适应。在沙盒中手动设计协议进一步限制了自主性。关键问题在于多轮交互中代码与上下文的一致性,以及每次交互中局部变量的隔离性。我们提出MOSS(llM-oriented Operating System Simulation),一个将代码生成与动态上下文管理系统融合的新框架。MOSS通过维护跨交互的Python上下文,实现局部变量隔离和运行时完整性,确保一致性与可适应性。核心机制采用控制反转(IoC)容器结合装饰器,遵循最小知识原则,使智能体只需关注抽象接口而非具体实现。这支持新工具无缝集成、运行时实例替换,并降低提示复杂度,为智能体提供‘所见即所得’环境。通过一系列案例研究,验证了该框架在提升智能体开发效率与能力方面的优势,推动迈向可通过代码自我演化的图灵完备智能体。

原文摘要 · Abstract (English)

Developing AI agents powered by large language models (LLMs) faces significant challenges in achieving true Turing completeness and adaptive, code-driven evolution. Current approaches often generate code independently of its runtime context, relying heavily on the LLM's memory, which results in inefficiencies and limits adaptability. Manual protocol development in sandbox environments further constrains the agent's autonomous adaptability. Crucially, achieving consistency in code and context across multi-turn interactions and ensuring isolation of local variables within each interaction remains an unsolved problem. We introduce MOSS (llM-oriented Operating System Simulation), a novel framework that addresses these challenges by integrating code generation with a dynamic context management system. MOSS ensures consistency and adaptability by using a mechanism that maintains the Python context across interactions, including isolation of local variables and preservation of runtime integrity. At its core, the framework employs an Inversion of Control (IoC) container in conjunction with decorators to enforce the least knowledge principle, allowing agents to focus on abstract interfaces rather than concrete implementations. This facilitates seamless integration of new tools and libraries, enables runtime instance replacement, and reduces prompt complexity, providing a "what you see is what you get" environment for the agent. Through a series of case studies, we show how this framework can enhance the efficiency and capabilities of agent development and highlight its advantages in moving towards Turing-complete agents capable of evolving through code.

AI智能体代码演化上下文管理

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。