Skip to main content

dragen/
lib.rs

1//! Dragen - CodeAct-style agent framework
2//!
3//! Dragen provides a simple framework for building AI agents that execute
4//! Python code in a secure sandbox. It uses the CodeAct pattern where the
5//! LLM writes Python code to accomplish tasks, with tools exposed as
6//! Python functions.
7//!
8//! # Quick Start
9//!
10//! ```ignore
11//! use dragen::{Agent, AgentConfig};
12//! use littrs::tool;
13//!
14//! /// Get the current weather for a city.
15//! ///
16//! /// Args:
17//! ///     city: The city name
18//! #[tool]
19//! fn get_weather(city: String) -> String {
20//!     format!("Weather in {}: Sunny, 22°C", city)
21//! }
22//!
23//! #[tokio::main]
24//! async fn main() {
25//!     let mut agent = Agent::new(AgentConfig::new("gpt-4o"));
26//!     agent.register(get_weather::Tool);
27//!
28//!     let result = agent.run("What's the weather in Paris?").await.unwrap();
29//!     println!("{}", result);
30//! }
31//! ```
32//!
33//! # Sharing Data Between Agents
34//!
35//! Use `Context` to pass data between agents without manual Arc/Mutex management:
36//!
37//! ```ignore
38//! use dragen::{Agent, AgentConfig, Context};
39//!
40//! let ctx = Context::new();
41//!
42//! // Planner writes output to context
43//! let mut planner = Agent::new(AgentConfig::new("gpt-4o"))
44//!     .to_context(&ctx, "plan");
45//! planner.run::<PlanOutput>(&query).await?;
46//!
47//! // Executor reads from context (injected into prompt)
48//! let mut executor = Agent::new(AgentConfig::new("gpt-4o"))
49//!     .from_context(&ctx, "plan");
50//! executor.run::<String>("Execute the plan").await?;
51//! ```
52
53mod agent;
54mod context;
55mod error;
56
57pub use agent::{pyvalue_to_json, Agent, AgentCallbacks, AgentConfig, AgentEvent};
58pub use context::Context;
59pub use error::{Error, Result};
60
61// Re-export littrs for convenience
62pub use littrs;