Skip to main content

CodeAct-style AI agent framework for Python

Project description

Dragen Logo

Dragen

CodeAct-style AI agents that write Python, not JSON.

PyPI version Crates.io License CI


Instead of making your LLM fill in JSON schemas one tool call at a time, Dragen gives it a Python sandbox. The agent writes real code — loops, branches, error handling, multi-step reasoning — all in one shot. That's the CodeAct pattern.

Code runs in a Littrs sandbox — a Python-to-bytecode compiler and stack VM embedded directly in your process. No containers, no cloud sandboxing services, no exec(). Zero ambient capabilities: no filesystem, no network, no env vars. The only way sandboxed code reaches the outside world is through tools you explicitly provide.

Installation

pip install dragen

Quick Start

import dragen

agent = dragen.Agent("moonshotai/kimi-k2.5")

@agent.tool
def search(query: str) -> str:
    """Search the web for information."""
    return f"Results for: {query}"

result = agent.run("Search for recent AI agent frameworks")
print(result)

Examples

Structured output with self-correction

Pass a schema and the agent retries until the output validates:

from pydantic import BaseModel

class Analysis(BaseModel):
    summary: str
    sentiment: str  # positive, negative, neutral
    confidence: float

agent = dragen.Agent("moonshotai/kimi-k2.5")
result = agent.run(
    "Analyze the sentiment of: 'This product is amazing!'",
    schema=Analysis.model_json_schema()
)
analysis = Analysis(**result)

Multi-agent pipeline with shared context

Agents pass typed data to each other through a shared Context:

from dragen import Agent, Context

ctx = Context()

# Planner researches and writes a plan
planner = Agent("moonshotai/kimi-k2.5").to_context(ctx, "plan")
planner.run("Create a research plan for: quantum computing trends")

# Writer reads the plan and produces content
writer = Agent("moonshotai/kimi-k2.5").from_context(ctx, "plan")
result = writer.run("Write a report based on the research plan")

Sandbox with tools, limits, and file access

sandbox = dragen.Sandbox(builtins=True)
sandbox.limit(max_instructions=50_000, max_recursion_depth=30)
sandbox.mount("data.csv", "./input/data.csv")

@sandbox.tool
def summarize(text: str) -> str:
    """Summarize text using an external API."""
    return call_summary_api(text)

agent = dragen.Agent("moonshotai/kimi-k2.5", sandbox=sandbox)
result = agent.run("Read data.csv and summarize its contents")

Recursive Language Model (RLM)

Process inputs far beyond the context window — the long input lives in the sandbox as a variable and the agent writes code to slice and summarize it across iterations:

sandbox = dragen.Sandbox(builtins=True)
sandbox["document"] = very_long_text  # e.g. 500K tokens

agent = dragen.Agent("moonshotai/kimi-k2.5", max_iterations=20, sandbox=sandbox)
result = agent.run("""
The variable `document` contains a very long research paper.
Extract all key findings, then synthesize them into a structured summary.
You can slice `document` with Python string indexing to read it in parts.
""")

Configuration

agent = dragen.Agent(
    "moonshotai/kimi-k2.5",
    max_iterations=10,
    temperature=0.7,
    max_tokens=4096,
    system="You are a helpful assistant"
)

Event Callbacks

agent = dragen.Agent("moonshotai/kimi-k2.5")

@agent.on_code
def on_code(code):
    print(f"Executing:\n{code}")

@agent.on_output
def on_output(output):
    print(f"Output: {output}")

@agent.on_finish
def on_finish(result):
    print(f"Done: {result}")

For the full feature reference, see DOCS.md. More examples in examples/.

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

dragen-0.2.1-cp312-cp312-win_amd64.whl (4.2 MB view details)

Uploaded CPython 3.12Windows x86-64

dragen-0.2.1-cp312-cp312-manylinux_2_38_x86_64.whl (7.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.38+ x86-64

dragen-0.2.1-cp312-cp312-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file dragen-0.2.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: dragen-0.2.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dragen-0.2.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0f20864fd7c0561eb08e498e3c382f578a49ce27b9dff18de70bb2107b909abd
MD5 fa89d741d7b375f8ad61890f7c216856
BLAKE2b-256 3a4cc08831c34a1e556c09587bf3bd293ee6818a8b432c0dfac14327b2e6efb4

See more details on using hashes here.

File details

Details for the file dragen-0.2.1-cp312-cp312-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for dragen-0.2.1-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 8609518e7f6a4c77e91af9550ebf3a2b74d91ef0234d05a5886d6850627bf8a7
MD5 24d16e324fd7c300e9febdab1e362610
BLAKE2b-256 47def27388bab81be5c1bd3df56496404f8b0aa3e657539e1dbbde49be80931a

See more details on using hashes here.

File details

Details for the file dragen-0.2.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for dragen-0.2.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d5caf3ea09a247629986ba65808d3298d54b4089ca1ad9a417e979a0b52da7f9
MD5 9a678f59ae61b372743b30f5d0ddac7f
BLAKE2b-256 b97efcd7767651d76b0371584d3553e18a29a3c731c5bd409f2cb5f26bf89d83

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page