Skip to content

fix(amp): preserve lowercase glob tool name#2766

Open
edlsh wants to merge 1 commit intorouter-for-me:devfrom
edlsh:fix/amp-glob-tool-casing
Open

fix(amp): preserve lowercase glob tool name#2766
edlsh wants to merge 1 commit intorouter-for-me:devfrom
edlsh:fix/amp-glob-tool-casing

Conversation

@edlsh
Copy link
Copy Markdown
Contributor

@edlsh edlsh commented Apr 13, 2026

Summary

  • normalize known Amp tool names in rewritten responses
  • preserve the lowercase glob name that Amp expects instead of rewriting it to Glob
  • add regression coverage for normalized and untouched tool names

Testing

  • go test ./internal/api/modules/amp
  • go test ./...
  • go build -o test-output ./cmd/server && rm test-output

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces tool name normalization to ensure compatibility with Amp's case-sensitive tool whitelist. It adds a mapping of canonical tool names and a function to update tool names in both streaming and non-streaming API responses. Unit tests were added to verify the normalization logic. Feedback was provided regarding an optimization in the streaming logic to reduce redundant JSON parsing when accessing content_block fields.

Comment on lines +158 to +160
if gjson.GetBytes(data, "content_block.type").String() == "tool_use" {
name := gjson.GetBytes(data, "content_block.name").String()
if canonical, ok := ampCanonicalToolNames[strings.ToLower(name)]; ok && name != canonical {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The code performs redundant JSON parsing by calling gjson.GetBytes twice for the same content_block object. It is more efficient to retrieve the content_block once and then use Get on the resulting gjson.Result to access its fields. This is particularly relevant in streaming mode where this logic is executed for every chunk.

	// Streaming: content_block.name in content_block_start events
	contentBlock := gjson.GetBytes(data, "content_block")
	if contentBlock.Get("type").String() == "tool_use" {
		name := contentBlock.Get("name").String()

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