fix: ChainPlanner._parse null-guard + TaskRecorder.input default_factory#262
Open
Ricardo-M-L wants to merge 2 commits intoTencentCloudADP:mainfrom
Open
Conversation
When the LLM output does not contain a <plan>[...]</plan> block, re.search returns None and calling .group(1) raises AttributeError, which is a confusing way to surface a parser/LLM-format problem. Raise ValueError with a clear message instead. The preceding <analysis> block (line 81-82) already uses `if match else ""` - this mirrors that defensive style. The subsequent assert on line 92 already fails hard when no tasks are parsed; this gives an equally clear error when the outer block is missing entirely. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
TaskRecorder.input is annotated as `str | list[TResponseInputItem]`,
but its default_factory is `dict`, so when a TaskRecorder is created
without an explicit input the runtime value is `{}` - neither a str
nor a list. Downstream code in simple_agent.py:264 and chain.py:32
uses the field as either a string message body or a list of input
items, both of which break when given an empty dict.
Other list-typed fields on the same dataclass (`trajectories`,
`raw_run_results`) already use the correct factory; this looks like
a copy-paste slip.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #261. Two small defensive-coding fixes in
utu/agents/:ChainPlanner._parse(utu/agents/orchestrator/chain.py) — guard the<plan>regex match so a malformed LLM output surfaces aValueErrorwith a clear message instead ofAttributeError: 'NoneType' object has no attribute 'group'. The preceding<analysis>match on line 82 already uses the same defensive style (if match else "").TaskRecorder.input(utu/agents/common.py) — usedefault_factory=listso the runtime default matches the declared typestr | list[TResponseInputItem]. Other list-typed fields on the same dataclass (trajectories,raw_run_results) already usedefault_factory=list;inputwas the outlier withdefault_factory=dict.Changes
Net: +3/-1 lines across two files, split into two commits so each fix is easy to bisect or cherry-pick.
Test plan
pre-commit run(ruff check + ruff format) passes locally🤖 Generated with Claude Code