garudust_agent/lib.rs
1//! AI agent run-loop, prompt builder, and multi-agent orchestration for Garudust.
2//!
3//! The centrepiece of this crate is [`Agent`], which drives the
4//! **think → tool-call → observe** loop until the model signals it is done.
5//!
6//! # Quick start
7//!
8//! ```no_run
9//! use std::sync::Arc;
10//! use std::path::PathBuf;
11//! use garudust_agent::{Agent, AutoApprover};
12//! use garudust_core::config::AgentConfig;
13//! use garudust_transport::build_transport;
14//! use garudust_memory::FileMemoryStore;
15//! use garudust_tools::ToolRegistry;
16//!
17//! #[tokio::main]
18//! async fn main() -> anyhow::Result<()> {
19//! let config = Arc::new(AgentConfig::default());
20//! let transport = build_transport(&config);
21//! let tools = Arc::new(ToolRegistry::default());
22//! let memory = Arc::new(FileMemoryStore::new(&PathBuf::from("/tmp")));
23//! let agent = Agent::new(transport, tools, memory, config);
24//! let approver = Arc::new(AutoApprover);
25//! let result = agent.run("List files here", approver, "cli").await?;
26//! println!("{}", result.output);
27//! Ok(())
28//! }
29//! ```
30//!
31//! # Architecture
32//!
33//! ```text
34//! ┌──────────────────────────────────────────┐
35//! │ Agent │
36//! │ build_system_prompt() │
37//! │ ┌────────────────────────────────────┐ │
38//! │ │ iteration loop │ │
39//! │ │ 1. call ProviderTransport (LLM) │ │
40//! │ │ 2. dispatch tool calls │ │
41//! │ │ 3. append results to history │ │
42//! │ │ 4. repeat until stop_reason=end │ │
43//! │ └────────────────────────────────────┘ │
44//! │ persist_session() → SessionDb │
45//! └──────────────────────────────────────────┘
46//! ```
47//!
48//! # Skills and self-improvement
49//!
50//! When the agent finishes a task it may call `write_skill` to save a reusable
51//! instruction set to `~/.garudust/skills/<name>/SKILL.md`. On subsequent
52//! runs the skill index is injected into the system prompt so the model can
53//! load and apply the skill via `skill_view`.
54
55pub mod agent;
56pub mod approver;
57pub mod compressor;
58pub mod prompt_builder;
59mod tests;
60
61pub use agent::Agent;
62pub use approver::{AutoApprover, ConstitutionalApprover, DenyApprover};