autoagents_core/
protocol.rs

1use autoagents_llm::chat::ChatMessage;
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4use uuid::Uuid;
5
6/// Submission IDs are used to track agent tasks
7pub type SubmissionId = Uuid;
8
9/// Agent IDs are used to identify agents
10pub type AgentID = Uuid;
11
12/// Session IDs are used to identify sessions
13pub type SessionId = Uuid;
14
15/// Event IDs are used to correlate events with their responses
16pub type EventId = Uuid;
17
18/// Protocol events represent the various events that can occur during agent execution
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub enum Event {
21    /// A new task has been submitted to an agent
22    NewTask {
23        sub_id: SubmissionId,
24        agent_id: Option<AgentID>,
25        prompt: String,
26    },
27
28    /// A task has been completed
29    TaskComplete {
30        sub_id: SubmissionId,
31        result: TaskResult,
32    },
33
34    /// A message from the agent to be presented to the user
35    AgentMessage {
36        sub_id: SubmissionId,
37        message: AgentMessage,
38    },
39
40    /// A tool request from the agent
41    ToolRequest {
42        sub_id: SubmissionId,
43        event_id: EventId,
44        request: ToolRequest,
45    },
46
47    /// A response to a tool request
48    ToolResponse {
49        sub_id: SubmissionId,
50        event_id: EventId,
51        response: ToolResponse,
52    },
53
54    /// An input request for the user
55    InputRequest {
56        sub_id: SubmissionId,
57        event_id: EventId,
58        prompt: String,
59    },
60
61    /// A response to an input request
62    InputResponse {
63        sub_id: SubmissionId,
64        event_id: EventId,
65        input: String,
66    },
67
68    /// An error occurred during task execution
69    Error { sub_id: SubmissionId, error: String },
70}
71
72/// Results from a completed task
73#[derive(Debug, Clone, Serialize, Deserialize)]
74pub enum TaskResult {
75    /// The task was completed successfully
76    Success(String),
77
78    /// The task was completed with a value
79    Value(serde_json::Value),
80
81    /// The task failed
82    Failure(String),
83
84    /// The task was aborted
85    Aborted,
86}
87
88/// Messages from the agent
89#[derive(Debug, Clone, Serialize, Deserialize)]
90pub struct AgentMessage {
91    /// The content of the message
92    pub content: String,
93
94    /// Optional chat messages for a full conversation history
95    pub chat_messages: Option<Vec<ChatMessage>>,
96}
97
98/// A request to use a tool
99#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct ToolRequest {
101    /// The name of the tool to use
102    pub tool_name: String,
103
104    /// The arguments to the tool
105    pub arguments: serde_json::Value,
106
107    /// Whether the tool needs approval
108    pub needs_approval: bool,
109}
110
111/// A response from a tool
112#[derive(Debug, Clone, Serialize, Deserialize)]
113pub enum ToolResponse {
114    /// The tool was approved and executed
115    Success(serde_json::Value),
116
117    /// The tool was denied
118    Denied,
119
120    /// The tool execution failed
121    Failure(String),
122}
123
124/// Protocol commands for controlling agent execution
125#[derive(Debug, Clone, Serialize, Deserialize)]
126pub enum Command {
127    /// Submit a new task to an agent
128    Submit {
129        agent_id: Uuid,
130        prompt: String,
131        context: Option<HashMap<String, String>>,
132    },
133
134    /// Submit a new task with a specific ID
135    SubmitWithId {
136        sub_id: SubmissionId,
137        agent_id: Uuid,
138        prompt: String,
139        context: Option<HashMap<String, String>>,
140    },
141
142    /// Approve a tool request
143    ApproveTool {
144        sub_id: SubmissionId,
145        event_id: EventId,
146    },
147
148    /// Deny a tool request
149    DenyTool {
150        sub_id: SubmissionId,
151        event_id: EventId,
152    },
153
154    /// Provide input for an input request
155    ProvideInput {
156        sub_id: SubmissionId,
157        event_id: EventId,
158        input: String,
159    },
160
161    /// Abort a task
162    Abort { sub_id: SubmissionId },
163}