Skip to content

fix(agents): guard missing plan block and correct TaskRecorder default#268

Open
wustwyh wants to merge 1 commit into
TencentCloudADP:mainfrom
wustwyh:fix/issue-261-defensive-bugs
Open

fix(agents): guard missing plan block and correct TaskRecorder default#268
wustwyh wants to merge 1 commit into
TencentCloudADP:mainfrom
wustwyh:fix/issue-261-defensive-bugs

Conversation

@wustwyh

@wustwyh wustwyh commented Jun 24, 2026

Copy link
Copy Markdown

Summary

Fixes #261.

This PR addresses two small defensive-coding issues in utu/agents/.

Changes

1. ChainPlanner._parse no longer crashes on a missing <plan> block

File: utu/agents/orchestrator/chain.py

The <analysis> match was already guarded with if match else "", but the <plan> match immediately called .group(1) without checking for None. When the LLM returns malformed/truncated output that omits the plan block, this raised:

AttributeError: 'NoneType' object has no attribute 'group'

Now the plan match is guarded the same way as the analysis match. The existing assert len(tasks) > 0, "No tasks parsed from plan" still produces a clear error for the empty-plan case.

2. TaskRecorder.input default matches its annotation

File: utu/agents/common.py

TaskRecorder.input is annotated as str | list[TResponseInputItem], but its default_factory was dict, so a default instance got input = {}. This change aligns it with the other list-typed fields on the same dataclass by using default_factory=list.

Tests

Added tests/agents/test_issue_261.py covering:

  • Missing <plan> block raises AssertionError (not AttributeError).
  • Valid plan block is still parsed correctly.
  • TaskRecorder() defaults input to an empty list.

All three tests pass.

- ChainPlanner._parse now handles a missing <plan>...</plan> block
  gracefully instead of raising AttributeError on None.group().
- TaskRecorder.input default_factory changed from dict to list to match
  its str | list[TResponseInputItem] annotation.

Fixes TencentCloudADP#261.
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.

Two small bugs: ChainPlanner._parse crashes on missing <plan> block; TaskRecorder.input wrong default_factory

1 participant