Architecture
File cache
Read deduplication
When agent A readssrc/index.ts, the content is cached. When agent B reads the same file:
Generation counter
Each cache entry has agen counter, incremented on every edit. Agents can check whether content has been updated by another agent since their last read.
Invalidation
invalidateFile(path):
- Resolve any waiting agents with
null(so they re-read from disk) - Clear the cache entry
- Expire any tool result cache entries that reference this path
Tool result cache
LRU cache with 200 entry limit. Keyed bytoolName:canonicalized-args:
read_code, grep, glob, navigate, analyze, web_search.
Cross-dispatch persistence
exportCaches() returns only completed file reads and the full tool result cache. Pending reads and edit state are not exported.
Edit mutex
Concurrent edits to the same file are serialized via promise chaining:Findings
Real-time peer communication without shared context windows.Report
Agent calls
report_finding("auth pattern", "Uses JWT with refresh tokens stored in HttpOnly cookies")Store
Finding appended to bus with
agentId, label, content, timestamp. Deduplication via findingKeys set.Drain
On each step,
prepareStep() calls drainUnseenFindings(agentId) — returns findings since last drain.Dispatch orchestration
Multi-agent dispatch
- Create AgentBus (import previous SharedCache if available)
- Register tasks on the bus
- Spawn agents with 100ms stagger (prevents thundering herd on file reads)
- Each agent runs independently with shared bus access
- Wait for all agents to complete (or hit timeout/budget)
- Aggregate results: each agent’s structured output + bus findings
- Apply
toModelOutput()compression - Export caches for next dispatch
- Return combined result to Forge
Single-agent optimization
If only one task is dispatched, the system skips bus coordination overhead and returns the result directly.Result compression
toModelOutput() compresses the dispatch result before the parent Forge sees it:
- Collapse consecutive blank lines
- Truncate individual lines (500 char limit, skip inside code blocks)
- Strip verbose reasoning that doesn’t add information