-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmod.rs
More file actions
63 lines (61 loc) · 1.9 KB
/
mod.rs
File metadata and controls
63 lines (61 loc) · 1.9 KB
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
//! Background agent execution system.
//!
//! This module provides infrastructure for running agents in the background
//! with async communication, event broadcasting, and lifecycle management.
//!
//! # Architecture
//!
//! ```text
//! BackgroundAgentManager
//! ├── BackgroundAgent (tokio task)
//! │ ├── status channel (mpsc)
//! │ ├── cancel channel (oneshot)
//! │ └── mailbox (AgentMailbox)
//! ├── Event broadcaster (broadcast)
//! └── Agent registry (HashMap)
//! ```
//!
//! # Example
//!
//! ```rust,ignore
//! use cortex_agents::background::{
//! BackgroundAgentManager, AgentConfig, AgentEvent
//! };
//!
//! // Create manager
//! let mut manager = BackgroundAgentManager::new(5);
//!
//! // Subscribe to events
//! let mut events = manager.subscribe();
//!
//! // Spawn a background agent
//! let id = manager.spawn(AgentConfig::new("Search for patterns")).await?;
//!
//! // Monitor events
//! while let Ok(event) = events.recv().await {
//! match event {
//! AgentEvent::Progress { id, message } => println!("{}: {}", id, message),
//! AgentEvent::Completed { id, result } => {
//! println!("Agent {} completed: {:?}", id, result);
//! break;
//! }
//! _ => {}
//! }
//! }
//! ```
//!
//! # Safety & Limits
//!
//! - Maximum concurrent agents: configurable (default 5)
//! - Automatic timeout: 30 minutes per agent
//! - RAII cleanup: agents are cancelled when manager is dropped
//! - Isolated contexts: agents don't share credentials
pub mod events;
pub mod executor;
pub mod messaging;
pub use events::{AgentEvent, Notification, NotificationLevel, NotificationManager};
pub use executor::{
AgentConfig, AgentResult, AgentStatus, BackgroundAgent, BackgroundAgentError,
BackgroundAgentManager,
};
pub use messaging::{AgentMailbox, AgentMessage, MessageContent, MessageRouter};