use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::execution::{
EventId, ExternalError, InvocationContext, MessageId, PreparedAction, RuntimeSnapshot,
UsageSummary,
};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum AgentEvent {
Started,
InteractionRequired {
batch_id: MessageId,
actions: Vec<PreparedAction>,
usage: UsageSummary,
},
Completed {
result: Value,
usage: UsageSummary,
},
Failed {
code: String,
message: String,
usage: UsageSummary,
},
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum AgentObservation {
Progress {
status: String,
},
CompanionText {
content: String,
append: bool,
},
ToolStarted {
call_id: String,
tool_name: String,
},
ToolResult {
call_id: String,
tool_name: String,
result: Value,
is_error: bool,
},
ToolCallsScheduled {
tool_names: Vec<String>,
},
ToolCallsCompleted {
count: u32,
},
DebugData {
scope: String,
payload: Value,
},
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct DurableEvent {
pub id: EventId,
pub sequence: u64,
pub context: InvocationContext,
pub event: AgentEvent,
}
#[async_trait]
pub trait EventPublisher: Send + Sync {
async fn publish(
&self,
snapshot: &RuntimeSnapshot,
event: &DurableEvent,
) -> Result<(), ExternalError>;
}
#[async_trait]
pub trait Observer: Send + Sync {
async fn observe(&self, context: &InvocationContext, observation: &AgentObservation);
}