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
LlmRequest history (function call parts in contents)
- Sanitize tool names in incoming
LlmResponse parts
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
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:Root Cause
KAgentLiteLlmdoes 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_asyncinKAgentLiteLlmto:LlmRequesthistory (function call parts incontents)LlmResponsepartsInvalid characters are replaced with
_. Empty/completely invalid names fall back tounknown_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