feat: implement background agents and async messaging system#422
Open
feat: implement background agents and async messaging system#422
Conversation
This commit adds the complete background worker architecture and asynchronous messaging system for the CLI as specified in ORCHESTRATE/AGENT_1_BACKGROUND_AGENTS.md. ## New Features ### Background Agent Module (cortex-agents/src/background/) - **executor.rs**: BackgroundAgentManager for spawning and managing background tasks - Configurable max concurrent agents (default: 5) - Automatic timeout after 30 minutes - RAII cleanup with proper cancellation support - Event broadcasting for monitoring - **messaging.rs**: Inter-agent async messaging system - AgentMailbox for per-agent message queues - MessageRouter for routing messages between agents - Support for notifications, requests/responses, data sharing, and status updates - **events.rs**: Event system for background agents - AgentEvent enum for lifecycle events (Started, Progress, Completed, Failed, Cancelled) - NotificationManager for collecting and displaying notifications - Support for TodoUpdated events for progress tracking ### TUI Enhancements (cortex-tui/) - New /tasks command (aliases: /bg, /background) for viewing background tasks - TasksView component for displaying task status, duration, and progress - ModalType::Tasks for the background tasks modal ## Tests - 21 new unit tests covering: - Background agent spawning and cancellation - Max concurrent agent limits - Event subscription and notification - Inter-agent messaging - Notification management ## Implementation Details - Uses tokio for async runtime with mpsc/broadcast channels - Proper error handling with BackgroundAgentError enum - Isolated agent contexts (no shared credentials) - Grace period for cancellation (5 seconds)
…resolve conflicts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements the complete background worker architecture and asynchronous messaging system for the CLI as specified in
ORCHESTRATE/AGENT_1_BACKGROUND_AGENTS.md.Changes
New Background Agent Module (
cortex-agents/src/background/)executor.rs:
BackgroundAgentManagerfor spawning and managing background tasksmessaging.rs: Inter-agent async messaging system
AgentMailboxfor per-agent message queuesMessageRouterfor routing messages between agentsevents.rs: Event system for background agents
AgentEventenum for lifecycle events (Started, Progress, Completed, Failed, Cancelled)NotificationManagerfor collecting and displaying notificationsTUI Enhancements (
cortex-tui/)/taskscommand (aliases:/bg,/background) for viewing background tasksTasksViewcomponent for displaying task status, duration, and progressModalType::Tasksfor the background tasks modalTests
Verification
cargo check -p cortex-agents✅cargo check -p cortex-tui✅cargo fmt✅cargo test -p cortex-agents -- background✅ (21 tests pass)Related
ORCHESTRATE/AGENT_1_BACKGROUND_AGENTS.md