pub struct DependencyMap { /* private fields */ }Implementations§
Source§impl DependencyMap
impl DependencyMap
pub fn new() -> Self
pub fn insert<T>(&self, value: T)
Sourcepub fn get<T>(&self) -> Option<Arc<T>>
pub fn get<T>(&self) -> Option<Arc<T>>
Examples found in repository?
examples/di_override.rs (line 52)
43async fn main() -> Result<(), Box<dyn Error>> {
44 let read_dep_tool = ToolSpec::new("read_dep", "read injected value")
45 .with_schema(json!({
46 "type": "object",
47 "properties": {},
48 "required": [],
49 "additionalProperties": false
50 }))?
51 .with_handler(|_args, deps| {
52 let value = deps.get::<u32>().map(|v| *v).unwrap_or_default();
53 async move { Ok(ToolOutcome::Text(value.to_string())) }
54 });
55
56 let done_tool = ToolSpec::new("done", "finish")
57 .with_schema(json!({
58 "type": "object",
59 "properties": {
60 "message": {"type": "string"}
61 },
62 "required": ["message"],
63 "additionalProperties": false
64 }))?
65 .with_handler(|args, _deps| async move {
66 let message = args
67 .get("message")
68 .and_then(|v| v.as_str())
69 .unwrap_or("done");
70 Ok(ToolOutcome::Done(message.to_string()))
71 });
72
73 let model = ScriptedModel::new(vec![
74 Ok(ModelCompletion {
75 text: None,
76 thinking: None,
77 tool_calls: vec![ModelToolCall {
78 id: "call_1".to_string(),
79 name: "read_dep".to_string(),
80 arguments: json!({}),
81 }],
82 usage: None,
83 }),
84 Ok(ModelCompletion {
85 text: None,
86 thinking: None,
87 tool_calls: vec![ModelToolCall {
88 id: "call_2".to_string(),
89 name: "done".to_string(),
90 arguments: json!({"message": "dependency override applied"}),
91 }],
92 usage: None,
93 }),
94 ]);
95
96 let mut agent = Agent::builder()
97 .model(model)
98 .tool(read_dep_tool)
99 .tool(done_tool)
100 .dependency(1_u32)
101 .dependency_override(9_u32)
102 .build()?;
103
104 let response = agent.query("use dependency").await?;
105 println!("final: {response}");
106
107 Ok(())
108}pub fn insert_named<T>(&self, key: impl Into<String>, value: T)
pub fn get_named<T>(&self, key: &str) -> Option<Arc<T>>
pub fn merged_with(&self, overrides: &DependencyMap) -> DependencyMap
Trait Implementations§
Source§impl Clone for DependencyMap
impl Clone for DependencyMap
Source§fn clone(&self) -> DependencyMap
fn clone(&self) -> DependencyMap
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DependencyMap
impl Debug for DependencyMap
Source§impl Default for DependencyMap
impl Default for DependencyMap
Source§fn default() -> DependencyMap
fn default() -> DependencyMap
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for DependencyMap
impl RefUnwindSafe for DependencyMap
impl Send for DependencyMap
impl Sync for DependencyMap
impl Unpin for DependencyMap
impl UnsafeUnpin for DependencyMap
impl UnwindSafe for DependencyMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more