[Bug]: sequential thinking tool publishes its five conditional fields as required, forcing a strict-mode model to fabricate them
What happened?
The sequentialthinking tool publishes five fields as required that its own description and its own validator treat as conditional, so a strict-mode model has no legal way to say "this thought revises nothing" — it has to invent values, and the tool then acts on them.
ToolParameter.required defaults to True (trae_agent/tools/base.py:63-71):
@dataclass
class ToolParameter:
"""Tool parameter definition."""
name: str
type: str | list[str]
description: str
enum: list[str] | None = None
items: dict[str, object] | None = None
required: bool = Trueand SequentialThinkingTool.get_parameters() (trae_agent/tools/sequential_thinking_tool.py:127-151) declares is_revision, revises_thought, branch_from_thought, branch_id and needs_more_thoughts without required=False — unlike the four fields above it, which spell required=True out. So all nine land in required for every provider, and for openai the five do not become nullable either, because get_input_schema() only adds "null" inside if not param.required (base.py:144-151).
Measured at main = e839e559ac61bdd0e057c375dd1dee391fee797d (trae_agent/tools/sequential_thinking_tool.py blob babe7334e17ef812e9bd063245ede8cc54dfeddd), no network and no API key:
--- openai ---
required: ['thought', 'next_thought_needed', 'thought_number', 'total_thoughts', 'is_revision', 'revises_thought', 'branch_from_thought', 'branch_id', 'needs_more_thoughts']
additionalProperties: False
is_revision: {'type': 'boolean', 'description': 'Whether this revises previous thinking'}
revises_thought: {'type': 'integer', 'description': 'Which thought is being reconsidered. Minimum value is 1.'}
branch_from_thought: {'type': 'integer', 'description': 'Branching point thought number. Minimum value is 1.'}
branch_id: {'type': 'string', 'description': 'Branch identifier'}
needs_more_thoughts: {'type': 'boolean', 'description': 'If more thoughts are needed'}
in required: yes
--- default provider ---
required: ['thought', 'next_thought_needed', 'thought_number', 'total_thoughts', 'is_revision', 'revises_thought', 'branch_from_thought', 'branch_id', 'needs_more_thoughts']
additionalProperties: <absent>
in required: yesNone of the five is ["boolean","null"] / ["integer","null"] / ["string","null"] — they are hard requirements with no escape hatch. That contradicts the tool's own documentation (sequential_thinking_tool.py:81-85):
- is_revision: A boolean indicating if this thought revises previous thinking
- revises_thought: If is_revision is true, which thought number is being reconsidered
- branch_from_thought: If branching, which thought number is the branching point
- branch_id: Identifier for the current branch (if any)
- needs_more_thoughts: If reaching end but realizing more thoughts needed"if any" and "If branching" are not required-field semantics, and _validate_thought_data() agrees — its own comments read # Validate minimum values, # Validate optional revision fields, # Handle optional fields with proper type checking, and each field is guarded by in arguments and arguments[...] is not None (lines 187-235).
The consequence is not cosmetic. For the first thought of an ordinary, non-revision, non-branching step, the schema leaves the model only one compliant move: fill the fields in. Sending exactly what the descriptions permit (is_revision=false, revises_thought=1, branch_from_thought=1, branch_id="main", needs_more_thoughts=false) makes the tool report a branch that was never intended:
forced-compliant error: None
forced-compliant output: [' "next_thought_needed": true,', ' "branches": [', ' "main"', ' ],', ' "thought_history_length": 1', '}']because execute() branches on truthiness at line 292 (if validated_input.branch_from_thought and validated_input.branch_id:). The two values the model fabricates to satisfy a schema are stored in self.branches and echoed back in the tool's response, so the model is told — correctly, from the tool's point of view — that it is now on a branch, and it keeps that belief for the rest of the reasoning chain.
And the values it should be allowed to send already work; they are simply illegal under the schema we generate:
all-null error: None
omitted error: None
revision-with-null-branch error: None
revision output tail: ... "branches": [], "thought_history_length": 1 ...What did you expect to happen?
The five conditional fields should be declared required=False, which is what the code already implements:
- for an ordinary provider they leave
required, matching "if any"; - for
openaithey stay inrequired(strict mode demands every property be listed —base.py:144-145) and become nullable, giving the model a legal way to say "not applicable"; nulland absent then both keep working exactly as they do today, because the reader already handles them.
The fix is 5 keyword arguments plus a comment. It changes no validation and no control flow.
Traceback
No traceback — every row above returns error: None. The wrong "branches" list is delivered as a success.
What is your system, Python, dependency version?
- OS: Windows 11 (10.0.26200)
- Python: 3.12.13
trae-agentatmain=e839e559ac61bdd0e057c375dd1dee391fee797d
Additional information that you believe is relevant to this bug
- This is the mirror image of #518 / #517, same root:
#175introduced the strict-mode required/nullable rule, and parameter declarations were never revisited against it. There the reader ignored anullthe schema offered; here the schema refuses to offer anullthe reader already handles. - This tool has no schema or behavior tests.
grep -ril 'sequential|thinking' tests/returns one file,tests/agent/test_trae_agent.py, and only for the tool name (lines 104 and 113,assertIn("sequentialthinking", tool_names)), so nothing could have caught this. - A wrong fix would be to drop the five from the OpenAI
requiredlist; that breaks strict mode, which requires every property to be listed. I am keeping that list intact and only adding"null"to the types, and I wrote a test for exactly that guard. - Deliberately not in scope:
execute()'s truthiness test at line 292 means an explicitly sentbranch_idstill opens a branch — correct behavior, and this issue is about the schema forcing that value, not about reinterpreting values a caller really sent. Also untouched:boolis a subclass ofint, sothought_number: truepasses theisinstance(..., int)check at line 168 and becomes1; that is a separate defect with its own fix shape. - Contention: 5 of the 87 open PRs touch this file (
#434,#435,#436,#437,#490). #434-#437 make one identical unrelated edit and mentionis_revision0 times; #490 (mine) adds lines insideThoughtDataat@@ -29,6 +29,19 @@. All five merge cleanly with my prepared head. - I'd like to take this and send a PR with regression tests.
Source: bytedance/trae-agent