Skip to main content

Crate dragen

Crate dragen 

Source
Expand description

Dragen - CodeAct-style agent framework

Dragen provides a simple framework for building AI agents that execute Python code in a secure sandbox. It uses the CodeAct pattern where the LLM writes Python code to accomplish tasks, with tools exposed as Python functions.

§Quick Start

use dragen::{Agent, AgentConfig};
use littrs::tool;

/// Get the current weather for a city.
///
/// Args:
///     city: The city name
#[tool]
fn get_weather(city: String) -> String {
    format!("Weather in {}: Sunny, 22°C", city)
}

#[tokio::main]
async fn main() {
    let mut agent = Agent::new(AgentConfig::new("gpt-4o"));
    agent.register(get_weather::Tool);

    let result = agent.run("What's the weather in Paris?").await.unwrap();
    println!("{}", result);
}

§Sharing Data Between Agents

Use Context to pass data between agents without manual Arc/Mutex management:

use dragen::{Agent, AgentConfig, Context};

let ctx = Context::new();

// Planner writes output to context
let mut planner = Agent::new(AgentConfig::new("gpt-4o"))
    .to_context(&ctx, "plan");
planner.run::<PlanOutput>(&query).await?;

// Executor reads from context (injected into prompt)
let mut executor = Agent::new(AgentConfig::new("gpt-4o"))
    .from_context(&ctx, "plan");
executor.run::<String>("Execute the plan").await?;

Re-exports§

pub use littrs;

Structs§

Agent
A CodeAct-style agent that executes Python code in a sandbox.
AgentCallbacks
Storage for agent callbacks
AgentConfig
Configuration for the CodeAct agent.
Context
Shared context for passing data between agents.

Enums§

AgentEvent
Events emitted during agent execution for observability.
Error
Errors that can occur during agent execution.

Functions§

pyvalue_to_json
Convert a PyValue to a serde_json::Value for typed deserialization.

Type Aliases§

Result
Result type for Dragen operations.