Skip to main content

agent_runtime/
types.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4#[cfg(test)]
5#[path = "types_test.rs"]
6mod types_test;
7
8/// Unique identifier for workflows
9pub type WorkflowId = String;
10
11/// Unique identifier for events
12pub type EventId = String;
13
14/// Sequential offset for event ordering
15pub type EventOffset = u64;
16
17/// Generic JSON value for flexible data passing
18pub type JsonValue = serde_json::Value;
19
20/// Input data passed to an agent
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct AgentInput {
23    pub data: JsonValue,
24    pub metadata: AgentInputMetadata,
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct AgentInputMetadata {
29    pub step_index: usize,
30    pub previous_agent: Option<String>,
31}
32
33/// Output data produced by an agent
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct AgentOutput {
36    pub data: JsonValue,
37    pub metadata: AgentOutputMetadata,
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct AgentOutputMetadata {
42    pub agent_name: String,
43    pub execution_time_ms: u64,
44    pub tool_calls_count: usize,
45}
46
47/// Result type for agent execution
48pub type AgentResult = Result<AgentOutput, AgentError>;
49
50/// Errors that can occur during agent execution
51#[derive(Debug, Clone, Serialize, Deserialize, thiserror::Error)]
52pub enum AgentError {
53    #[error("Tool execution failed: {0}")]
54    ToolError(String),
55
56    #[error("Invalid input: {0}")]
57    InvalidInput(String),
58
59    #[error("Execution failed: {0}")]
60    ExecutionError(String),
61}
62
63/// Tool invocation parameters
64#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct ToolCall {
66    pub tool_name: String,
67    pub parameters: HashMap<String, JsonValue>,
68}
69
70/// Tool execution result
71#[derive(Debug, Clone, Serialize, Deserialize)]
72pub struct ToolResult {
73    pub output: JsonValue,
74    pub duration_ms: u64,
75}
76
77/// Result type for tool execution
78pub type ToolExecutionResult = Result<ToolResult, ToolError>;
79
80/// Errors that can occur during tool execution
81#[derive(Debug, Clone, Serialize, Deserialize, thiserror::Error)]
82pub enum ToolError {
83    #[error("Invalid parameters: {0}")]
84    InvalidParameters(String),
85
86    #[error("Execution failed: {0}")]
87    ExecutionFailed(String),
88}