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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
//! # HOPE Agents - Hierarchical Optimizing Policy Engine
//!
//! Autonomous AI agents framework for AIngle semantic networks.
//!
//! ## Overview
//!
//! HOPE Agents provides a complete framework for building autonomous AI agents that can:
//! - **Observe** their environment (IoT sensors, network events, user inputs)
//! - **Decide** based on learned policies and hierarchical goals
//! - **Execute** actions in the AIngle network
//! - **Learn** and adapt over time using reinforcement learning
//!
//! This crate is designed for use cases ranging from simple reactive agents to complex
//! multi-agent systems with learning capabilities
//!
//! ## Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────┐
//! │ HOPE Agent │
//! ├─────────────────────────────────────────────────────────────┤
//! │ │
//! │ ┌──────────────┐ ┌──────────────┐ ┌──────────────────┐ │
//! │ │ Sensors │ │ Policy │ │ Actuators │ │
//! │ │ │ │ Engine │ │ │ │
//! │ │ • IoT data │─►│ │─►│ • Network calls │ │
//! │ │ • Events │ │ • Goals │ │ • State changes │ │
//! │ │ • Messages │ │ • Rules │ │ • Messages │ │
//! │ └──────────────┘ │ • Learning │ └──────────────────┘ │
//! │ └──────┬───────┘ │
//! │ │ │
//! │ ┌──────▼───────┐ │
//! │ │ Memory │ │
//! │ │ (Titans) │ │
//! │ │ │ │
//! │ │ STM ◄──► LTM │ │
//! │ └──────────────┘ │
//! │ │
//! └─────────────────────────────────────────────────────────────┘
//! ```
//!
//! ## Quick Start
//!
//! ### Simple Reactive Agent
//!
//! ```rust,ignore
//! use hope_agents::{Agent, SimpleAgent, Goal, Observation, Rule, Condition, Action};
//!
//! // Create a simple reactive agent
//! let mut agent = SimpleAgent::new("sensor_monitor");
//!
//! // Add a rule: if temperature > 30, alert
//! let rule = Rule::new(
//! "high_temp",
//! Condition::above("temperature", 30.0),
//! Action::alert("Temperature too high!"),
//! );
//! agent.add_rule(rule);
//!
//! // Process observations
//! let obs = Observation::sensor("temperature", 35.0);
//! agent.observe(obs.clone());
//! let action = agent.decide();
//! let result = agent.execute(action.clone());
//! agent.learn(&obs, &action, &result);
//! ```
//!
//! ### HOPE Agent with Learning
//!
//! ```rust,ignore
//! use hope_agents::{HopeAgent, HopeConfig, Observation, Goal, Priority, Outcome};
//!
//! // Create a HOPE agent with learning, prediction, and hierarchical goals
//! let mut agent = HopeAgent::with_default_config();
//!
//! // Set a goal
//! let goal = Goal::maintain("temperature", 20.0..25.0)
//! .with_priority(Priority::High);
//! agent.set_goal(goal);
//!
//! // Agent loop with reinforcement learning
//! for episode in 0..100 {
//! let obs = Observation::sensor("temperature", 22.0);
//! let action = agent.step(obs.clone());
//!
//! // Execute action in environment and get reward
//! let reward = 1.0; // Example reward
//! let next_obs = Observation::sensor("temperature", 21.0);
//!
//! let outcome = Outcome::new(action, result, reward, next_obs, false);
//! agent.learn(outcome);
//! }
//! ```
//!
//! ### Multi-Agent Coordination
//!
//! ```rust,ignore
//! use hope_agents::{AgentCoordinator, HopeAgent, Message, Observation};
//! use std::collections::HashMap;
//!
//! // Create coordinator
//! let mut coordinator = AgentCoordinator::new();
//!
//! // Register agents
//! let agent1 = HopeAgent::with_default_config();
//! let agent2 = HopeAgent::with_default_config();
//!
//! let id1 = coordinator.register_agent(agent1);
//! let id2 = coordinator.register_agent(agent2);
//!
//! // Broadcast message
//! coordinator.broadcast(Message::new("update", "System status changed"));
//!
//! // Step all agents
//! let mut observations = HashMap::new();
//! observations.insert(id1, Observation::sensor("temp", 20.0));
//! observations.insert(id2, Observation::sensor("humidity", 60.0));
//!
//! let actions = coordinator.step_all(observations);
//! ```
//!
//! ### State Persistence
//!
//! ```rust,ignore
//! use hope_agents::{HopeAgent, AgentPersistence};
//! use std::path::Path;
//!
//! let mut agent = HopeAgent::with_default_config();
//!
//! // Train the agent...
//!
//! // Save agent state
//! agent.save_to_file(Path::new("agent_state.json")).unwrap();
//!
//! // Later, load agent state
//! let loaded_agent = HopeAgent::load_from_file(Path::new("agent_state.json")).unwrap();
//! ```
//!
//! ## Agent Types
//!
//! - **ReactiveAgent**: Simple stimulus-response behavior
//! - **GoalBasedAgent**: Works toward explicit goals
//! - **LearningAgent**: Adapts behavior over time
//! - **CooperativeAgent**: Coordinates with other agents
pub use ;
pub use ;
pub use AgentConfig;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use *;
/// HOPE framework version
pub const VERSION: &str = env!;
/// Creates a simple agent with default configuration.
///
/// This is a convenience function that creates a [`SimpleAgent`] with standard settings
/// suitable for general-purpose use. The agent will have learning enabled, a maximum of
/// 10 goals, and default policy engine settings.
///
/// # Arguments
///
/// * `name` - A unique identifier for the agent. This will be used in logging and coordination.
///
/// # Examples
///
/// ```
/// use hope_agents::{create_agent, Agent};
///
/// let agent = create_agent("my_agent");
/// assert_eq!(agent.name(), "my_agent");
/// ```
///
/// # See Also
///
/// - [`SimpleAgent::new`] for direct construction
/// - [`SimpleAgent::with_config`] for custom configuration
/// - [`create_iot_agent`] for IoT-optimized agents with reduced memory footprint
/// Creates an IoT-optimized agent with reduced memory footprint.
///
/// This creates a [`SimpleAgent`] configured for resource-constrained environments
/// with memory limits suitable for embedded devices. IoT agents trade some capabilities
/// for reduced resource usage, making them ideal for edge computing scenarios.
///
/// # Arguments
///
/// * `name` - A unique identifier for the agent.
///
/// # Examples
///
/// ```
/// use hope_agents::{create_iot_agent, Agent};
///
/// let agent = create_iot_agent("sensor_agent");
/// assert!(agent.config().max_memory_bytes <= 128 * 1024);
/// ```
///
/// # Configuration
///
/// IoT agents have:
/// - Maximum memory: 128KB
/// - Learning disabled by default (can be re-enabled)
/// - Reduced observation buffer size
/// - Maximum of 5 concurrent goals (vs. 10 for standard agents)
/// - Simplified policy engine with fewer rules
///
/// # See Also
///
/// - [`AgentConfig::iot_mode`] for manual configuration
/// - [`create_agent`] for standard agents with full capabilities