Skip to content

bug(chat-api): agent narrates GenerateReport intent but fails to invoke the tool #306

@willvelida

Description

@willvelida

Summary

Claude agent intermittently narrates intent to call GenerateReport in text but ends its turn without actually invoking the tool function. The user sees a truncated response like "Let me fetch your food data... Got all 7 days! Now let me generate your report!" followed by nothing.

Evidence

Log Analytics query on 2026-04-20 at 10:54 UTC:

  • get_food_by_date_range MCP tool called successfully at 10:54:21 — returned 7 days of food data
  • Second Anthropic API call at 10:54:47 returned 200 (1244ms) — Claude responded with text only, no tool call
  • GenerateReport was never invoked — no log entry after the food data call
  • POST / AGUI request completed with 200 in 76.9 seconds — no timeout, no error
  • The GenerateReport function is correctly registered and was successfully called earlier the same day at 09:41 UTC

Root Cause (Suspected)

Claude is consuming most of its output token budget on the text narration ("Let me fetch... Got the data... Now let me generate...") and the large food data tool result in the conversation context, leaving insufficient tokens to emit the GenerateReport tool call JSON. The agent ends its turn with end_turn stop reason instead of tool_use.

Impact

  • Users cannot generate diet analysis or food-related reports when the food data payload is large (7 days × detailed nutrition records)
  • The issue is intermittent — GenerateReport worked at 09:41 UTC the same day

Potential Fixes

  1. Reduce food data payload size — paginate or summarize before passing to GenerateReport
  2. Increase max_tokens on the Anthropic API call for the main chat agent
  3. Adjust system prompt to discourage narration of tool calls (instruct the agent to call tools directly without announcing)
  4. Split the flow — have the agent call GenerateReport in a separate turn after receiving food data

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingchat-api

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions