-
Notifications
You must be signed in to change notification settings - Fork 424
Description
Problem
When using kagent with Amazon Bedrock models, MCP servers (e.g. GitHub Copilot) may produce tool names containing dots, spaces, or other characters that violate Bedrock's API constraints.
Bedrock requires tool names to match [a-zA-Z0-9_-]+ with a minimum length of 1. Any name outside this pattern causes API errors like:
ValidationException: A tool name is invalid. Tool names can only contain letters, numbers, underscores, and hyphens
Root Cause
KAgentLiteLlm does not sanitize tool names before passing them to the Bedrock API, and does not sanitize tool names in the conversation history (function call parts) sent in subsequent requests.
Fix
Override generate_content_async in KAgentLiteLlm to:
- Sanitize tool names in the outgoing
LlmRequesthistory (function call parts incontents) - Sanitize tool names in incoming
LlmResponseparts
Invalid characters are replaced with _. Empty/completely invalid names fall back to unknown_tool_<idx>. A warning is logged whenever a name is sanitized, to aid debugging.
Affected File
python/packages/kagent-adk/src/kagent/adk/models/_litellm.py
Metadata
Metadata
Assignees
Labels
Type
Projects
Status