Skip to content

feat(a2a): inbound agent replies use shared orchestration (tools + memory + citations)#25

Merged
hyhmrright merged 1 commit into
mainfrom
feat/a2a-agent-tools
Jun 14, 2026
Merged

feat(a2a): inbound agent replies use shared orchestration (tools + memory + citations)#25
hyhmrright merged 1 commit into
mainfrom
feat/a2a-agent-tools

Conversation

@hyhmrright

Copy link
Copy Markdown
Owner

What

Inbound A2A agent replies (processA2AMessage) previously used a bare runAgentLoop with 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

  • New packages/gateway/src/lib/agent-orchestrator.ts — extracted the tool loop from stream.ts into runAgentTurn({...,emit?}) -> {content, citations}. Streaming side effects are parameterized as optional emit callbacks (chat wires them to SSE writes; A2A omits emit and just collects the result).
  • stream.ts — deletes the local buildSystemPrompt/buildToolDefinitions/executeToolCall/runAgentWithTools; calls runAgentTurn with emit mapped back to writeSSE. SSE output is byte-equivalent (token/tool/tool_result/citation/done order, timing, payload shape unchanged). extractAndStore stays in the route.
  • a2a.ts processA2AMessage — loads ≤20 prior visible messages (peer_agentuser, own_agentassistant), resolves embedding/tavily/KBs against the agent owner's keys (not the requesting peer), calls runAgentTurn (no emit), persists citations_json, fire-and-forget extractAndStore.
  • Signing untouched — inbound verifyA2ASignature (HTTP signature + DID resolution + sender_mismatch guard) and outbound sendA2AMessage signing are byte-for-byte unchanged; this only touches reply generation after the signature is already verified and the message is persisted.

Contracts / safety

  • Contract feat: client UI polish, CI/CD, and Android signing #1 (A2A signature verification) — verified untouched; a2a-contract-reviewer ran COMPLIANT (signature chain byte-identical, cross-user key isolation correct).
  • No schema change, no migration (messages.citations_json and agent_memories already exist).
  • PII: console.error on recall/tool failure logs userId only, never message content.
  • Owner with no embedding/KB/tavily key → graceful plain-LLM degradation (no throw).

Tests

  • New: KB-citation main path (asserts citations_json non-empty) + plain-LLM degradation (asserts null citations, no throw).
  • Regression: existing a2a suite (incl. ask_user gate + resume) and stream/stream-memory integration green. Full gateway 219/219 pass locally.

Deploy

gateway only — already rebuilt and redeployed; /health → 200, unsigned A2A → 401.

🤖 Generated with Claude Code

…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>
@hyhmrright

Copy link
Copy Markdown
Owner Author

Code review

No 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 👎.

@hyhmrright hyhmrright merged commit 2e0802c into main Jun 14, 2026
1 check passed
@hyhmrright hyhmrright deleted the feat/a2a-agent-tools branch June 14, 2026 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant