Skip to main content

brainwires_agent/
lib.rs

1#![deny(missing_docs)]
2//! Brainwires Agents - Agent orchestration, coordination, and lifecycle management
3//!
4//! This crate provides the multi-agent infrastructure for autonomous task execution:
5//!
6//! ## Core Components
7//! - **CommunicationHub** - Inter-agent messaging bus with 50+ message types
8//! - **FileLockManager** - File access coordination with deadlock detection
9//! - **ResourceLockManager** - Scoped resource locking with heartbeat-based liveness
10//! - **OperationTracker** - Operation tracking with heartbeat-based liveness checking
11//! - **ValidationLoop** - Quality checks before agent completion (Bug #5 prevention)
12//! - **TaskManager** - Hierarchical task decomposition and dependency tracking
13//! - **TaskQueue** - Priority-based task scheduling with dependency awareness
14//!
15//! ## Coordination Patterns
16//! - **ContractNet** - Bidding protocol for agent negotiation
17//! - **Saga** - Compensating transactions for distributed operations
18//! - **OptimisticConcurrency** - Optimistic locking with version-based conflict detection
19//! - **WaitQueue** - Queue-based coordination primitives
20//! - **MarketAllocation** - Market-based task allocation
21//! - **ThreeStateModel** - State snapshots for rollback support
22//!
23//! ## Analysis & Validation
24//! - **ResourceChecker** - Conflict detection and resolution
25//! - **ValidationAgent** - Rule-based validation
26//! - **Confidence** - Response confidence scoring
27//! - **WorktreeManager** - Git worktree management for agent isolation
28//!
29//! ## Feature Flags
30//! - `tools` - Enable validation tool integration (check_duplicates, verify_build, check_syntax)
31
32// Re-export core types
33pub use brainwires_core;
34
35// Re-export the tool runtime for ToolExecutor / ToolRegistry trait surface.
36pub use brainwires_tool_runtime;
37
38// ── LLM-driven workhorses moved to brainwires-inference in Phase 11f ─────────
39// chat_agent, summarization, planner_agent, judge_agent, validator_agent,
40// validation_agent, validation_loop, cycle_orchestrator, plan_executor,
41// system_prompts, task_agent — see crates/brainwires-inference/
42
43// ── Personas (pluggable system-prompt assembly) ──────────────────────────────
44
45pub mod personas;
46
47// agent_hooks moved to brainwires-inference in Phase 11f (TaskAgent-coupled).
48
49// runtime + context moved to brainwires-inference in Phase 11f (the
50// AgentRuntime drives the inference workhorses; AgentContext owns the
51// AgentLifecycleHooks trait object).
52
53// ── Schema + lifecycle ───────────────────────────────────────────────────────
54
55pub mod execution_graph;
56// pool moved to brainwires-inference in Phase 11f (TaskAgent pool, not generic).
57pub mod roles;
58
59// ── Core components ──────────────────────────────────────────────────────────
60
61pub mod communication;
62// `confidence` moved to `brainwires-core` in Phase 11a; the agent-side
63// shim was dropped in Phase 11g. Use `brainwires_core::confidence::*`
64// directly.
65pub mod file_locks;
66pub mod operation_tracker;
67pub mod resource_locks;
68pub mod task_manager;
69pub mod task_queue;
70
71// ── Coordination patterns ────────────────────────────────────────────────────
72
73pub mod contract_net;
74pub mod market_allocation;
75pub mod optimistic;
76pub mod saga;
77pub mod state_model;
78pub mod wait_queue;
79
80// ── Access control ─────────────────────────────────────────────────────────
81
82pub mod access_control;
83
84// ── Agent management (lifecycle trait + MCP tool registry) ─────────────────
85//
86// Moved out of brainwires-network in Phase 2 — both modules import only
87// brainwires_core/serde/anyhow/async_trait, so they belong here with the
88// rest of the agent-runtime surface.
89
90/// Agent lifecycle management — `AgentManager` trait + `SpawnConfig`.
91pub mod agent_manager;
92/// Pre-built MCP tools for agent operations — `AgentToolRegistry`.
93pub mod agent_tools;
94
95pub use agent_manager::{AgentInfo, AgentManager, AgentResult, SpawnConfig};
96pub use agent_tools::AgentToolRegistry;
97
98// ── Git coordination ───────────────────────────────────────────────────────
99
100pub mod git_coordination;
101
102// plan_executor moved to brainwires-inference in Phase 11f.
103
104// task_orchestrator moved to brainwires-inference in Phase 11f
105// (TaskAgent-coupled, not a generic orchestrator).
106
107// ── Workflow graph builder ───────────────────────────────────────────────────
108
109pub mod workflow;
110
111// ── OpenTelemetry export ─────────────────────────────────────────────────────
112#[cfg(feature = "otel")]
113pub mod otel;
114
115// Eval — extracted to its own brainwires-eval crate in Phase 11e.
116
117// MDAP — extracted to its own brainwires-mdap crate in Phase 11b.
118
119// SEAL — extracted to its own brainwires-seal crate in Phase 11d.
120
121// Skills — extracted to its own brainwires-skills crate in Phase 11c.
122
123// ── Analysis ────────────────────────────────────────────────────────────────
124
125pub mod resource_checker;
126// validation_agent + validation_loop moved to brainwires-inference in Phase 11f.
127#[cfg(feature = "native")]
128pub mod worktree;
129
130// ── Re-exports ───────────────────────────────────────────────────────────────
131
132// agent_hooks re-exports moved to brainwires-inference in Phase 11f
133// (the trait references TaskAgentResult, which is TaskAgent-specific).
134
135// AgentRuntime + run_agent_loop re-exports moved to brainwires-inference in
136// Phase 11f.
137
138// Core components
139pub use communication::{
140    AgentMessage, CommunicationHub, ConflictInfo, ConflictType, GitOperationType,
141};
142// confidence types moved to brainwires-core in Phase 11a; re-export shim
143// dropped in Phase 11g. Import from `brainwires_core::confidence::*` directly.
144pub use file_locks::{FileLockManager, LockType};
145pub use operation_tracker::OperationTracker;
146pub use resource_checker::{ConflictCheck, ResourceChecker};
147pub use resource_locks::{
148    ResourceLockGuard, ResourceLockManager, ResourceScope, ResourceType as ResourceLockType,
149};
150pub use task_manager::{TaskManager, format_duration_secs};
151pub use task_queue::TaskQueue;
152#[cfg(feature = "native")]
153pub use worktree::WorktreeManager;
154
155// Access control
156pub use access_control::{AccessControlManager, ContentionStrategy, LockBundle, LockPersistence};
157
158// Git coordination
159pub use git_coordination::{
160    GitCoordinator, GitLockRequirements, GitOperationLocks, GitOperationRunner,
161    get_lock_requirements, git_tools,
162};
163
164// Task orchestration re-exports moved to brainwires-inference in Phase 11f
165// (TaskAgent-coupled).
166
167// Workflow graph builder
168pub use workflow::{WorkflowBuilder, WorkflowContext, WorkflowResult};
169
170// Coordination patterns
171pub use contract_net::ContractNetManager;
172pub use market_allocation::MarketAllocator;
173pub use optimistic::OptimisticController;
174pub use saga::SagaExecutor;
175pub use state_model::{StateModelProposedOperation, StateSnapshot, ThreeStateModel};
176pub use wait_queue::WaitQueue;
177
178// Schema + lifecycle (AgentContext re-export moved to brainwires-inference in 11f)
179pub use brainwires_tool_runtime::{PreHookDecision, ToolPreHook};
180pub use execution_graph::{ExecutionGraph, RunTelemetry, StepNode, ToolCallRecord};
181// pool re-exports moved to brainwires-inference in Phase 11f.
182
183// SEAL re-exports — extracted to brainwires-seal in Phase 11d.
184// LLM-driven workhorses (chat_agent, planner_agent, judge_agent, validator_agent,
185// validation_agent, validation_loop, cycle_orchestrator, plan_executor,
186// summarization, system_prompts, task_agent) — extracted to brainwires-inference
187// in Phase 11f. Import from `brainwires_inference::*` directly or via
188// `brainwires::inference::*` (facade).
189
190/// Prelude module for convenient imports — coordination + patterns + schema.
191///
192/// LLM-driven workhorses (`ChatAgent`, `TaskAgent`, planner/judge/validator,
193/// validation_loop, cycle_orchestrator, plan_executor, system_prompts,
194/// summarization) live in `brainwires-inference` since Phase 11f. Import
195/// from there directly or use the umbrella `brainwires::inference` module.
196pub mod prelude {
197    // Schema + lifecycle (AgentContext lives in brainwires-inference now)
198    pub use super::execution_graph::{ExecutionGraph, RunTelemetry, StepNode, ToolCallRecord};
199    pub use brainwires_tool_runtime::{PreHookDecision, ToolPreHook};
200
201    // Core components
202    pub use super::communication::{AgentMessage, CommunicationHub, ConflictInfo, ConflictType};
203    pub use super::file_locks::{FileLockManager, LockType};
204    pub use super::operation_tracker::OperationTracker;
205    pub use super::resource_checker::{ConflictCheck, ResourceChecker};
206    pub use super::resource_locks::{ResourceLockManager, ResourceScope};
207    pub use super::state_model::{StateSnapshot, ThreeStateModel};
208    pub use super::task_manager::{TaskManager, format_duration_secs};
209    pub use super::task_queue::TaskQueue;
210    #[cfg(feature = "native")]
211    pub use super::worktree::WorktreeManager;
212    pub use brainwires_core::confidence::{ConfidenceFactors, ResponseConfidence};
213
214    // Access control
215    pub use super::access_control::{AccessControlManager, ContentionStrategy, LockPersistence};
216
217    // Git coordination
218    pub use super::git_coordination::{GitCoordinator, git_tools};
219
220    // Workflow graph builder
221    pub use super::workflow::{WorkflowBuilder, WorkflowContext, WorkflowResult};
222
223    // Coordination patterns
224    pub use super::contract_net::ContractNetManager;
225    pub use super::market_allocation::MarketAllocator;
226    pub use super::optimistic::OptimisticController;
227    pub use super::saga::SagaExecutor;
228    pub use super::wait_queue::WaitQueue;
229}