Skip to main content

agent_service/manager/
run_executor.rs

1//! The asynchronous contract implemented by run executors.
2
3use super::ExecutionReport;
4use crate::RunId;
5use agent_runtime::{CancellationToken, EventSink, Message, ToolContext};
6use async_trait::async_trait;
7use std::sync::Arc;
8
9/// Executes an accepted agent run with its conversation history and trusted context.
10#[async_trait]
11pub trait RunExecutor: Send + Sync + 'static {
12    async fn execute(
13        &self,
14        run_id: RunId,
15        agent: String,
16        input: String,
17        history: Vec<Message>,
18        context: ToolContext,
19        cancellation: CancellationToken,
20    ) -> Result<ExecutionReport, String>;
21
22    /// Executes while forwarding runtime events as they occur. Executors that
23    /// do not support live events may keep the default batch-based behavior.
24    async fn execute_with_event_sink(
25        &self,
26        run_id: RunId,
27        agent: String,
28        input: String,
29        history: Vec<Message>,
30        context: ToolContext,
31        cancellation: CancellationToken,
32        event_sink: Arc<dyn EventSink>,
33    ) -> Result<ExecutionReport, String> {
34        drop(event_sink);
35        self.execute(run_id, agent, input, history, context, cancellation)
36            .await
37    }
38}