Overview

AgentScript: Build AI Agents That Think in Code

AgentScript is an open-source framework for building re-act AI agents. Unlike traditional approaches, AgentScript prompts an LLM to generate code (a subset of JavaScript) that represents its plan. This generated code isn't directly executed; instead, it's first parsed into an Abstract Syntax Tree (AST), which is then interpreted and executed within a dedicated, safe runtime environment. This approach enables features such as resumability, state persistence, and support for human-in-the-loop.

Core Idea

Instead of orchestrating agents through a series of LLM calls, AgentScript lets the LLM generate the actual code to execute a plan, giving it more power and flexibility. This makes complex, dynamic agent behavior easier to express and more efficient to execute.

Key Benefits

  • Flexibility: By expressing agent logic as code, you can create sophisticated behaviors that are difficult to implement with traditional orchestration methods.
  • Resumability: Agents can be paused at any point, serialized to a database, and resumed later, making them robust to interruptions or long-running processes.
  • State Persistence: The execution state, including variables and tool states, is persisted and can be accessed or modified.
  • Human-in-the-Loop: You can easily add human-in-the-loop by creating interactive tools that require user input, approval, or confirmation.

How it Works

  1. You define a runtime environment with tools, and specify input and output requirements.
  2. You provide a natural language prompt that describes the task you want the agent to perform.
  3. AgentScript uses an LLM to generate JavaScript-like code that represents the agent's plan.
  4. This code is parsed into an Abstract Syntax Tree (AST).
  5. The AST is then executed within a dedicated, safe runtime environment, and it can be paused on any statement or tool call.
  6. The execution can be serialized to a database and restored at any point.

Target Audience

AgentScript is designed for developers who:

  • Want a more powerful and flexible way to build AI agents.
  • Need features like state management, resumability, and human-in-the-loop.
  • Are comfortable with JavaScript-like syntax and understand AST concepts.