Skip to content

Commit 4703895

Browse files
authored
fix(a2a-middleware): ensure tool results are passed to orchestrator in subsequent runs (#465)
Bug: The A2A middleware was not including tool results in input.messages when triggering subsequent runs. This caused the orchestration agent to not see the tool results in its context, leading to repeated tool calls and broken multi-turn conversations with A2A agents. Fix: Collect all tool result messages and add them to input.messages before calling triggerNewRun(). This ensures the orchestrator receives the tool results in the conversation context for the next run. Also removes unused 'text' import from stream/consumers.
1 parent e94630b commit 4703895

File tree

1 file changed

+12
-1
lines changed
  • typescript-sdk/integrations/a2a-middleware/src

1 file changed

+12
-1
lines changed

typescript-sdk/integrations/a2a-middleware/src/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { AgentCard, SendMessageResponse, SendMessageSuccessResponse } from "@a2a
2020
import { Observable, Subscriber, tap } from "rxjs";
2121
import { createSystemPrompt, sendMessageToA2AAgentTool } from "./utils";
2222
import { randomUUID } from "crypto";
23-
import { text } from "stream/consumers";
2423

2524
export interface A2AAgentConfig extends AgentConfig {
2625
agentUrls: string[];
@@ -129,6 +128,9 @@ export class A2AMiddlewareAgent extends AbstractAgent {
129128
this.finishTextMessages(observer, pendingTextMessages);
130129

131130
if (pendingA2ACalls.size > 0) {
131+
// Array to collect all new tool result messages
132+
const newToolMessages: Message[] = [];
133+
132134
const callProms = [...pendingA2ACalls].map((toolCallId) => {
133135
const toolCallsFromMessages = this.messages
134136
.filter((message) => message.role === "assistant")
@@ -160,6 +162,9 @@ export class A2AMiddlewareAgent extends AbstractAgent {
160162
this.addMessage(newMessage);
161163
this.orchestrationAgent.addMessage(newMessage);
162164

165+
// Collect the message so we can add it to input.messages
166+
newToolMessages.push(newMessage);
167+
163168
const newEvent: ToolCallResultEvent = {
164169
type: EventType.TOOL_CALL_RESULT,
165170
toolCallId: toolCallId,
@@ -184,6 +189,12 @@ export class A2AMiddlewareAgent extends AbstractAgent {
184189
runId: input.runId,
185190
} as RunFinishedEvent);
186191

192+
// Add all tool result messages to input.messages BEFORE triggering new run
193+
// This ensures the orchestrator sees the tool results in its context
194+
newToolMessages.forEach((msg) => {
195+
input.messages.push(msg);
196+
});
197+
187198
this.triggerNewRun(observer, input, pendingA2ACalls, pendingTextMessages);
188199
});
189200
} else {

0 commit comments

Comments
 (0)