-
Notifications
You must be signed in to change notification settings - Fork 0
Code Review Bench PR #27749 - refactor(models): Refine MessageAgentThought SQLAlchemy typing #11
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
base: base_pr_27749_20260125_2703
Are you sure you want to change the base?
Code Review Bench PR #27749 - refactor(models): Refine MessageAgentThought SQLAlchemy typing #11
Conversation
| tool_call_response.append( | ||
| ToolPromptMessage( | ||
| content=tool_responses.get(tool, agent_thought.observation), | ||
| content=str(tool_inputs.get(tool, agent_thought.observation)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚨 Bug: ToolPromptMessage uses tool_inputs instead of tool_responses
The ToolPromptMessage content was changed from tool_responses.get(tool, agent_thought.observation) to str(tool_inputs.get(tool, agent_thought.observation)). This means that when reconstructing conversation history, tool call responses will now contain tool inputs (the arguments sent to the tool) instead of the actual tool outputs/observations.
This corrupts the agent's conversation history, causing the LLM to see tool inputs where it should see tool results. This will lead to incorrect agent behavior in multi-turn conversations that reference prior tool usage.
The original code using tool_responses was correct. The variable tool_responses is parsed from agent_thought.observation (the tool's output), which is the right data to put in a ToolPromptMessage.
Was this helpful? React with 👍 / 👎
| content=str(tool_inputs.get(tool, agent_thought.observation)), | |
| content=str(tool_responses.get(tool, agent_thought.observation)), | |
- Apply suggested fix
| answer_token=0, | ||
| answer_unit_price=0, | ||
| answer_price_unit=0, | ||
| answer_unit_price=Decimal("0.001"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠️ Bug: Swapped answer_unit_price and answer_price_unit defaults
The initial values for answer_unit_price and answer_price_unit are swapped compared to their message_* counterparts:
message_unit_price=Decimal(0), # ✅ unit price starts at 0
message_price_unit=Decimal("0.001"), # ✅ price unit = per 1000 tokens
answer_unit_price=Decimal("0.001"), # ❌ should be Decimal(0)
answer_price_unit=Decimal(0), # ❌ should be Decimal("0.001")The semantics of *_unit_price (the cost per token) and *_price_unit (the denomination, e.g., per 1000 tokens) should be consistent between message and answer. The model's server_default for answer_price_unit is sa.text("0.001"), confirming that price_unit should be 0.001, not 0.
These values are later overwritten by actual LLM usage data (llm_usage.completion_unit_price / llm_usage.completion_price_unit), so the impact is limited to the brief window between creation and the update. However, if the update fails or is skipped, the swapped defaults would result in incorrect cost calculations.
Was this helpful? React with 👍 / 👎
| answer_unit_price=Decimal("0.001"), | |
| answer_unit_price=Decimal(0), | |
| answer_price_unit=Decimal("0.001"), | |
- Apply suggested fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Configure merge blocking · Maintainers can dismiss this review. Gitar never approves changes.
Code Review 🚫 Blocked 0 resolved / 5 findingsCritical bug: ToolPromptMessage content uses tool_inputs instead of tool_responses, corrupting agent conversation history. Also, answer price defaults are swapped and the new AgentThoughtValidation class is unused dead code. 🚨 Bug: ToolPromptMessage uses tool_inputs instead of tool_responses📄 api/core/agent/base_agent_runner.py:502 The This corrupts the agent's conversation history, causing the LLM to see tool inputs where it should see tool results. This will lead to incorrect agent behavior in multi-turn conversations that reference prior tool usage. The original code using Suggested fix
|
| Auto-apply | Compact |
|
|
Was this helpful? React with 👍 / 👎 | Gitar
Code Review Bench PR langgenius#27749 - refactor(models): Refine MessageAgentThought SQLAlchemy typing
Benchmark PR for Gitar evaluation
Original PR: agentic-review-benchmarks#11
refactor(models): Refine MessageAgentThought SQLAlchemy typing
Summary by Gitar
thoughtis None, and corrected wrong variable reference (tool_responses→tool_inputs) in tool response handlingMessageAgentThoughtfrom legacyBaseto modernTypeBase(MappedAsDataclass) with completeMapped[T]type annotations across 20+ columnsDecimaltype to prevent rounding errors in monetary calculationsCreatorUserRoleenum usage, Pydantic validation model (AgentThoughtValidation), and explicit null checks throughout agent runner logic