llm_agent/toolkit.rs
1use crate::{errors::BoxedError, AgentTool};
2use futures::future::BoxFuture;
3use std::sync::Arc;
4
5/// Toolkit produces a per-session toolkit session that can provide dynamic
6/// prompt and tool data.
7pub trait Toolkit<TCtx>: Send + Sync {
8 /// Create a new toolkit session for the supplied context value.
9 /// Implementations should also initialize the session with instructions and
10 /// tools.
11 fn create_session<'a>(
12 &'a self,
13 context: &'a TCtx,
14 ) -> BoxFuture<'a, Result<Box<dyn ToolkitSession<TCtx> + Send + Sync>, BoxedError>>;
15}
16
17/// `ToolkitSession` exposes dynamically resolved tools and system prompt data
18/// for a run session.
19pub trait ToolkitSession<TCtx>: Send + Sync {
20 /// Retrieve the current system prompt for the session, if available.
21 fn system_prompt(&self) -> Option<String>;
22 /// Retrieve the current set of tools that should be available to the
23 /// session.
24 fn tools(&self) -> Vec<Arc<dyn AgentTool<TCtx>>>;
25 /// Release any resources that were allocated for the session.
26 fn close(self: Box<Self>) -> BoxFuture<'static, Result<(), BoxedError>>;
27}