Skip to main content

CodeAct-style AI agent framework for Python

Project description

dragen

CodeAct-style AI agent framework for Python.

Installation

pip install dragen

Quick Start

from dragen import Agent

# Create an agent
agent = Agent("gpt-4o")

# Register a tool
def search(args):
    query = args[0]
    return {"results": [f"Found: {query}"]}

agent.register_function("search", search)

# Run a task
result = agent.run("Search for Python tutorials")
print(result)

Features

  • CodeAct pattern: LLM writes Python code to accomplish tasks
  • Secure sandbox: Code runs in a sandboxed environment
  • Tool registration: Expose Python functions as tools for the agent
  • Multi-agent support: Share data between agents via Context

Configuration

from dragen import Agent

agent = Agent(
    "gpt-4o",
    max_iterations=10,
    temperature=0.7,
    max_tokens=4096,
    system="You are a helpful assistant"
)

Tool Registration

Simple function

def add(args):
    return args[0] + args[1]

agent.register_function("add", add)

With type information

from dragen import ToolInfo

info = ToolInfo("search", "Search the web") \
    .arg_required("query", "str", "The search query") \
    .returns("dict")

def search(args):
    query = args[0]
    return {"results": ["result1", "result2"]}

agent.register_tool(info, search)

Multi-Agent with Context

from dragen import Agent, Context

ctx = Context()

# Planner writes output to context
planner = Agent("gpt-4o")
planner.to_context(ctx, "plan")
planner.run("Create a research plan about AI")

# Executor reads from context
executor = Agent("gpt-4o")
executor.from_context(ctx, "plan")
executor.run("Execute the research plan")

Environment Variables

Set your API key based on the model provider:

  • OPENAI_API_KEY for OpenAI models (gpt-4o, etc.)
  • ANTHROPIC_API_KEY for Anthropic models (claude-*, etc.)
  • GROQ_API_KEY for Groq models

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.1.0-cp312-cp312-win_amd64.whl (4.3 MB view details)

Uploaded CPython 3.12Windows x86-64

dragen-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl (7.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

dragen-0.1.0-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.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: dragen-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 4.3 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.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3a934b2b3ab252fa45c2abeae26c7a9477d40573c78fc7b4aee4a7c43a4591bf
MD5 1501e9123c0550aeee0d2a9f69fbed49
BLAKE2b-256 3a4e5e75bb46381d66dac6a05b4f518cc7f137824bda26c0b7cba67c6762a0f2

See more details on using hashes here.

File details

Details for the file dragen-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for dragen-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a99fc15692c565f42e7e5e6fabf3776a5a20641d2fdf035be69a92cafdbddc38
MD5 265d0cd5d8e33160ba7ae9b58b04d691
BLAKE2b-256 7fcab2b022a80dfa955a0f506510cacf27a92cdf3a6648ca57770ff9a97b3dfb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dragen-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e3154dc51ec0ba5b20d4d7ddc72d3f9d4affd6dac4e5555670a71370ae911f00
MD5 32cec87625aba4f9b3dd3d4775b83af7
BLAKE2b-256 82f9fe83ad171a522502be84e42dd42286cf8e0d05eca164247f7e7f98cf40ad

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