1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! A Rust crate for configuring and using OpenAI in an agentic system.
//!
//! This library provides a high-level interface to interact with OpenAI's API,
//! with particular focus on agent-based interactions that leverage tool calls
//! (formerly known as function calls).
//!
//! # Basic usage
//!
//! ```rust
//! use agio::{Agent, AgentBuilder, Config};
//!
//! # async fn example() -> Result<(), agio::Error> {
//! // Create a configuration
//! let config = Config::new()
//! .with_api_key("your-api-key")
//! .with_model("gpt-4o");
//!
//! // Create an agent
//! let mut agent = AgentBuilder::new()
//! .with_config(config)
//! .with_system_prompt("You are a helpful assistant.")
//! .build()?;
//!
//! // Run the agent
//! let response = agent.run("Tell me about Rust programming.").await?;
//! println!("Response: {}", response);
//! # Ok(())
//! # }
//! ```
// Internal modules
// Public exports for the prelude
// Direct exports for the main API surface
pub use *;
// Re-export from models for public use
pub use crateToolDefinition;
// Re-export FunctionTool
pub use crateFunctionTool;
// Selective re-exports of internal types that are needed in public APIs
// but should not be directly constructed by users
pub use AgentState;
// Define the tool_fn macro directly in lib.rs to avoid module path issues
/// Creates a tool from a function.
///
/// This macro simplifies creating tools from functions by handling the type inference.
///
/// # Arguments
///
/// * `name` - The name of the tool
/// * `description` - A description of what the tool does
/// * `function` - The function to execute
///
/// # Example
///
/// ```
/// use agio::tool_fn;
/// use serde::{Deserialize, Serialize};
///
/// #[derive(Debug, Serialize, Deserialize, schemars::JsonSchema)]
/// struct ReverseArgs {
/// text: String,
/// }
///
/// async fn reverse_string(args: ReverseArgs) -> Result<String, agio::Error> {
/// Ok(args.text.chars().rev().collect())
/// }
///
/// let tool = tool_fn!("reverse_string", "Reverses a string", reverse_string);
/// ```