feat : multi agent collaboration#73
Open
Nixxx19 wants to merge 60 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an opt-in multi-agent collaboration subsystem to mofaclaw, introducing role-specialized agents, inter-agent messaging, workflow orchestration with approval gates, shared workspace artifacts, and CLI/tooling to operate the new features.
Changes:
- Introduces agent roles (architect/developer/reviewer/tester) with capability/tool constraints and a role registry.
- Adds inter-agent communication (protocol + message bus), team management, and a workflow engine with step context propagation and approvals.
- Adds workspace artifact management + persistence, plus new tools, CLI subcommands, docs, and examples.
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| examples/multi_agent_workflow_example.rs | Demonstrates team creation + workflow execution. |
| examples/multi_agent_team_example.rs | Demonstrates team creation and listing members. |
| examples/multi_agent_config.json | Sample JSON config for teams + workflows. |
| docs/MULTI_AGENT_COLLABORATION.md | End-user documentation for the multi-agent system and CLI/tools. |
| core/src/tools/workspace.rs | Adds workspace-related tools (create/get/list artifacts). |
| core/src/tools/workflow.rs | Adds workflow-related tools (start/status/list). |
| core/src/tools/team.rs | Adds team-related tools (create/list/status). |
| core/src/tools/multi_agent.rs | Helper to register the multi-agent tool suite into a registry. |
| core/src/tools/mod.rs | Exposes new tool modules and re-exports. |
| core/src/tools/agent_message.rs | Adds tools for agent-to-agent messaging + approval responses. |
| core/src/rbac/tests.rs | Formatting/refactor in RBAC tests (no functional change). |
| core/src/rbac/path_matcher.rs | Formatting/refactor in RBAC matcher tests (no functional change). |
| core/src/rbac/mod.rs | Reorders RBAC re-exports. |
| core/src/rbac/manager.rs | Formatting/refactor; minor readability changes. |
| core/src/lib.rs | Adjusts module ordering (adds/positions rbac). |
| core/src/channels/discord/mod.rs | Removes an extraneous blank line. |
| core/src/agent/roles/tester.rs | Implements Tester role + tests. |
| core/src/agent/roles/reviewer.rs | Implements Reviewer role + tests. |
| core/src/agent/roles/mod.rs | Adds roles module and RoleRegistry. |
| core/src/agent/roles/developer.rs | Implements Developer role + tests. |
| core/src/agent/roles/base.rs | Adds AgentRole trait + RoleCapabilities. |
| core/src/agent/roles/architect.rs | Implements Architect role + tests. |
| core/src/agent/mod.rs | Wires new collaboration/communication/roles modules and re-exports. |
| core/src/agent/loop_.rs | Adds AgentLoop::with_agent_and_tools_custom for per-role overrides. |
| core/src/agent/communication/protocol.rs | Defines AgentId, AgentMessage, and message enums + tests. |
| core/src/agent/communication/mod.rs | Exposes communication submodules and re-exports types. |
| core/src/agent/communication/bus.rs | Implements AgentMessageBus with broadcast-based delivery + tests. |
| core/src/agent/collaboration/workspace.rs | Implements SharedWorkspace artifacts, versioning, persistence, conflict handling + tests. |
| core/src/agent/collaboration/workflow.rs | Implements WorkflowEngine, workflow/step/result structs, built-in workflows + tests. |
| core/src/agent/collaboration/tests.rs | Adds collaboration integration tests (some ignored). |
| core/src/agent/collaboration/team.rs | Implements TeamManager, AgentTeam, member creation with role-specific tool filtering + tests. |
| core/src/agent/collaboration/mod.rs | Exposes collaboration modules and re-exports types. |
| core/Cargo.toml | Registers new examples for the core crate. |
| cli/src/main.rs | Adds CLI subcommands for team/workflow/workspace operations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b3faf62 to
2c2c223
Compare
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
Implements a complete multi-agent collaboration framework for mofaClaw — specialized agents that work together through structured communication, workflow orchestration, and shared artifact management — and makes it accessible through natural language chat via a consolidated skill.
Previously, subagents had no coordination primitives, no shared state, and no role specialization. This PR closes all of those gaps and wires the system into the main agent loop so users can trigger multi-agent workflows conversationally.
Related Issues
Closes #58
Context & Pain Points Addressed
Before this PR
start_workflowwould not return until the entire workflow completedAfter this PR
manifest.jsonstart_workflowreturns aworkflow_idimmediatelylist_teamswith "recreate to use" guidanceArchitecture
Current Implementation
flowchart TD User[User Message] --> AgentLoop[Main AgentLoop] AgentLoop --> SkillsManager[SkillsManager] SkillsManager --> MultiAgentSkill[multi-agent Skill] MultiAgentSkill --> AgentLoop AgentLoop --> ToolRegistry[ToolRegistry] ToolRegistry --> MultiAgentTools[Multi-Agent Tools] MultiAgentTools --> TeamManager[TeamManager] MultiAgentTools --> WorkflowEngine[WorkflowEngine Controller] MultiAgentTools --> SharedWorkspace[SharedWorkspace] TeamManager --> AgentTeam[AgentTeam] WorkflowEngine -->|process_direct| DevAgent[Developer Agent] WorkflowEngine -->|process_direct| RevAgent[Reviewer Agent] WorkflowEngine -->|process_direct| ArchAgent[Architect Agent] style MultiAgentTools fill:#4a90e2,color:#fff style MultiAgentSkill fill:#f39c12,color:#fff style WorkflowEngine fill:#e74c3c,color:#fff style TeamManager fill:#9b59b6,color:#fffThe proposed event-driven architecture (agents with persistent event loops,
WorkflowEngineas coordinator,AgentMessageBusas hub) is documented indocs/MULTI_AGENT_ARCHITECTURE.mdand deferred to a future PR when a concrete use case requires it.Changes
Skill & Hub Integration (
skills/)code-review/,design-review/,team-task/into oneskills/multi-agent/SKILL.mdskills/multi-agent/manifest.json— ClawHub-compatible permissions manifest declaring all 12 multi-agent tools; no filesystem or network access neededskills/README.mdupdatedNon-Blocking Workflow Execution (
core/src/agent/collaboration/workflow.rs)WorkflowEngine::start_async()— spawns workflow in a backgroundtokio::task, returns uniqueworkflow_idimmediately (format:code_review-{uuid8})StartWorkflowToolnow returns{workflow_id, status: "started", message: "Poll get_workflow_status..."}instead of blockingGetWorkflowStatusToolreturns step results with output previews for pollingParallel Step Execution
compute_execution_layers()— topological sort grouping independent steps into concurrent layersjoin_all()— e.g. code review + test writing run in parallel after implementation completesPersistence
serdeSerialize/Deserializeon all types;save_workflow_state()after every transition;load_persisted_workflows()on startup (staleRunning/WaitingApproval→Failed)TeamSnapshot(id, name, roles, member_count, created_at) saved to{data_dir}/teams/{id}.json;TeamManager::with_persistence()async constructor;list_teams_detailed()returns active + inactive with statusGetTeamStatusToolfalls back to snapshot for inactive teams with "recreate to use" messageTeamManagerandWorkflowEngineusewith_persistence()in CLI entry pointsOrchestrator Artifact Access
register_multi_agent_tools()now always registersCreateArtifactTool, using a syntheticAgentId("main", "orchestrator", "main")when noagent_idis provided — previously the tool was silently skipped for the main agentCLI Integration (
cli/src/main.rs)command_gateway()andcommand_agent()now instantiateTeamManager::with_persistence(),WorkflowEngine::with_persistence(),SharedWorkspace, and callregister_multi_agent_tools()— multi-agent tools available in all agent modes without any configAgent Roles (
core/src/agent/roles/)AgentRoletrait:name(),description(),system_prompt(),allowed_tools(),capabilities()RoleCapabilities:can_read_files,can_write_files,can_execute_commands,can_spawn_subagents,max_iterations,temperatureArchitectRole,DeveloperRole,ReviewerRole,TesterRoleRoleRegistryfor lookupInter-Agent Communication (
core/src/agent/communication/)AgentId(team_id + role + instance_id), serialized as"team:role:instance"AgentMessagevariants:Request,Response,Broadcast,ArtifactUpdateRequestType:AskQuestion,RequestReview,RequestImplementation,RequestTesting,ShareFinding,RequestApproval,RequestInformationAgentMessageBus— tokio broadcast channel with topic subscriptions and per-agent routingShared Workspace (
core/src/agent/collaboration/workspace.rs)Artifactwith versioning, author tracking,ArtifactType(CodeFile,DesignDoc,TestFile,ReviewComment)create_artifact(),update_artifact()(auto-increments version),get_artifact(),list_artifacts(){base_dir}/{team_id}/artifacts.jsoncan_write_files/can_read_filesrole capabilitiesLastWriteWins,ManualMerge,AutomaticMergeTools (
core/src/tools/)team.rs—CreateTeamTool,ListTeamsTool(detailed with active/inactive),GetTeamStatusTool(snapshot fallback)workflow.rs—StartWorkflowTool(non-blocking),GetWorkflowStatusTool,ListWorkflowsToolworkspace.rs—CreateArtifactTool,GetArtifactTool,ListArtifactsToolagent_message.rs—SendAgentMessageTool,BroadcastToTeamTool,RespondToApprovalToolmulti_agent.rs—register_multi_agent_tools()wires everything with a single callDocumentation
docs/MULTI_AGENT_ARCHITECTURE.md— current vs proposed architecture with mermaid diagrams, 4-phase migration plan, use case trigger tabledocs/MULTI_AGENT_INTEGRATION_PLAN.md— implementation plan with current + proposed architecture diagramsHow it was Tested
New Tests Added
test_start_async_is_non_blocking— verifiesstart_asyncreturns in <500mstest_start_async_unique_ids— 3 runs produce 3 distinct workflow IDstest_team_snapshot_persistence— twoTeamManagerinstances over sameTempDir, verifies persistence round-triptest_workflow_serialization— serde round-trip for fullWorkflowstructtest_compute_execution_layers_code_review— verifies 3 layers, layer 1 has 2 parallel stepstest_compute_execution_layers_design— verifies 3 sequential layersExamples
examples/multi_agent_team_example.rs— creates a team, assigns roles, member access patternsexamples/multi_agent_workflow_example.rs— code review workflow end-to-end, context propagationexamples/multi_agent_config.json— sample config for a three-agent teamBreaking Changes
None — all existing single-agent workflows, tool registries, and channel integrations unaffected
Checklist
Code Quality
cargo fmtcleancargo clippy— zero warnings in new codeTesting
cargo build --examplespassesDocumentation
docs/MULTI_AGENT_ARCHITECTURE.md)docs/MULTI_AGENT_INTEGRATION_PLAN.md)PR Hygiene