Skip to content

refactor(models): Refine MessageAgentThought SQLAlchemy typing#11

Open
tomerqodo wants to merge 2 commits intocursor_full_base_refactormodels_refine_messageagentthought_sqlalchemy_typing_pr11from
cursor_full_head_refactormodels_refine_messageagentthought_sqlalchemy_typing_pr11
Open

refactor(models): Refine MessageAgentThought SQLAlchemy typing#11
tomerqodo wants to merge 2 commits intocursor_full_base_refactormodels_refine_messageagentthought_sqlalchemy_typing_pr11from
cursor_full_head_refactormodels_refine_messageagentthought_sqlalchemy_typing_pr11

Conversation

@tomerqodo
Copy link
Copy Markdown

@tomerqodo tomerqodo commented Jan 25, 2026

Benchmark PR from agentic-review-benchmarks#11


Note

Modernizes agent thought persistence and improves history reconstruction.

  • Refactors MessageAgentThought to extend TypeBase with typed Mapped fields, insert_default/default_factory IDs, nullable defaults, and Decimal pricing with sensible server defaults
  • Introduces created_by_role/created_by typing on the model and uses CreatorUserRole enum in runner
  • Base agent runner: safer thought concatenation, uses Decimal prices, null-safe/defensive JSON parsing for tool_input/observation, and clearer tool name handling; constructs tool_calls/responses even with empty or malformed payloads
  • Adds lightweight AgentThoughtValidation model (pydantic) for pre-persist validation scaffold
  • Tests updated to rely on auto-generated IDs and align with new model behavior

Written by Cursor Bugbot for commit 5209691. Configure here.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

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

Choose a reason for hiding this comment

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

Tool response data replaced with tool input data

High Severity

The ToolPromptMessage content incorrectly uses tool_inputs instead of tool_responses. The code parses tool_responses from agent_thought.observation (lines 478-485) but then mistakenly uses tool_inputs.get(tool, ...) when constructing the response message. This causes agent history to contain tool inputs where tool outputs/responses should be, corrupting the conversation context for subsequent agent interactions.

Fix in Cursor Fix in Web

answer_unit_price=0,
answer_price_unit=0,
answer_unit_price=Decimal("0.001"),
answer_price_unit=Decimal(0),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Answer price unit values are swapped

Medium Severity

The answer_unit_price and answer_price_unit values appear to be swapped. The pattern for message_* fields shows message_unit_price=Decimal(0) and message_price_unit=Decimal("0.001"), but for answer_* it's reversed: answer_unit_price=Decimal("0.001") and answer_price_unit=Decimal(0). This is inconsistent with the model's default of Decimal("0.001") for answer_price_unit and could cause incorrect price calculations.

Fix in Cursor Fix in Web

Comment thread api/models/model.py
thought: Mapped[str | None] = mapped_column(LongText, nullable=True, default=None)
tool: Mapped[str | None] = mapped_column(LongText, nullable=True, default=None)
tool_labels_str: Mapped[str] = mapped_column(LongText, nullable=False, default=sa.text("'{}'"))
tool_meta_str: Mapped[str] = mapped_column(LongText, nullable=False, default=sa.text("'{}'"))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SQL text object used as Python dataclass default

Medium Severity

Changing MessageAgentThought from Base to TypeBase (which uses MappedAsDataclass) makes default=sa.text("'{}'") problematic. In dataclass mode, the default parameter provides the Python default value, so tool_labels_str and tool_meta_str would default to a TextClause object instead of the string "{}". The correct pattern (as used in other TypeBase classes like Account) is default="{}", server_default=sa.text("'{}'").

Fix in Cursor Fix in Web

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.

1 participant