Skip to main content

robit_agent/
event.rs

1//! Agent event and message types for Frontend <-> Agent communication.
2
3use crate::tool::ToolResult;
4
5/// Unique session identifier (UUID v4).
6pub type SessionId = String;
7
8/// Create a new random session ID.
9pub fn new_session_id() -> SessionId {
10    uuid::Uuid::new_v4().to_string()
11}
12
13/// Events pushed from Agent to Frontend.
14#[derive(Debug)]
15pub enum AgentEvent {
16    /// Streaming text delta from LLM response.
17    TextDelta(String),
18
19    /// LLM requested a tool call. Frontend should display and optionally wait for confirmation.
20    ToolCallRequested {
21        tool_call_id: String,
22        name: String,
23        arguments: String,
24    },
25
26    /// Tool execution completed with result.
27    ToolCallResult {
28        tool_call_id: String,
29        result: ToolResult,
30    },
31
32    /// Current turn is complete (LLM finished responding, no more tool calls).
33    TurnComplete,
34
35    /// An error occurred during agent execution.
36    Error(crate::error::AgentError),
37
38    /// A skill was triggered. Frontend can display this as a system notice.
39    SkillTriggered { name: String, description: String },
40}
41
42/// Messages sent from Frontend to Agent.
43#[derive(Debug)]
44pub enum FrontendMessage {
45    /// User typed a new message.
46    UserInput(String),
47
48    /// User wants to cancel the current operation.
49    Cancel,
50
51    /// User responded to a tool confirmation request.
52    ConfirmationResponse {
53        tool_call_id: String,
54        approved: bool,
55    },
56}