1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//! Agent state management and context types.
//!
//! This module provides types for managing agent state, memory, and context in autonomous
//! LLM-powered agents. These types enable agents to maintain conversation history, track
//! execution statistics, store short/long-term memory, and manage task context.
//!
//! ## Core Types
//!
//! - [`AgentState`]: Complete agent state including messages, memory, context, and stats
//! - [`AgentMemory`]: Memory storage with short-term, long-term, and working memory
//! - [`AgentContext`]: Task context including goals, constraints, and environment
//! - [`AgentMessage`]: Enum for different message types agents can process
//! - [`AgentResponse`]: Response from agent execution including content and tool results
//! - [`AgentStats`]: Execution statistics for monitoring and debugging
//!
//! ## Example: Using Agent State
//!
//! ```
//! use neuromance_common::agents::{AgentState, AgentContext, AgentMemory, AgentStats};
//!
//! // Create a new agent state with default values
//! let mut state = AgentState::default();
//!
//! // Configure the agent's task context
//! state.context.task = Some("Research the Rust programming language".to_string());
//! state.context.goals = vec![
//! "Find creation date".to_string(),
//! "Identify key features".to_string(),
//! ];
//! state.context.constraints = vec!["Use only reliable sources".to_string()];
//!
//! // Add to short-term memory
//! state.memory.short_term.push("User prefers concise answers".to_string());
//!
//! // Track statistics
//! state.stats.total_messages += 1;
//! state.stats.successful_tool_calls += 2;
//! ```
//!
//! ## Memory Management
//!
//! [`AgentMemory`] provides three types of memory storage:
//!
//! - **Short-term**: Recent context and observations (Vec of strings)
//! - **Long-term**: Persistent knowledge (key-value string storage)
//! - **Working memory**: Arbitrary JSON data for active processing
//!
//! ## Context Updates
//!
//! The [`ContextUpdate`] enum allows dynamic modification of agent context:
//!
//! ```
//! use neuromance_common::agents::ContextUpdate;
//!
//! // Examples of context updates
//! let updates = vec![
//! ContextUpdate::SetTask("New task description".to_string()),
//! ContextUpdate::AddGoal("Complete research".to_string()),
//! ContextUpdate::AddConstraint("Time limit: 5 minutes".to_string()),
//! ContextUpdate::SetEnvironmentVariable("debug".to_string(), "true".to_string()),
//! ];
//! ```
use HashMap;
use ;
use crateMessage;
/// Updates that can be applied to an agent's context.
///
/// Allows dynamic modification of task, goals, constraints, and environment during execution.
/// Messages that can be sent to or from an agent.
///
/// Represents different types of communication in an agent system.
/// Response from agent execution.
///
/// Contains the main content, optional reasoning trace, and any tool execution results.
/// Complete state of an agent.
///
/// Maintains all messages, conversation history, memory, context, and execution statistics.
/// Execution statistics for monitoring agent performance.
/// Context describing the agent's current task and environment.
/// Memory storage for agents.
///
/// Provides three types of memory for different use cases:
/// - Short-term: Recent observations and context
/// - Long-term: Persistent facts and knowledge
/// - Working: Arbitrary data for active processing