pub trait ToolSource: MaybeSend + MaybeSync {
// Required method
fn tools<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Vec<Arc<dyn AgentTool>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
A provider of tools consulted at the start of every run.
Install with Agent::with_tool_source
or SubAgentTool::with_tool_source.
See the module docs for when it is consulted and how name
collisions resolve.
use std::sync::{Arc, Mutex};
use yoagent::{AgentTool, ToolSource};
/// A tool list that the application swaps at runtime.
struct Swappable(Mutex<Vec<Arc<dyn AgentTool>>>);
#[async_trait::async_trait]
impl ToolSource for Swappable {
async fn tools(&self) -> Vec<Arc<dyn AgentTool>> {
self.0.lock().unwrap().clone()
}
}Required Methods§
Sourcefn tools<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Vec<Arc<dyn AgentTool>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn tools<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Vec<Arc<dyn AgentTool>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
The tools to offer for the run about to start.
Called once per run, before the first request. Keep it quick: the run
waits for it. The returned Arcs are held until the run ends.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".