Skip to main content

aether_core/core/
agent_deps.rs

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