Skip to main content

brainwires_agents/
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 brainwires-tool-system for ToolExecutor trait
36pub use brainwires_tool_system;
37
38// ── Agent loop hooks ─────────────────────────────────────────────────────────
39
40pub mod agent_hooks;
41
42// ── Agent runtime ────────────────────────────────────────────────────────────
43
44pub mod runtime;
45
46// ── Concrete agent implementation ────────────────────────────────────────────
47
48pub mod context;
49pub mod cycle_orchestrator;
50pub mod execution_graph;
51pub mod judge_agent;
52pub mod planner_agent;
53pub mod pool;
54pub mod system_prompts;
55pub mod task_agent;
56pub mod validator_agent;
57
58// ── Core components ──────────────────────────────────────────────────────────
59
60pub mod communication;
61pub mod confidence;
62pub mod file_locks;
63pub mod operation_tracker;
64pub mod resource_locks;
65pub mod task_manager;
66pub mod task_queue;
67pub mod validation_loop;
68
69// ── Coordination patterns ────────────────────────────────────────────────────
70
71pub mod contract_net;
72pub mod market_allocation;
73pub mod optimistic;
74pub mod saga;
75pub mod state_model;
76pub mod wait_queue;
77
78// ── Access control ─────────────────────────────────────────────────────────
79
80pub mod access_control;
81
82// ── Git coordination ───────────────────────────────────────────────────────
83
84pub mod git_coordination;
85
86// ── Plan execution ─────────────────────────────────────────────────────────
87
88pub mod plan_executor;
89
90// ── Task orchestration ────────────────────────────────────────────────────────
91
92pub mod task_orchestrator;
93
94// ── Workflow graph builder ───────────────────────────────────────────────────
95
96pub mod workflow;
97
98// ── Reasoning (merged from brainwires-reasoning) ────────────────────────────
99#[cfg(feature = "reasoning")]
100pub mod reasoning;
101
102// ── OpenTelemetry export ─────────────────────────────────────────────────────
103#[cfg(feature = "otel")]
104pub mod otel;
105
106// ── Evaluation framework (merged from brainwires-eval) ──────────────────────
107#[cfg(feature = "eval")]
108pub mod eval;
109
110// ── MDAP: Multi-Dimensional Adaptive Planning (merged from brainwires-mdap) ──
111#[cfg(feature = "mdap")]
112pub mod mdap;
113
114// ── SEAL: Self-Evolving Agentic Learning ─────────────────────────────────
115#[cfg(feature = "seal")]
116pub mod seal;
117
118// ── Analysis & validation ────────────────────────────────────────────────────
119
120pub mod resource_checker;
121pub mod validation_agent;
122#[cfg(feature = "native")]
123pub mod worktree;
124
125// ── Re-exports ───────────────────────────────────────────────────────────────
126
127// Agent loop hooks
128pub use agent_hooks::{
129    AgentLifecycleHooks, ConversationView, DefaultDelegationHandler, DelegationRequest,
130    DelegationResult, IterationContext, IterationDecision, ToolDecision,
131};
132
133// Agent runtime
134pub use runtime::{AgentExecutionResult, AgentRuntime, run_agent_loop};
135
136// Core components
137pub use communication::{
138    AgentMessage, CommunicationHub, ConflictInfo, ConflictType, GitOperationType,
139};
140pub use confidence::{
141    ConfidenceFactors, ResponseConfidence, extract_confidence, quick_confidence_check,
142};
143pub use file_locks::{FileLockManager, LockType};
144pub use operation_tracker::OperationTracker;
145pub use resource_checker::{ConflictCheck, ResourceChecker};
146pub use resource_locks::{
147    ResourceLockGuard, ResourceLockManager, ResourceScope, ResourceType as ResourceLockType,
148};
149pub use task_manager::{TaskManager, format_duration_secs};
150pub use task_queue::TaskQueue;
151pub use validation_loop::*;
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// Plan execution
165pub use plan_executor::{
166    ExecutionApprovalMode, ExecutionProgress, PlanExecutionConfig, PlanExecutionStatus,
167    PlanExecutorAgent,
168};
169
170// Task orchestration
171pub use task_orchestrator::{
172    FailurePolicy, OrchestrationResult, TaskOrchestrator, TaskOrchestratorConfig, TaskSpec,
173};
174
175// Workflow graph builder
176pub use workflow::{WorkflowBuilder, WorkflowContext, WorkflowResult};
177
178// Coordination patterns
179pub use contract_net::ContractNetManager;
180pub use market_allocation::MarketAllocator;
181pub use optimistic::OptimisticController;
182pub use saga::SagaExecutor;
183pub use state_model::{StateModelProposedOperation, StateSnapshot, ThreeStateModel};
184pub use wait_queue::WaitQueue;
185
186// Concrete agent types
187pub use brainwires_tool_system::{PreHookDecision, ToolPreHook};
188pub use context::AgentContext;
189pub use execution_graph::{ExecutionGraph, RunTelemetry, StepNode, ToolCallRecord};
190pub use pool::{AgentPool, AgentPoolStats};
191pub use system_prompts::{
192    judge_agent_prompt, planner_agent_prompt, reasoning_agent_prompt, simple_agent_prompt,
193};
194
195// SEAL re-exports
196#[cfg(feature = "seal")]
197pub use seal::{
198    CoreferenceResolver, DialogState, LearningCoordinator as SealLearningCoordinator, QueryCore,
199    QueryCoreExtractor, ReflectionModule, SealConfig, SealProcessingResult, SealProcessor,
200};
201
202// Cycle orchestration
203pub use cycle_orchestrator::{
204    CycleOrchestrator, CycleOrchestratorConfig, CycleOrchestratorResult, CycleRecord, MergeStrategy,
205};
206pub use judge_agent::{
207    JudgeAgent, JudgeAgentConfig, JudgeContext, JudgeVerdict, MergeStatus, WorkerResult,
208};
209pub use planner_agent::{
210    DynamicTaskPriority, DynamicTaskSpec, PlannerAgent, PlannerAgentConfig, PlannerOutput,
211    SubPlannerRequest,
212};
213pub use task_agent::{
214    FailureCategory, TaskAgent, TaskAgentConfig, TaskAgentResult, TaskAgentStatus, spawn_task_agent,
215};
216pub use validator_agent::{
217    ValidatorAgent, ValidatorAgentConfig, ValidatorAgentResult, ValidatorAgentStatus,
218    spawn_validator_agent,
219};
220
221/// Prelude module for convenient imports
222pub mod prelude {
223    // Agent loop hooks
224    pub use super::agent_hooks::{
225        AgentLifecycleHooks, ConversationView, DefaultDelegationHandler, DelegationRequest,
226        DelegationResult, IterationContext, IterationDecision, ToolDecision,
227    };
228
229    // Concrete agent types
230    pub use super::context::AgentContext;
231    pub use super::execution_graph::{ExecutionGraph, RunTelemetry, StepNode, ToolCallRecord};
232    pub use super::pool::{AgentPool, AgentPoolStats};
233    pub use super::task_agent::{
234        FailureCategory, TaskAgent, TaskAgentConfig, TaskAgentResult, TaskAgentStatus,
235    };
236    pub use super::validator_agent::{
237        ValidatorAgent, ValidatorAgentConfig, ValidatorAgentResult, ValidatorAgentStatus,
238    };
239    pub use brainwires_tool_system::{PreHookDecision, ToolPreHook};
240
241    // Core components
242    pub use super::communication::{AgentMessage, CommunicationHub, ConflictInfo, ConflictType};
243    pub use super::confidence::{ConfidenceFactors, ResponseConfidence};
244    pub use super::file_locks::{FileLockManager, LockType};
245    pub use super::operation_tracker::OperationTracker;
246    pub use super::resource_checker::{ConflictCheck, ResourceChecker};
247    pub use super::resource_locks::{ResourceLockManager, ResourceScope};
248    pub use super::state_model::{StateSnapshot, ThreeStateModel};
249    pub use super::task_manager::{TaskManager, format_duration_secs};
250    pub use super::task_queue::TaskQueue;
251    pub use super::validation_loop::{
252        ValidationCheck, ValidationConfig, ValidationIssue, ValidationResult,
253    };
254    #[cfg(feature = "native")]
255    pub use super::worktree::WorktreeManager;
256
257    // Access control
258    pub use super::access_control::{AccessControlManager, ContentionStrategy, LockPersistence};
259
260    // Git coordination
261    pub use super::git_coordination::{GitCoordinator, git_tools};
262
263    // Plan execution
264    pub use super::plan_executor::{ExecutionApprovalMode, PlanExecutionConfig, PlanExecutorAgent};
265
266    // Task orchestration
267    pub use super::task_orchestrator::{FailurePolicy, TaskOrchestrator, TaskOrchestratorConfig};
268
269    // Workflow graph builder
270    pub use super::workflow::{WorkflowBuilder, WorkflowContext, WorkflowResult};
271
272    // Coordination patterns
273    pub use super::contract_net::ContractNetManager;
274    pub use super::market_allocation::MarketAllocator;
275    pub use super::optimistic::OptimisticController;
276    pub use super::saga::SagaExecutor;
277    pub use super::wait_queue::WaitQueue;
278
279    // Cycle orchestration
280    pub use super::cycle_orchestrator::{
281        CycleOrchestrator, CycleOrchestratorConfig, CycleOrchestratorResult, MergeStrategy,
282    };
283    pub use super::judge_agent::{JudgeAgent, JudgeAgentConfig, JudgeVerdict, MergeStatus};
284    pub use super::planner_agent::{
285        DynamicTaskSpec, PlannerAgent, PlannerAgentConfig, PlannerOutput,
286    };
287}