Table of Contents
Fetching ...

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

Ming Zhu, Yi Zhou

TL;DR

MOSS (llM-oriented Operating System Simulation), a novel framework that addresses challenges in developing AI agents by integrating code generation with a dynamic context management system, is introduced and its advantages in moving towards Turing-complete agents capable of evolving through code are highlighted.

Abstract

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.

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

TL;DR

MOSS (llM-oriented Operating System Simulation), a novel framework that addresses challenges in developing AI agents by integrating code generation with a dynamic context management system, is introduced and its advantages in moving towards Turing-complete agents capable of evolving through code are highlighted.

Abstract

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.
Paper Structure (59 sections, 2 figures)

This paper contains 59 sections, 2 figures.

Figures (2)

  • Figure 1: This diagram depicts the lifecycle of a MOSS agent as it handles complex, multi-turn tasks by dynamically generating and executing code. Each Thread represents a sequence of steps (turns) executed within Frames. Conceptually similar to function call stack frames in programming languages, each Frame represents an execution context that maintains its own dependencies and state. When the agent encounters an AIFunc or Thought in a higher-level frame (e.g., frame m), these components only have a definition but lack a body. MOSS then "drills down" into a new Frame (e.g., frame m+1), where the MOSS Compiler converts the surrounding code and definitions into a temporary Python module. The MOSS Runtime takes over, transforming this module into a prompt, which provides the LLM with the necessary context, dependencies, and AIFunc/Thought definitions. The LLM then writes the missing body (often a 'main' function) to complete the function. After executing this new code, the result is passed back to the original frame, allowing the agent to continue processing from where it left off. Each frame maintains its own IoC container for dependency injection and manages its execution context independently through PyContext, ensuring consistency across multi-turn interactions. This iterative process of code generation, execution, and feedback enables MOSS to handle adaptive, multi-step tasks, achieving Turing-complete behavior.
  • Figure 2: This diagram illustrates the code-driven evolving mechanism within MOSS. The system enables dynamic interactions between meta-agents, the source code, and the environment. Tools within the environment continuously modify agent source code, which is then used by the Meta-Agent to create encapsulated intelligent code units (e.g., AIFunc or Thought). The Meta-Agent uses these units to develop new tools and agents, thereby perpetuating a cycle of code-driven evolution.