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.3.1-cp313-cp313-win_amd64.whl (4.2 MB view details)

Uploaded CPython 3.13Windows x86-64

dragen-0.3.1-cp313-cp313-manylinux_2_38_x86_64.whl (7.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.38+ x86-64

dragen-0.3.1-cp313-cp313-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

dragen-0.3.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.3.1-cp312-cp312-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

dragen-0.3.1-cp311-cp311-win_amd64.whl (4.2 MB view details)

Uploaded CPython 3.11Windows x86-64

dragen-0.3.1-cp311-cp311-manylinux_2_38_x86_64.whl (7.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.38+ x86-64

dragen-0.3.1-cp311-cp311-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

dragen-0.3.1-cp310-cp310-win_amd64.whl (4.2 MB view details)

Uploaded CPython 3.10Windows x86-64

dragen-0.3.1-cp310-cp310-manylinux_2_38_x86_64.whl (7.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.38+ x86-64

dragen-0.3.1-cp310-cp310-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file dragen-0.3.1-cp313-cp313-win_amd64.whl.

File metadata

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

File hashes

Hashes for dragen-0.3.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 43a1006801769cbf19d0472e094ba2251567e3023d40a5774a122bba19263232
MD5 fcff79bcfb7943c62cef5a1efbdd6380
BLAKE2b-256 bfb0ee69f33af978af8a672d10ff0b12990ce961e344af9f56a55b603a86927f

See more details on using hashes here.

File details

Details for the file dragen-0.3.1-cp313-cp313-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for dragen-0.3.1-cp313-cp313-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 221fff01ce615f832f02758e43b90d9ff6d9039ac7875717a184b25c79c2a24a
MD5 3d2e09fba5cc0d60b04b3ceb036e9d53
BLAKE2b-256 8a1125ef74a951bdc719c362c34978be3a72a1b1f44bf00225dd144a74dee4f2

See more details on using hashes here.

File details

Details for the file dragen-0.3.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for dragen-0.3.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cc2bd2e7c6cc8aa7ab128536da11c5ca711412755c158d7a9f348a9b3c7e86b1
MD5 20fa460af5ee0a8a7c3270114ac00d4b
BLAKE2b-256 81b91087d679e3da19db9a681f479f61629a593747896ddafca24060ab466b67

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dragen-0.3.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.3.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 893eae35a13169c67c915d69a0a0c145c8f6f4f34d86417b8d82e2e56e05cf31
MD5 5bade3511e79551b09cac7892c034dad
BLAKE2b-256 40b7b6cff46dcb159272919fd84ec300bcff2b653ee6f23a3be17a8244cdcde6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dragen-0.3.1-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 6dea9c6c27d670c615c36cf4b3b7284d3685fd468034a9fe857e7ce9ba3ebd36
MD5 cd2e89020e2d07a4563dc4754eaa2630
BLAKE2b-256 b4701efca31285b12c48077fa4ec06e9ead3839b69d95838da319ae96f3a4720

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dragen-0.3.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bfe11ef3716d7621ffb8e358f864677b9e1b764a1a5b6f290eaee685a09c2f20
MD5 043226d6e9a24590da4fe5bbfcf714b5
BLAKE2b-256 5bdd1bf311ae142582ae09642450650e114ac95f578bbb5509851eca80a62bae

See more details on using hashes here.

File details

Details for the file dragen-0.3.1-cp311-cp311-win_amd64.whl.

File metadata

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

File hashes

Hashes for dragen-0.3.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 cc8d8c17c3e4f8319fa39fbbcf442652900db443aa32ffd8e5570dda23472acd
MD5 b50375be6d3cd126f48fb9b8bbeaf808
BLAKE2b-256 39a931ca53fdc53cc24f9a1750494c5c65724edaa24016c659b92d3a2eb0a331

See more details on using hashes here.

File details

Details for the file dragen-0.3.1-cp311-cp311-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for dragen-0.3.1-cp311-cp311-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 6ffddcd3fba23f4e99c426939545d094d5fbb51fd906bd6e3aa962251eb9df3a
MD5 e8da141fa69601b3fa2464448d7dec3d
BLAKE2b-256 9016c21edf5b303d21c3611f46c85fb50eb99850326b24223f542af0db26d3a6

See more details on using hashes here.

File details

Details for the file dragen-0.3.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for dragen-0.3.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3e0bc47a44e56354cd0c0b56999aab8e099ee093b633a63c3064facb4a45311f
MD5 c3778f60c5230a74bcc04ff1a53f3487
BLAKE2b-256 c0ee733019b7cdd07fef355c13629ecb2acc233c4d5670e039624abd6ab98991

See more details on using hashes here.

File details

Details for the file dragen-0.3.1-cp310-cp310-win_amd64.whl.

File metadata

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

File hashes

Hashes for dragen-0.3.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 db263d421680c4512ac145c18a3fc918955b23cca1021787fd93c4105f011850
MD5 064bf907cadabf3be627b3ebd2f23c62
BLAKE2b-256 9b7c0051209df268c13614aaac4640fb7ba3277bbdb19eb5e1a3075c587fcea6

See more details on using hashes here.

File details

Details for the file dragen-0.3.1-cp310-cp310-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for dragen-0.3.1-cp310-cp310-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 a9987914268ed4194097a5013e8f180c74d11ad402115796e63607f549209d8a
MD5 0ad14a0800b8e975a2d0b9392d46fff8
BLAKE2b-256 158e13b86325b33a6772b0ae74688efcc3cc29bf85664b8d54e2d01eb0fc71d4

See more details on using hashes here.

File details

Details for the file dragen-0.3.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for dragen-0.3.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1c1dcfc142e94e95f37a2cd7da8add0bbe082d883af781fa646bef61da46295c
MD5 972c3092bd37fa129daf7671784e3a17
BLAKE2b-256 8ae1820f1bab17ba8fef04f147bad3b0ecc7bece1481237196f9c7079c599246

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