98 lines
3.7 KiB
Markdown
98 lines
3.7 KiB
Markdown
# Agent Team Collaboration Framework Implementation
|
|
|
|
## Overview
|
|
Implemented a true agent team collaboration framework with shared blackboard, parallel execution, and automatic challenge rounds.
|
|
|
|
## Changes Made
|
|
|
|
### 1. `internal/agent/agent.go`
|
|
- Added `CanChallenge bool` field to `Config` struct
|
|
- Allows agents to participate in the challenge round
|
|
|
|
### 2. `internal/room/room.go`
|
|
- **Added imports**: `sync` for concurrent operations
|
|
- **New types**:
|
|
- `BoardEntry`: Represents a single entry on the shared board
|
|
- `SharedBoard`: Thread-safe shared blackboard with mutex protection
|
|
- `Add(author, content, typ)`: Add entries to the board
|
|
- `ToContext()`: Convert board to XML context for agents
|
|
|
|
- **New methods**:
|
|
- `runMembersParallel()`: Execute all assignments concurrently using goroutines and WaitGroup
|
|
- Each member sees the current board snapshot
|
|
- Results are added to the board as "draft" entries
|
|
- Emits streaming events for real-time UI updates
|
|
|
|
- `runChallengeRound()`: Automatic challenge phase after draft completion
|
|
- Only agents with `CanChallenge=true` participate
|
|
- Each challenger sees the full board
|
|
- Outputs `CHALLENGE:<concern>` or `AGREE`
|
|
- Challenge entries are added to the board
|
|
|
|
- **Refactored `HandleUserMessage()`**:
|
|
- Replaced sequential member execution with `runMembersParallel()`
|
|
- Added automatic `runChallengeRound()` after parallel execution
|
|
- Master receives complete board (drafts + challenges) for final review
|
|
- Board context is injected into master's feedback message
|
|
|
|
- **Updated `Event` struct**:
|
|
- Role field now supports "challenge" in addition to "master" and "member"
|
|
|
|
### 3. Agent Configuration Files
|
|
|
|
#### `agents/legal-team/合规专员/AGENT.md`
|
|
- Added `can_challenge: true`
|
|
|
|
#### `agents/legal-team/合同律师/AGENT.md`
|
|
- Added `can_challenge: true`
|
|
|
|
### 4. Agent System Prompts (SOUL.md)
|
|
|
|
#### `agents/legal-team/合规专员/SOUL.md`
|
|
- Added "质疑机制" (Challenge Mechanism) section
|
|
- Instructions to actively challenge when seeing `<team_board>`
|
|
- Format: `CHALLENGE:<specific compliance risk or suggestion>`
|
|
|
|
#### `agents/legal-team/合同律师/SOUL.md`
|
|
- Added "质疑与修订机制" (Challenge & Revision Mechanism) section
|
|
- Instructions to review other members' opinions
|
|
- Ability to challenge compliance officer's suggestions if conflicts exist
|
|
- Preparation to revise work when challenged
|
|
|
|
#### `agents/legal-team/法律总监/SOUL.md`
|
|
- Added "处理 CHALLENGE 的决策指令" (Decision Instructions for Handling CHALLENGE)
|
|
- Evaluate challenge validity
|
|
- Decide whether to request revisions or reassign tasks
|
|
- Document how challenges were addressed in final recommendations
|
|
|
|
## New Workflow
|
|
|
|
```
|
|
User Question
|
|
↓
|
|
Master Plans → ASSIGN:member1:task1 + ASSIGN:member2:task2
|
|
↓
|
|
[Parallel] Members execute simultaneously (each sees empty board initially)
|
|
↓
|
|
[Auto] Challenge Round: Members with CanChallenge=true review board
|
|
↓
|
|
Master sees complete board (drafts + challenges) → DONE or re-ASSIGN
|
|
```
|
|
|
|
## Key Features
|
|
|
|
1. **Parallel Execution**: Members work concurrently, not sequentially
|
|
2. **Shared Blackboard**: All members can see each other's work via `<team_board>`
|
|
3. **Automatic Challenge Round**: Triggered after parallel execution completes
|
|
4. **Thread-Safe**: Uses sync.RWMutex for concurrent board access
|
|
5. **Streaming Events**: Real-time UI updates with "challenge" role events
|
|
6. **Master Integration**: Board context fed back to master for informed decisions
|
|
|
|
## Verification
|
|
|
|
- ✅ Code compiles: `go build ./...`
|
|
- ✅ All imports added correctly
|
|
- ✅ Thread-safety ensured with sync primitives
|
|
- ✅ Event streaming maintained for UI
|
|
- ✅ Backward compatible with existing master/member roles
|