opi_agent/event.rs
1//! Agent event protocol (S7.4).
2
3use crate::message::AgentMessage;
4
5/// Callback type for emitting agent events to subscribers.
6pub type AgentEventSink = Box<dyn Fn(AgentEvent) + Send + Sync>;
7
8/// Events emitted during the agent loop lifecycle.
9#[non_exhaustive]
10#[derive(Debug)]
11pub enum AgentEvent {
12 /// The agent loop has started.
13 AgentStart,
14 /// The agent loop has ended. No more loop events will be emitted.
15 AgentEnd { messages: Vec<AgentMessage> },
16 /// A new turn (provider request/response cycle) has started.
17 TurnStart,
18 /// A turn has ended with the assistant message and any tool results.
19 TurnEnd {
20 message: AgentMessage,
21 tool_results: Vec<opi_ai::message::ToolResultMessage>,
22 },
23 /// An assistant message has started streaming.
24 MessageStart { message: AgentMessage },
25 /// An assistant message has been updated with a stream event.
26 MessageUpdate {
27 message: AgentMessage,
28 assistant_event: Box<opi_ai::stream::AssistantStreamEvent>,
29 },
30 /// An assistant message has finished streaming.
31 MessageEnd { message: AgentMessage },
32 /// Tool execution is about to begin.
33 ToolExecutionStart {
34 tool_call_id: String,
35 tool_name: String,
36 args: serde_json::Value,
37 },
38 /// Tool execution has produced a progress update.
39 ToolExecutionUpdate {
40 tool_call_id: String,
41 tool_name: String,
42 args: serde_json::Value,
43 partial_result: serde_json::Value,
44 },
45 /// Tool execution has completed.
46 ToolExecutionEnd {
47 tool_call_id: String,
48 tool_name: String,
49 result: serde_json::Value,
50 is_error: bool,
51 },
52 /// Queue messages were delivered to the conversation.
53 QueueUpdate {
54 steering: Vec<String>,
55 follow_up: Vec<String>,
56 },
57}