feat(a2a): inbound agent replies use shared orchestration (tools + memory + citations)#25
Merged
Merged
Conversation
…mory + citations)
Extract the web-chat tool loop into a shared lib (agent-orchestrator.ts) and
route both paths through it. Inbound A2A agent replies now match web chat:
knowledge-base search, web_search, long-term memory recall, KB citation
persistence, and post-reply memory extraction — resolved against the agent
owner's keys (not the requesting peer).
- New lib/agent-orchestrator.ts: runAgentTurn({...,emit?}) -> {content, citations};
streaming side effects parameterized as optional emit callbacks.
- stream.ts: drop local buildSystemPrompt/buildToolDefinitions/executeToolCall/
runAgentWithTools; call runAgentTurn with emit mapped back to writeSSE.
SSE output is byte-equivalent (token/tool/tool_result/citation/done unchanged).
- a2a.ts processA2AMessage: load <=20 visible history (peer_agent->user,
own_agent->assistant), resolve owner embedding/tavily/KBs, call runAgentTurn
(no emit), persist citations_json, fire-and-forget extractAndStore.
- Inbound verifyA2ASignature and outbound sendA2AMessage signing untouched.
- Tests: KB-citation main path + plain-LLM degradation; stream regression green.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Owner
Author
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
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.
What
Inbound A2A agent replies (
processA2AMessage) previously used a barerunAgentLoopwith empty history — no tools, no memory, no citations — making them strictly dumber than the web chat path. This routes both paths through one shared orchestration core so an agent answering a peer gets the same capabilities as its owner does in the web UI.Changes
packages/gateway/src/lib/agent-orchestrator.ts— extracted the tool loop fromstream.tsintorunAgentTurn({...,emit?}) -> {content, citations}. Streaming side effects are parameterized as optionalemitcallbacks (chat wires them to SSE writes; A2A omitsemitand just collects the result).stream.ts— deletes the localbuildSystemPrompt/buildToolDefinitions/executeToolCall/runAgentWithTools; callsrunAgentTurnwithemitmapped back towriteSSE. SSE output is byte-equivalent (token/tool/tool_result/citation/doneorder, timing, payload shape unchanged).extractAndStorestays in the route.a2a.tsprocessA2AMessage— loads ≤20 prior visible messages (peer_agent→user,own_agent→assistant), resolves embedding/tavily/KBs against the agent owner's keys (not the requesting peer), callsrunAgentTurn(noemit), persistscitations_json, fire-and-forgetextractAndStore.verifyA2ASignature(HTTP signature + DID resolution + sender_mismatch guard) and outboundsendA2AMessagesigning are byte-for-byte unchanged; this only touches reply generation after the signature is already verified and the message is persisted.Contracts / safety
messages.citations_jsonandagent_memoriesalready exist).console.erroron recall/tool failure logsuserIdonly, never message content.Tests
citations_jsonnon-empty) + plain-LLM degradation (asserts null citations, no throw).stream/stream-memoryintegration green. Full gateway 219/219 pass locally.Deploy
gateway only — already rebuilt and redeployed;
/health → 200, unsigned A2A→ 401.🤖 Generated with Claude Code