Skip to content

refactor(models): Refine MessageAgentThought SQLAlchemy typing#60

Open
tomerqodo wants to merge 2 commits intocopilot_combined_20260121_qodo_grep_cursor_copilot_1_base_refactormodels_refine_messageagentthought_sqlalchemy_typing_pr425from
copilot_combined_20260121_qodo_grep_cursor_copilot_1_head_refactormodels_refine_messageagentthought_sqlalchemy_typing_pr425
Open

refactor(models): Refine MessageAgentThought SQLAlchemy typing#60
tomerqodo wants to merge 2 commits intocopilot_combined_20260121_qodo_grep_cursor_copilot_1_base_refactormodels_refine_messageagentthought_sqlalchemy_typing_pr425from
copilot_combined_20260121_qodo_grep_cursor_copilot_1_head_refactormodels_refine_messageagentthought_sqlalchemy_typing_pr425

Conversation

@tomerqodo
Copy link
Copy Markdown

Benchmark PR from qodo-benchmark#425

Copilot AI review requested due to automatic review settings January 21, 2026 18:58
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the MessageAgentThought model to improve SQLAlchemy typing by:

  • Migrating from Base to TypeBase (MappedAsDataclass)
  • Adding explicit Mapped type annotations to all fields
  • Using proper Decimal types for price-related fields
  • Adding init=False for auto-generated fields (id, created_at)
  • Improving field ordering with required fields first

Changes:

  • Enhanced type safety with explicit Mapped annotations for all model fields
  • Improved field defaults and nullable constraints consistency
  • Removed manual ID assignment from tests (now auto-generated)

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

File Description
api/models/model.py Migrated MessageAgentThought from Base to TypeBase with comprehensive Mapped type annotations and proper Decimal types
api/core/agent/base_agent_runner.py Updated agent thought creation to use Decimal types, added CreatorUserRole enum, improved null handling in save_agent_thought and organize_agent_history
api/tests/test_containers_integration_tests/services/test_agent_service.py Removed manual ID assignments from test fixtures to align with auto-generated IDs

tool_call_response.append(
ToolPromptMessage(
content=tool_responses.get(tool, agent_thought.observation),
content=str(tool_inputs.get(tool, agent_thought.observation)),
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The content for ToolPromptMessage should use tool_responses (the observation/output) instead of tool_inputs (the arguments). This will cause the wrong data to be passed as the tool response in the conversation history. The correct value should be obtained from tool_responses.get(tool, agent_thought.observation).

Suggested change
content=str(tool_inputs.get(tool, agent_thought.observation)),
content=str(tool_responses.get(tool, agent_thought.observation)),

Copilot uses AI. Check for mistakes.
Comment on lines +325 to +326
answer_unit_price=Decimal("0.001"),
answer_price_unit=Decimal(0),
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The values for answer_unit_price and answer_price_unit appear to be swapped. Based on the pattern in the model definition and the message_unit_price/message_price_unit assignments (lines 319-320), answer_unit_price should be Decimal(0) and answer_price_unit should be Decimal("0.001").

Suggested change
answer_unit_price=Decimal("0.001"),
answer_price_unit=Decimal(0),
answer_unit_price=Decimal(0),
answer_price_unit=Decimal("0.001"),

Copilot uses AI. Check for mistakes.
answer_unit_price=Decimal("0.001"),
answer_price_unit=Decimal(0),
tokens=0,
total_price=0,
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The total_price field should be set to Decimal(0) instead of the integer 0 to match the field's type annotation (Mapped[Decimal | None]) in the MessageAgentThought model. This ensures type consistency and prevents potential issues with database operations.

Suggested change
total_price=0,
total_price=Decimal(0),

Copilot uses AI. Check for mistakes.
Comment on lines +64 to +65
class Config:
extra = "allow" # Pydantic v1 syntax - should use ConfigDict(extra='forbid')
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The Pydantic configuration is using outdated v1 syntax. The codebase uses Pydantic v2 (as evidenced by ConfigDict usage throughout the project). The Config class should be replaced with model_config = ConfigDict(extra='allow') to align with the modern Pydantic v2 pattern used elsewhere in the codebase.

Copilot uses AI. Check for mistakes.
Comment on lines +52 to +66
class AgentThoughtValidation(BaseModel):
"""
Validation model for agent thought data before database persistence.
"""

message_id: str
position: int
thought: str | None = None
tool: str | None = None
tool_input: str | None = None
observation: str | None = None

class Config:
extra = "allow" # Pydantic v1 syntax - should use ConfigDict(extra='forbid')

Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The AgentThoughtValidation class is defined but never used in the codebase. If it's intended for future use, consider adding a TODO comment. Otherwise, it should be removed to avoid confusion and maintain code cleanliness.

Copilot uses AI. Check for mistakes.
observation_payload = agent_thought.observation
if observation_payload:
try:
tool_responses = json.loads(observation_payload)
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

This assignment to 'tool_responses' is unnecessary as it is redefined before this value is used.
This assignment to 'tool_responses' is unnecessary as it is redefined before this value is used.

Copilot uses AI. Check for mistakes.
Comment on lines +478 to +486
observation_payload = agent_thought.observation
if observation_payload:
try:
tool_responses = json.loads(observation_payload)
except Exception:
tool_responses = dict.fromkeys(tool_names, observation_payload)
else:
tool_responses = dict.fromkeys(tool_names, observation_payload)

Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

This assignment to 'tool_responses' is unnecessary as it is redefined before this value is used.
This assignment to 'tool_responses' is unnecessary as it is redefined before this value is used.

Suggested change
observation_payload = agent_thought.observation
if observation_payload:
try:
tool_responses = json.loads(observation_payload)
except Exception:
tool_responses = dict.fromkeys(tool_names, observation_payload)
else:
tool_responses = dict.fromkeys(tool_names, observation_payload)

Copilot uses AI. Check for mistakes.
Comment on lines +478 to +486
observation_payload = agent_thought.observation
if observation_payload:
try:
tool_responses = json.loads(observation_payload)
except Exception:
tool_responses = dict.fromkeys(tool_names, observation_payload)
else:
tool_responses = dict.fromkeys(tool_names, observation_payload)

Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

This assignment to 'tool_responses' is unnecessary as it is redefined before this value is used.
This assignment to 'tool_responses' is unnecessary as it is redefined before this value is used.

Suggested change
observation_payload = agent_thought.observation
if observation_payload:
try:
tool_responses = json.loads(observation_payload)
except Exception:
tool_responses = dict.fromkeys(tool_names, observation_payload)
else:
tool_responses = dict.fromkeys(tool_names, observation_payload)

Copilot uses AI. Check for mistakes.
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.

2 participants