Skip to content

fix(agents): harden update_agent null-like args#3237

Open
Eilen6316 wants to merge 3 commits into
bytedance:mainfrom
Eilen6316:fix-issue-2906-update-agent-null-args-refresh
Open

fix(agents): harden update_agent null-like args#3237
Eilen6316 wants to merge 3 commits into
bytedance:mainfrom
Eilen6316:fix-issue-2906-update-agent-null-args-refresh

Conversation

@Eilen6316
Copy link
Copy Markdown
Contributor

Summary

Supersedes #2945.
Closes #2906.

This reopens the update_agent null-like argument fix on a fresh PR so it appears with the latest PR queue. The branch is based on the latest main.

Changes

  • Normalize literal null-like strings ("null", "none", "undefined") for optional update_agent fields so they behave like omitted fields.
  • Keep skills / tool_groups schema strict as arrays while accepting null-like placeholders as omitted through the production .invoke() path.
  • Mark update_agent validation failures as error ToolMessages.
  • Clarify the self-update prompt so models omit unchanged fields instead of passing null-like string placeholders.

Review follow-up from #2945

  • Removed redundant body-level text normalization.
  • Kept the Pydantic BeforeValidator as the single production normalization path.
  • Updated optional text and list-field tests to use .invoke() consistently.

Tests

  • uv run pytest tests/test_update_agent_tool.py tests/test_update_agent_e2e_user_isolation.py tests/test_lead_agent_prompt.py::test_build_self_update_section_present_for_custom_agent tests/test_tool_args_schema_no_pydantic_warning.py
  • uvx ruff check .
  • uvx ruff format --check .

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Hardens the update_agent builtin tool against LLM-provided “null-like” placeholder strings so optional fields behave as omitted, avoiding accidental persistence of "null"/"none"/"undefined" and reducing repeated tool-call failure loops during agent self-updates.

Changes:

  • Added Pydantic BeforeValidator-based normalization to treat null-like strings as None for optional text and optional list fields in update_agent.
  • Ensured update_agent returns error ToolMessages with status="error" for validation-style failures (e.g., no fields provided).
  • Updated the lead-agent self-update prompt and expanded tests to exercise the .invoke() path and null-like inputs.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
backend/packages/harness/deerflow/tools/builtins/update_agent_tool.py Adds null-like string normalization via validators and marks validation failures with ToolMessage(status="error").
backend/packages/harness/deerflow/agents/lead_agent/prompt.py Clarifies self-update instructions to omit unchanged fields and not pass null-like placeholders.
backend/tests/test_update_agent_tool.py Adds .invoke()-based regression tests for null-like placeholders and list-field strictness behavior.
backend/tests/test_lead_agent_prompt.py Verifies the self-update prompt includes guidance about null-like placeholder strings.

Comment on lines 100 to 106
Pass ``soul`` as the FULL replacement SOUL.md content — there is no patch
semantics, so always start from the current SOUL and apply your edits.

Pass ``skills=[]`` to disable all skills for this agent. Omit ``skills``
entirely to keep the existing whitelist.
entirely to keep the existing whitelist. Do not pass literal strings like
``"null"`` / ``"none"`` for unchanged fields; omit those fields instead.


if soul is None and description is None and skills is None and tool_groups is None and model is None:
return _err("No fields provided. Pass at least one of: soul, description, skills, tool_groups, model.")
return _err('No fields provided. Pass at least one of: soul, description, skills, tool_groups, model. Omit unchanged fields instead of passing null-like strings such as "null" or "none".')
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added undefined to both the docstring guidance and the validation error message so they match the null-like normalization behavior.

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.

[Bug]Agent 更新失败 Repeated tool calls exceeded the safety limit

3 participants