Skip to content

fix(supervisor): add useToolHandler to fix streaming with SupervisorAgent#444

Open
guoyangzhen wants to merge 3 commits into2FastLabs:mainfrom
guoyangzhen:fix/supervisor-streaming-tool-handler
Open

fix(supervisor): add useToolHandler to fix streaming with SupervisorAgent#444
guoyangzhen wants to merge 3 commits into2FastLabs:mainfrom
guoyangzhen:fix/supervisor-streaming-tool-handler

Conversation

@guoyangzhen
Copy link
Copy Markdown

Problem

SupervisorAgent with streaming enabled crashes with:

Error: this.toolConfig.useToolHandler is not a function

Reported in #252. When SupervisorAgent sets up the lead agent's toolConfig in configureSupervisorTools(), it only provides tool and toolMaxRecursions — missing useToolHandler. When the lead agent (BedrockLLMAgent or AnthropicAgent) processes a streaming response containing tool_use blocks, the fallback handler references this.toolConfig.useToolHandler which is undefined.

Root Cause

The fallback handler in both BedrockLLMAgent and AnthropicAgent (streaming and non-streaming paths) has a bug:

const toolHandler = this.toolConfig.useToolHandler ?? (async (response, conversationHistory) => {
  if (this.isAgentTools(tools)) {
    return tools.toolHandler(...);
  }
  return this.toolConfig.useToolHandler(response, conversationHistory);  // ← undefined!
});

When useToolHandler is not set AND the instanceof AgentTools check fails (can happen with different module instances), the code calls undefined.

Fix

PrimarysupervisorAgent.ts: Add proper useToolHandler to the toolConfig that delegates to AgentTools.toolHandler with the required getter methods. This ensures correct tool dispatch for both streaming and non-streaming.

SecondarybedrockLLMAgent.ts and anthropicAgent.ts: Replace the dangling this.toolConfig.useToolHandler reference in the fallback handler with a clear error message.

Testing

  1. Create a SupervisorAgent with BedrockLLMAgent lead agent + streaming enabled
  2. Send a query that triggers tool use
  3. Verify streaming completes without crash and tool results are properly dispatched to team agents

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