1#![forbid(unsafe_code)]
2
3pub mod error;
6pub mod streaming;
7pub mod testing;
8pub mod types;
9
10use async_trait::async_trait;
11use futures::stream::BoxStream;
12
13pub use error::{AgentError, BoxError, McpError, MemoryError, ProviderError, Result, ToolError};
14pub use types::{
15 AgentEvent, AgentOutput, CompletionRequest, CompletionResponse, ContentPart, Message,
16 MessageContent, Role, StopReason, StreamChunk, ToolCall, ToolCallDelta, ToolContent,
17 ToolDefinition, ToolOutput, Usage,
18};
19
20#[async_trait]
22pub trait LlmProvider: Send + Sync + 'static {
23 async fn complete(&self, req: CompletionRequest) -> Result<CompletionResponse>;
25
26 async fn stream(&self, req: CompletionRequest) -> Result<BoxStream<'_, Result<StreamChunk>>>;
28
29 fn name(&self) -> &str;
31}
32
33#[async_trait]
35pub trait Tool: Send + Sync + 'static {
36 fn name(&self) -> &str;
38
39 fn description(&self) -> &str;
41
42 fn schema(&self) -> serde_json::Value;
44
45 async fn call(&self, input: serde_json::Value) -> Result<ToolOutput>;
47}
48
49#[async_trait]
51pub trait Memory: Send + Sync + 'static {
52 async fn store(&mut self, key: &str, value: Message) -> Result<()>;
54
55 async fn retrieve(&self, query: &str, limit: usize) -> Result<Vec<Message>>;
57
58 async fn history(&self) -> Result<Vec<Message>>;
60
61 async fn clear(&mut self) -> Result<()>;
63}
64
65#[async_trait]
67pub trait Agent: Send + Sync + 'static {
68 async fn run(&mut self, input: &str) -> Result<AgentOutput>;
70
71 async fn stream_run(&mut self, input: &str) -> Result<BoxStream<'_, Result<AgentEvent>>>;
73}