TypeError in Agent Component with Anthropic Models after 1.4.2 Update
Bug Description
Bug Description Agent component crashes with TypeError: unsupported operand type(s) for +: 'NoneType' and 'int' when using Anthropic Claude models. This is a regression bug introduced in the May 25, 2025 automatic update. Primary Issue:
Agent component consistently crashes at conversation step 3 with NoneType + int error Error occurs specifically with Anthropic models (OpenAI works fine) Fresh/empty chat sessions trigger the bug
Secondary Issue:
Agent component automatically reverts to Claude 3.7 regardless of user configuration Claude 3.5 Sonnet and Claude 4.0 selections don't persist New Agent components immediately default back to 3.7
Technical Analysis: The error appears to originate from Anthropic API response parsing where usage.completion_tokens returns None instead of an integer: python# Suspected bug in Anthropic response handler: anthropic_response = get_anthropic_response() message_tokens = response.usage.completion_tokens # Returns None sometimes total_cost = message_tokens + previous_tokens # NoneType + int = CRASH
Reproduction
Reproduction
Create new Agent component in Langflow 1.4.2 Configure with Anthropic Claude 3.5 Sonnet model Enable internal memory (not Memory component) Start fresh chat session (empty state) Perform 3+ conversational exchanges Error occurs at step 3: TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
Additional reproduction scenario:
Create Agent component with Claude 3.5 or 4.0 selected Save and reload flow Component automatically reverts to Claude 3.7
Expected behavior
Expected behavior Environment
Langflow Version: 1.4.2 (latest) Deployment: Docker via Elestio hosting Docker Image: langflowai/langflow:latest Broken SHA: sha256:4c9e7ca3d3d2ef4cc68bc03bbcca709bd53e44fa1716c0ebd5e7839cc605b8e7 Working SHA: sha256:c2ccc1200e4eaaad24ddd2eaff7f3560db9e7a37c299d0d951b4df6ab46482eb LLM Provider: Anthropic Claude (claude-3-5-sonnet-20241022) Memory: Internal Langflow memory (not Memory component) Update Date: May 25, 2025, 01:00-01:03 UTC Platform: Linux Docker container
Additional Context Langfuse Trace Data: json{ "name": "Agent-xizRz", "ls_provider": "anthropic", "ls_model_name": "claude-3-5-sonnet-20241022", "ls_temperature": 0.25, "ls_max_tokens": 4096, "error": "unsupported operand type(s) for +: 'NoneType' and 'int'", "tags": ["seq:step:3"] } Impact:
Production multi-agent workflows completely broken Affects all Agent components using Anthropic models No viable workaround while maintaining Anthropic model quality OpenAI models work without issues (confirms Anthropic-specific bug)
Regression Confirmed: This worked perfectly in the previous version with identical configurations. The bug was introduced in the automatic Docker update on May 25, 2025.
Who can help?
No response
Operating System
Docker via Elestio hosting (langflowai/langflow:latest)
Langflow Version
1.4.2 (latest)
Python Version
None
Screenshot
No response
Flow File
No response
Here’s what I found regarding the TypeError and model reversion issues with Anthropic models in Langflow 1.4.2:
TypeError: NoneType + int with Anthropic Models
- The error occurs because the Anthropic API response sometimes returns
Noneforusage.completion_tokens. When the code tries to add this value to an integer (e.g.,total_cost = message_tokens + previous_tokens), it triggers a TypeError since you can't addNoneandint. - This issue is specific to Anthropic models; OpenAI models do not exhibit this behavior.
- The bug is a regression introduced in the May 25, 2025 update and did not exist in the previous version with the same configuration.
- The relevant code for Anthropic model handling is in the
AnthropicModelclass, which builds the model and processes responses. However, there is no explicit check forNonebefore performing arithmetic oncompletion_tokensin the code reviewed so far. This is likely the root cause of the crash. A typical fix would be to ensure thatcompletion_tokensis checked and defaulted to0(or another safe value) ifNonebefore any arithmetic operation is performed.
See AnthropicModel implementation
Model Selection Reverting to Claude 3.7
- The Agent component reverts to Claude 3.7 regardless of user configuration, and selections for Claude 3.5 Sonnet and Claude 4.0 do not persist.
- This suggests an issue with how model configuration is saved or loaded, possibly defaulting to the first or a fallback model in the list. The dropdown and input configuration for models is handled in the
AnthropicModelComponent, but there is no evidence in the available documentation or code comments explaining why this regression was introduced. - No relevant changes or discussions were found in the repository that directly address this model reversion issue.
Workarounds & Next Steps
- For the TypeError, a code-level workaround would be to add a check such as:
This would prevent the crash, but you may want to verify whymessage_tokens = response.usage.completion_tokens or 0 total_cost = message_tokens + previous_tokenscompletion_tokensisNonein the first place (possibly an upstream API change or edge case). - For the model reversion, review the logic that loads and persists the selected model in the Agent component. Ensure that the selected value is being saved and restored correctly, and that the dropdown options match the available models.
Repository Status
- No existing tickets, discussions, or documentation were found that directly address these issues.
- No specific changes in the May 25, 2025 update were identified as the cause, but the regression is confirmed by the version and SHA details you provided.
If you need more detailed guidance on where to add the check or how to debug the model persistence, let me know which files or components you want to focus on.
To continue talking to Dosu, mention @dosu-bot.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other
+1 same issue with vanilla uv environment on Ubuntu 24.04
Hi everyone!
With the introduction of our new Model Providers architecture, the Anthropic integration was fully reworked.
We haven't seen these issues reproduced in recent versions. I'm going to close this issue, but if you're still experiencing any problems with the Anthropic provider on a recent release, please open a new issue with your current version details so we can take a closer look.
Thanks for reporting this! 🙏