deerflow2/backend/packages/harness/deerflow
Octopus e4f896e90d
fix(todo-middleware): prevent premature agent exit with incomplete todos (#2135)
* fix(todo-middleware): prevent premature agent exit with incomplete todos

When plan mode is active (is_plan_mode=True), the agent occasionally
exits the loop and outputs a final response while todo items are still
incomplete. This happens because the routing edge only checks for
tool_calls, not todo completion state.

Fixes #2112

Add an after_model override to TodoMiddleware with
@hook_config(can_jump_to=["model"]). When the model produces a
response with no tool calls but there are still incomplete todos, the
middleware injects a todo_completion_reminder HumanMessage and returns
jump_to=model to force another model turn. A cap of 2 reminders
prevents infinite loops when the agent cannot make further progress.

Also adds _completion_reminder_count() helper and 14 new unit tests
covering all edge cases of the new after_model / aafter_model logic.

* Remove unnecessary blank line in test file

* Fix runtime argument annotation in before_model

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: octo-patch <octo-patch@github.com>
Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-04-14 11:11:26 +08:00
..
agents fix(todo-middleware): prevent premature agent exit with incomplete todos (#2135) 2026-04-14 11:11:26 +08:00
community fix(backend): fix uploads for mounted sandbox providers (#2199) 2026-04-14 10:44:31 +08:00
config fix: disable custom-agent management API by default (#2161) 2026-04-14 00:03:38 +08:00
guardrails feat(guardrails): add pre-tool-call authorization middleware with pluggable providers (#1240) 2026-03-23 18:07:33 +08:00
mcp feat(harness): integration ACP agent tool (#1344) 2026-03-26 14:20:18 +08:00
models feat(config): add when_thinking_disabled support for model configs (#1970) 2026-04-09 18:49:00 +08:00
reflection refactor: split backend into harness (deerflow.*) and app (app.*) (#1131) 2026-03-14 22:55:52 +08:00
runtime feat: implement full checkpoint rollback on user cancellation (#1867) 2026-04-09 17:56:36 +08:00
sandbox fix(backend): fix uploads for mounted sandbox providers (#2199) 2026-04-14 10:44:31 +08:00
skills Implement skill self-evolution and skill_manage flow (#1874) 2026-04-06 22:07:11 +08:00
subagents feat(subagents): allow model override per subagent in config.yaml (#2064) 2026-04-12 16:40:21 +08:00
tools fix(middleware): fix present_files thread id fallback (#2181) 2026-04-13 22:59:13 +08:00
tracing feat(tracing): add optional Langfuse support (#1717) 2026-04-02 13:06:10 +08:00
uploads feat(harness): integration ACP agent tool (#1344) 2026-03-26 14:20:18 +08:00
utils fix(uploads): handle split-bold headings and ** ** artefacts in extract_outline (#1838) 2026-04-04 14:25:08 +08:00
__init__.py refactor: split backend into harness (deerflow.*) and app (app.*) (#1131) 2026-03-14 22:55:52 +08:00
client.py fix(backend): stream DeerFlowClient AI text as token deltas (#1969) (#1974) 2026-04-10 18:16:38 +08:00