You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Agent has error calling tool even if is_enabled = True #2232
I'm using the is_enabled param within the @function_tool decorator to control the tools that are exposed to a user at runtime based on the callable function below to control the value for is_enabled
@NateMoneyLion This happens because the model asks to call fetch_latest_credit_report, but at that time the tool is not registered on the agent due to is_enabled=False. Since the agent no longer has this tool, the SDK raises agents.exceptions.ModelBehaviorError.
In fact, I can’t reproduce this issue with OpenAI models. If the function schema is not provided, OpenAI models usually do not try to call that function.
So this looks like a model behavior issue. The model seems to remember that the function appeared earlier in the conversation and assumes it is always available, even when it is no longer exposed.
You can try switching to a different model, or adjusting your prompt to make the model avoid calling functions that may not exist.
One thing to note, I did a bit of logging and saw that the fetch _latest_credit_report tool was available
Available tools: ['fetch_latest_credit_report', ...]
However, in the error log, it outputs it as
agents.exceptions.ModelBehaviorError: Tool fetch_latest_credit_report" /> not found in agent Credit Monitoring Agent
Note that the tool name in the error is fetch_latest_credit_report " />. I don't know if this is how the error log should look or if there is a corruption in name-parsing
I've been testing out Claude Sonnet (jumping between 4 and 4.5) so I don't know if this is an edge case.
Oddly, after trying a lot more, oddly, the tool error comes and goes even with the same query.
@NateMoneyLion If you’re using Claude Sonnet, it shouldn’t return a malformed tool name. If you can share a minimal reproducible code, I can help take another look.
Activity
[-]Agent calls tool even if is_enabled = False[/-][+]Agent has error calling tool even if is_enabled = True[/+]ihower commentedon Dec 24, 2025
@NateMoneyLion This happens because the model asks to call
fetch_latest_credit_report, but at that time the tool is not registered on the agent due tois_enabled=False. Since the agent no longer has this tool, the SDK raisesagents.exceptions.ModelBehaviorError.In fact, I can’t reproduce this issue with OpenAI models. If the function schema is not provided, OpenAI models usually do not try to call that function.
However, other models behave differently. I can reproduce the same issue with Gemini 2.5 Pro: https://gist.github.com/ihower/39435370e337c03c0ef92dffd42f9af4
So this looks like a model behavior issue. The model seems to remember that the function appeared earlier in the conversation and assumes it is always available, even when it is no longer exposed.
You can try switching to a different model, or adjusting your prompt to make the model avoid calling functions that may not exist.
NateMoneyLion commentedon Dec 26, 2025
oooh, I'll have a try then.
One thing to note, I did a bit of logging and saw that the
fetch _latest_credit_reporttool was availableHowever, in the error log, it outputs it as
Note that the tool name in the error is
fetch_latest_credit_report " />. I don't know if this is how the error log should look or if there is a corruption in name-parsingihower commentedon Dec 26, 2025
@NateMoneyLion The SDK does not change the tool name.
This is likely because the model you are using does not support function calling very well, so it returned this incorrect name.
NateMoneyLion commentedon Dec 26, 2025
I've been testing out Claude Sonnet (jumping between 4 and 4.5) so I don't know if this is an edge case.
Oddly, after trying a lot more, oddly, the tool error comes and goes even with the same query.
I'll try with the OpenAI models.
ihower commentedon Dec 26, 2025
@NateMoneyLion If you’re using Claude Sonnet, it shouldn’t return a malformed tool name. If you can share a minimal reproducible code, I can help take another look.
NateMoneyLion commentedon Dec 29, 2025
@ihower ironically, it is the code that you've tested with for Gemini. Let me just paste my exact implementation
I've omitted any message history saving logic at the moment
ihower commentedon Jan 5, 2026
@NateMoneyLion One thing I noticed that may be related: you are actually using
OpenAIChatCompletionsModel, notLiteLLMModel.OpenAIChatCompletionsModeluses Claude’s Chat Completions API (https://platform.claude.com/docs/en/api/openai-sdk). And this API does not return thought data. Because of that, the model cannot receive reasoning tokens during the same turn of function calling. This may make function calling behave less reliably.NateMoneyLion commentedon Jan 6, 2026
ahhh, that didn't come across my mind. Thanks for the heads up, I'll apply that change too.
github-actions commentedon Jan 14, 2026
This issue is stale because it has been open for 7 days with no activity.
github-actions commentedon Jan 18, 2026
This issue was closed because it has been inactive for 3 days since being marked as stale.