pub struct Execute { /* private fields */ }Expand description
Unified agent execution service — the single place handling:
- conversation history loading (
TenantDb) - memory injection (
ContextProvider) ToolCoordinatorloop- fallback LLM chain (
Coordinator) - observability sink (
run_history+agent_runs) - usage/cost aggregation
- token budget check
- loop detection
Reachable via ctx.get::<Execute>() (see Service impl).
Implementations§
Source§impl Execute
impl Execute
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new service with no backing stores (useful for tests and
cargo check --no-default-features).
Sourcepub fn with_strict_fallbacks(self, strict: bool) -> Self
pub fn with_strict_fallbacks(self, strict: bool) -> Self
Enable strict fallback mode: every echo/fallback entry in execute
returns Err(AppError::Unavailable) whose message starts with
strict_fallbacks: instead of echoing the request.
Sourcepub fn strict_fallbacks(&self) -> bool
pub fn strict_fallbacks(&self) -> bool
Whether strict fallback mode is enabled.
Sourcepub async fn emit_agent_started(
&self,
ctx: &Arc<Context>,
payload: AgentStartedPayload,
) -> Value
pub async fn emit_agent_started( &self, ctx: &Arc<Context>, payload: AgentStartedPayload, ) -> Value
Emit the agent.started event through the Cordis event bus with
Dispatch::Parallel, which fans out to every registered observer
concurrently and awaits all of them before returning (join-all).
If no EventsService is present in the context, or the dispatch
errors, the original payload is returned unchanged so callers never
lose data.
Sourcepub async fn emit_observability(
&self,
ctx: &Arc<Context>,
event: impl Into<String>,
payload: Value,
)
pub async fn emit_observability( &self, ctx: &Arc<Context>, event: impl Into<String>, payload: Value, )
Fire-and-forget observability event via Cordis Dispatch::Emit.
Returns immediately without waiting for handlers. Missing EventsService
is a no-op. Usage snapshot recording stays in server middleware
(UsageContext is not in this crate).
Sourcepub async fn emit_observability_typed<E: TypedEvent>(
&self,
ctx: &Arc<Context>,
payload: &E::Payload,
)
pub async fn emit_observability_typed<E: TypedEvent>( &self, ctx: &Arc<Context>, payload: &E::Payload, )
Typed fire-and-forget variant of [emit_observability]: dispatches the
payload struct for its catalog-bound event via Dispatch::Emit.
Sourcepub fn with_context_provider(self, provider: Arc<dyn ContextProvider>) -> Self
pub fn with_context_provider(self, provider: Arc<dyn ContextProvider>) -> Self
Attach a context provider for memory injection.
Sourcepub fn with_agent_registry(self, registry: Arc<AgentRegistry>) -> Self
pub fn with_agent_registry(self, registry: Arc<AgentRegistry>) -> Self
Attach an agent registry for creating agents from resolved configs.
Sourcepub fn with_run_tracker(self, tracker: Arc<dyn RunTracker>) -> Self
pub fn with_run_tracker(self, tracker: Arc<dyn RunTracker>) -> Self
Attach a run tracker for observability.
Sourcepub fn run_tracker(&self) -> Option<&Arc<dyn RunTracker>>
pub fn run_tracker(&self) -> Option<&Arc<dyn RunTracker>>
Host-injected run tracker, if any.
Sourcepub async fn run(
&self,
req: &AgentRequest,
ctx: &Arc<Context>,
) -> Result<ExecutionResult, AppError>
pub async fn run( &self, req: &AgentRequest, ctx: &Arc<Context>, ) -> Result<ExecutionResult, AppError>
Execute an agent by name using the full pipeline: resolve → create → execute.
This is the PRIMARY entry point that handlers should call. It:
- Resolves the agent via crate-private
Resolver(3-tier: tenant → community → system) - Creates the agent via
AgentRegistry::create_agent_from_config_with_fallbacks - Calls
agent.execute(message, context)with the request ctx bound - Returns
ExecutionResultwith response + resolution metadata
Run tracking (start/finish) is handled internally via RunTracker.