Skip to main content

oxi_agent/
types.rs

1/// Core types for oxi-agent
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4
5/// Tool definition
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct ToolDefinition {
8    /// pub.
9    pub name: String,
10    /// pub.
11    pub description: String,
12    /// pub.
13    pub input_schema: HashMap<String, serde_json::Value>,
14}
15
16impl ToolDefinition {
17    /// TODO.
18    pub fn new(
19        name: impl Into<String>,
20        description: impl Into<String>,
21        input_schema: HashMap<String, serde_json::Value>,
22    ) -> Self {
23        Self {
24            name: name.into(),
25            description: description.into(),
26            input_schema,
27        }
28    }
29}
30
31/// Tool call
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct ToolCall {
34    /// pub.
35    pub id: String,
36    /// pub.
37    pub name: String,
38    /// pub.
39    pub arguments: String,
40}
41
42impl ToolCall {
43    /// TODO.
44    pub fn new(
45        id: impl Into<String>,
46        name: impl Into<String>,
47        arguments: impl Into<String>,
48    ) -> Self {
49        Self {
50            id: id.into(),
51            name: name.into(),
52            arguments: arguments.into(),
53        }
54    }
55}
56
57/// Tool result
58#[derive(Debug, Clone, Serialize, Deserialize)]
59pub struct ToolResult {
60    /// pub.
61    pub tool_call_id: String,
62    /// pub.
63    pub content: String,
64    /// pub.
65    pub is_error: bool,
66}
67
68impl ToolResult {
69    /// TODO.
70    pub fn success(tool_call_id: impl Into<String>, content: impl Into<String>) -> Self {
71        Self {
72            tool_call_id: tool_call_id.into(),
73            content: content.into(),
74            is_error: false,
75        }
76    }
77
78    /// TODO.
79    pub fn error(tool_call_id: impl Into<String>, content: impl Into<String>) -> Self {
80        Self {
81            tool_call_id: tool_call_id.into(),
82            content: content.into(),
83            is_error: true,
84        }
85    }
86}
87
88/// Response message
89#[derive(Debug, Clone, Serialize, Deserialize)]
90pub struct Response {
91    /// pub.
92    pub content: String,
93    /// pub.
94    pub stop_reason: StopReason,
95}
96
97#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
98#[serde(rename_all = "camelCase")]
99/// StopReason.
100pub enum StopReason {
101    /// stop variant.
102    Stop,
103    /// length variant.
104    Length,
105    /// tool use variant.
106    ToolUse,
107    /// error variant.
108    Error,
109    /// aborted variant.
110    Aborted,
111}