Skip to content

fix(agent): Prevent AttributeError for reasoning model config #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

dkqjrm
Copy link
Contributor

@dkqjrm dkqjrm commented Jun 5, 2025

Problem/Issue

Previously, accessing configurable.reasoning_model within the agent's graph logic, specifically in backend/src/agent/graph.py, could lead to an AttributeError if the reasoning_model field was not explicitly defined in the Configuration class. This could occur in scenarios where the configuration was initialized without this specific field being present or properly set.

The problematic line was:

# backend/src/agent/graph.py
reasoning_model = state.get("reasoning_model") or configurable.reasoning_model

Solution/Changes

This PR introduces the reasoning_model field to the backend/src/agent/configuration.py file's Configuration class.

# backend/src/agent/configuration.py
class Configuration(BaseModel):
    # ... existing code ...
    reasoning_model: str = Field(
        default="gemini-2.5-flash-preview-04-17",
        metadata={
            "description": "The name of the language model to use for the agent's reasoning."
        },
    )
    # ... existing code ...

By adding this field with a sensible default value ("gemini-2.5-flash-preview-04-17"), we ensure that configurable.reasoning_model always references a valid string value, thus preventing the potential AttributeError at the point of access in graph.py.

Benefits

  • Prevents AttributeError: Eliminates the potential runtime error when configurable.reasoning_model is accessed in backend/src/agent/graph.py.
  • Enhances Robustness: Makes the agent's configuration more robust by ensuring all expected model fields are defined.
  • Improves Clarity: Clearly defines the model used for agent reasoning within the central configuration.

How to test

No specific testing steps are required beyond standard unit/integration tests for the agent, as this is a configuration addition designed to prevent a potential error rather than fix a known, reproducible bug in existing functionality. The change ensures the expected attribute is always present.

Related Issue

Closes #34

Introduce 'reasoning_model' to the agent's Configuration class.
This change specifically addresses the potential AttributeError
that would occur when attempting to access 'configurable.reasoning_model'
if the field was not explicitly defined in the Configuration.

By adding this field with a default value, we ensure
'configurable.reasoning_model' always references a valid value,
enhancing the robustness of the agent's configuration.
@philschmid
Copy link
Contributor

Should be fixed with #109

@philschmid philschmid closed this Jun 18, 2025
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.

Prevent potential AttributeError when accessing reasoning_model
2 participants