CodeAct-style AI agent framework for Python
Project description
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dragen-0.3.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: dragen-0.3.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a63af2edd4a18bd1a7e89b15843f97b3431d89384b6d9fefee652b3ea3d98216
|
|
| MD5 |
be64d0b5441f4d8c947c03bdfd66c536
|
|
| BLAKE2b-256 |
f914cb18af21d41ee42fed0e3eb9218cf1f9083d059d83cfbfb24026ef7735b3
|
File details
Details for the file dragen-0.3.0-cp312-cp312-manylinux_2_38_x86_64.whl.
File metadata
- Download URL: dragen-0.3.0-cp312-cp312-manylinux_2_38_x86_64.whl
- Upload date:
- Size: 7.1 MB
- Tags: CPython 3.12, manylinux: glibc 2.38+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffcc60eae4e09800bff3b5259361ce190d91af89c6283f63c5fcc3de420f4c3d
|
|
| MD5 |
6a748ac4f5ac5ad2580b693f26488429
|
|
| BLAKE2b-256 |
a6f40ba4b2a114d846fdbfd039aafc62b11272b0df06f1e9982af6989ca28031
|
File details
Details for the file dragen-0.3.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: dragen-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 4.5 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c89cab6c58a23bddc1274f59251bb6927d21102c63c924e284206b4e5d6e001
|
|
| MD5 |
29e336154098c05d1a05b7d727e91a20
|
|
| BLAKE2b-256 |
e2c246fbab95490c1d0247ee8050a78b471753fb115a8dd804af99bb3295f1c7
|