alanhuangyoo 86406cf197
fix(agents): make create_deerflow_agent's subagent limit, summarization and token_budget features take effect (#5488)
* fix(agents): keep the delegation ledger and summary in create_deerflow_agent graphs

The SDK factory chain had no DurableContextMiddleware. SubagentLimitMiddleware
counts a run's delegations from the ledger that middleware writes, so the
per-run subagent total never tripped, and DeerFlowSummarizationMiddleware
keeps compacted history in summary_text, which only that middleware puts back
into model requests, so a summarized factory graph lost its history.

Add it after ToolErrorHandlingMiddleware, ahead of summarization, where
make_lead_agent has it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(agents): make RuntimeFeatures(token_budget=True) enforce the budget

The factory built TokenBudgetMiddleware from TokenBudgetConfig(), whose
enabled flag defaults to False, and every hook returns early on it. A graph
created with token_budget=True had no warning, no hard stop and no
token_capped.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(agents): coalesce system messages in create_deerflow_agent graphs

DurableContextMiddleware injects its authority contract as a second
SystemMessage. The lead and subagent chains pair it with
SystemMessageCoalescingMiddleware because strict backends reject that; the
factory now does the same.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs: trim inherited harness guidance below chain limits

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-09-17 09:35:50 +08:00
..