use async_trait::async_trait;
use tokio_util::sync::CancellationToken;
use turul_a2a_types::{Message, Task};
use crate::error::A2aError;
use crate::event_sink::EventSink;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct ExecutionContext {
pub owner: String,
pub tenant: Option<String>,
pub task_id: String,
pub context_id: Option<String>,
pub claims: Option<serde_json::Value>,
pub cancellation: CancellationToken,
pub events: EventSink,
}
impl ExecutionContext {
pub fn anonymous(task_id: &str) -> Self {
Self {
owner: "anonymous".to_string(),
tenant: None,
task_id: task_id.to_string(),
context_id: None,
claims: None,
cancellation: CancellationToken::new(),
events: EventSink::detached(),
}
}
}
#[async_trait]
pub trait AgentExecutor: Send + Sync {
async fn execute(
&self,
task: &mut Task,
message: &Message,
ctx: &ExecutionContext,
) -> Result<(), A2aError>;
fn agent_card(&self) -> turul_a2a_proto::AgentCard;
fn extended_agent_card(
&self,
_claims: Option<&serde_json::Value>,
) -> Option<turul_a2a_proto::AgentCard> {
None
}
}