Skip to main content

aether_core/core/
agent_deps.rs

1use crate::events::{AgentObserver, DynObserverFactory, TraceContext};
2use aether_auth::OAuthCredentialStorage;
3use std::sync::Arc;
4
5/// Cross-cutting dependencies threaded to every agent a run spawns — the root
6/// agent and any sub-agents created by in-memory MCP servers. Bundling them
7/// keeps the plumbing through builders and servers a single value.
8#[derive(Clone, Default)]
9pub struct AgentDeps {
10    pub oauth_credential_store: Option<Arc<dyn OAuthCredentialStorage>>,
11    pub observer_factory: Option<DynObserverFactory>,
12    /// Remote trace these agents continue, set by whoever handled the request
13    /// that spawned them.
14    pub parent_trace_context: Option<TraceContext>,
15}
16
17impl AgentDeps {
18    pub fn new(
19        oauth_credential_store: Arc<dyn OAuthCredentialStorage>,
20        observer_factory: Option<DynObserverFactory>,
21    ) -> Self {
22        Self { oauth_credential_store: Some(oauth_credential_store), observer_factory, parent_trace_context: None }
23    }
24
25    /// Continue `parent`'s trace in every agent built from these deps.
26    pub fn with_parent_trace_context(mut self, parent: Option<TraceContext>) -> Self {
27        self.parent_trace_context = parent;
28        self
29    }
30
31    /// A fresh observer isolated to one agent, if a factory is configured.
32    pub fn observer(&self) -> Option<Box<dyn AgentObserver>> {
33        self.observer_factory.as_ref().map(|factory| factory.agent(self.parent_trace_context.as_ref()))
34    }
35}