feat: Inject agent ID into prompts, SSE-based cw listen, all flags documented

- INTER_AGENT_COMMUNICATION constant → buildInterAgentCommunication(agentId) function
- Manager injects actual agent ID into prompt after DB record creation
- Agent ID hardcoded in cw listen/ask commands — no manifest.json indirection
- cw listen now uses onPendingConversation SSE subscription instead of polling
- CLI trpc-client upgraded with splitLink for subscription support
- All CLI flags (--agent-id, --from, --timeout, --poll-interval) documented in prompt
- conversation:created/answered added to ALL_EVENT_TYPES
This commit is contained in:
Lukas May
2026-02-10 15:53:01 +01:00
parent c2d665c24f
commit bfc1b422f9
14 changed files with 166 additions and 103 deletions

View File

@@ -142,28 +142,27 @@ Agent output is persisted to `agent_log_chunks` table and drives all live stream
Agents can communicate with each other via the `conversations` table, coordinated through CLI commands.
### Prompt Integration
`INTER_AGENT_COMMUNICATION` constant in `prompts/shared.ts` is appended to all 5 agent mode prompts. It instructs agents to:
`buildInterAgentCommunication(agentId)` function in `prompts/shared.ts` generates per-agent communication instructions. Called in `manager.ts` after agent record creation — the actual agent ID is injected directly into the prompt (no manifest.json indirection). Appended to the prompt regardless of mode. Instructions include:
1. Set up a background listener via temp-file redirect: `cw listen > $CW_LISTEN_FILE &`
2. Periodically check the temp file for incoming questions between work steps
3. Answer via `cw answer`, clear the file, restart the listener
4. Ask questions to peers via `cw ask --from <ID> --agent-id|--task-id|--phase-id`
4. Ask questions to peers via `cw ask --from <agentId> --agent-id|--task-id|--phase-id`
5. Kill the listener and clean up the temp file before writing `signal.json`
### Agent Identity
`manifest.json` now includes `agentId` and `agentName` fields. The manager passes these from the DB record after agent creation.
`manifest.json` includes `agentId` and `agentName` fields. The manager passes these from the DB record after agent creation. The agent ID is also injected directly into the prompt's communication instructions.
### CLI Commands
**`cw listen --agent-id <id> [--timeout <ms>] [--poll-interval <ms>]`**
- Polls `getPendingConversations`, prints first pending as JSON, exits with code 0
- `--timeout`: max wait in ms (default 0=forever)
- `--poll-interval`: polling frequency in ms (default 2000)
**`cw listen --agent-id <id>`**
- Subscribes to `onPendingConversation` SSE subscription, prints first pending as JSON, exits with code 0
- First yields any existing pending conversations from DB, then listens for `conversation:created` events
- Output: `{ conversationId, fromAgentId, question, phaseId?, taskId? }`
**`cw ask <question> --from <agentId> --agent-id|--task-id|--phase-id <target> [--timeout <ms>] [--poll-interval <ms>]`**
- Creates conversation, polls `getConversation` until answered, prints answer text to stdout
- Target resolution: `--agent-id` (direct), `--task-id` (find agent running task), `--phase-id` (find agent in phase)
- `--timeout` / `--poll-interval`: same defaults as listen
- `--timeout`: max wait in ms (default 0=forever), `--poll-interval`: polling frequency in ms (default 2000)
**`cw answer <answer> --conversation-id <id>`**
- Calls `answerConversation`, prints `{ conversationId, status: "answered" }`