swiftide_agents/lib.rs
1//! Swiftide agents are a flexible way to build fast and reliable AI agents.
2//!
3//! # Features
4//!
5//! * **Tools**: Tools can be defined as functions using the `#[tool]` attribute macro, the `Tool` derive macro, or manually implementing the `Tool` trait.
6//! * **Hooks**: At various stages of the agent lifecycle, hooks can be defined to run custom logic. These are defined when building the agent, and each take a closure.
7//! * **Context**: Agents operate in an `AgentContext`, which is a shared state between tools and hooks. The context is responsible for managing the completions and interacting with the outside world.
8//! * **Tool Execution**: A context takes a tool executor (local by default) to execute its tools on. This enables tools to be run i.e. in containers, remote, etc.
9//! * **System prompt defaults**: `SystemPrompt` provides a default, customizable prompt for the agent. If you want to provider your own prompt, the builder takes anything that converts into a `Prompt`, including strings.
10//! * **Open Telemetry**: Agents are fully instrumented with open telemetry.
11//!
12//! # Example
13//!
14//! ```ignore
15//! # use swiftide_agents::Agent;
16//! # use swiftide_integrations as integrations;
17//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
18//! let openai = integrations::openai::OpenAI::builder()
19//! .default_prompt_model("gpt-4o-mini")
20//! .build()?;
21//!
22//! Agent::builder()
23//! .llm(&openai)
24//! .before_completion(move |_,_|
25//! Box::pin(async move {
26//! println!("Before each tool");
27//! Ok(())
28//! })
29//! )
30//! .build()?
31//! .query("What is the meaning of life?")
32//! .await?;
33//! # return Ok(());
34//!
35//! # }
36//! ```
37//!
38//! Agents run in a loop as long as they have new messages to process.
39mod agent;
40mod default_context;
41pub mod hooks;
42mod state;
43pub mod system_prompt;
44pub mod tools;
45
46pub use agent::Agent;
47pub use default_context::DefaultContext;
48
49#[cfg(test)]
50mod test_utils;