2 Commits

Author SHA1 Message Date
Dan Caldr
19266a5eac
fix(middlewares): end length-capped turns cleanly, prevent todo re-engagement, annotate write_file budget (#5569)
* fix(middlewares): end length-capped turns cleanly, prevent todo re-engagement, annotate write_file budget

When a model hits its per-response output cap (finish_reason=length) while
emitting a write_file tool call, ModelLengthFinishReasonMiddleware suppresses
the truncated call and stamps model_length_termination. TodoMiddleware must
not re-engage (jump_to=model) on such a capped turn -- doing so re-emits the
same oversized call into the same cap, producing up to 3 futile responses
with junk fragments instead of a clean truncation notice.

Changes:
- TodoMiddleware.after_model: skip completion reminder jump when
  additional_kwargs.model_length_termination is present (follows the existing
  deerflow_error_fallback precedent).
- ModelLengthFinishReasonMiddleware: always append the length notice when
  tool calls were suppressed, even when partial text survived (collapses the
  visible-content ternary). Fixes a latent bug in append_visible_text that
  silently dropped string content.
- tools.get_available_tools: annotate write_file's model-visible description
  with the model's configured max_tokens output budget. Guarded extraction
  safely handles missing or non-numeric tokens, and the tool is cloned via
  model_copy to keep module-level singletons immutable across assemblies and
  prevent guidance leakage to unbudgeted models.
- release_policy_parameters() updated for both middlewares.
- AGENTS.md chain entries (#20, #35) and module docstrings updated within
  AG002 guidance limits.
- Tests: 8 new/focused unit tests + 1 updated pin + 1 real create_agent()
  integration test reproducing the incident (thread b1723286).

* fix(tools): use effective model cap for write_file guidance

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-09-20 19:28:21 +08:00
0xzkslr-ai
e89b128157
fix(runtime): harden model response recovery at provider boundaries (#5080)
* fix(models): preserve DeepSeek thinking tool history

* fix(runtime): harden model response recovery

* fix(runtime): tighten model response recovery

* fix(runtime): protect run-scoped retry state

* fix(runtime): complete model recovery review fixes

* fix(runtime): preserve empty-response diagnostics

* fix(runtime): strip native tool calls on length caps

* docs(middleware): fit recovery guidance within inherited size limit

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-09-18 07:29:34 +08:00