Skip to content

feat: auto-continue after max-iteration exhaustion#31418

Open
stefanpieter wants to merge 1 commit into
NousResearch:mainfrom
stefanpieter:local/hermes-auto-continue-max-turns
Open

feat: auto-continue after max-iteration exhaustion#31418
stefanpieter wants to merge 1 commit into
NousResearch:mainfrom
stefanpieter:local/hermes-auto-continue-max-turns

Conversation

@stefanpieter

Copy link
Copy Markdown

Summary

  • add config-gated auto-continue when a turn exhausts agent.max_turns
  • preserve truthful cumulative api_calls accounting across auto-continue cycles
  • mark synthetic continuation prompts clearly and skip them in CLI, gateway, and TUI retry/undo flows
  • document the new config in defaults/example config and add focused regressions

Motivation

Long autonomous workflows were stopping at the iteration/tool-turn ceiling only to require the user to say "continue". This patch lets Hermes continue boundedly when configured, while preserving the existing fallback summary path once the auto-continue cap is reached.

Validation

  • pytest tests/run_agent/test_run_agent.py tests/cli/test_cli_retry.py tests/gateway/test_retry_replacement.py tests/tui_gateway/test_protocol.py -k "auto_continue or retry" -q
  • pytest tests/run_agent/test_run_agent.py::TestHandleMaxIterations::test_auto_continue_helper_injects_prompt_and_resets_budget tests/run_agent/test_run_agent.py::TestRunConversation::test_auto_continue_on_iteration_exhaustion_resumes_without_summary -q
  • python -m py_compile agent/chat_completion_helpers.py agent/conversation_loop.py cli.py gateway/run.py tui_gateway/server.py hermes_cli/config.py run_agent.py

Independent review

  • bounded fresh-context review: PASS
  • verified the prior retry/undo regression and api_calls accounting regression are fixed

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery comp/tui Terminal UI (ui-tui/ + tui_gateway/) labels May 24, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Implements feature request #16004. Related: #18607 (emergency compression before max_iterations), #30709 (iteration_budget reset on cached agent reuse).

@alt-glitch alt-glitch added the comp/dashboard Web dashboard / control panel UI (dashboard/, landing) label Jun 26, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the bounded, config-gated continuation design and the retry/undo coverage. The feature remains relevant: current main still moves exhausted turns to the tool-less summary fallback in agent/turn_finalizer.py:82-97.

Problems

  • agent/chat_completion_helpers.py:127 appends the continuation as a user message. After a tool-calling iteration exhausts the budget, the tail can be tool → user. Current main explicitly repairs that malformed shape before requests (agent/conversation_loop.py:773-790), and documents strict-provider failures for it in agent/message_sanitization.py:282-311. Existing synthetic continuations preserve alternation by first appending an assistant turn (agent/conversation_loop.py:4927-4944).
  • The loop was refactored after this branch: budget initialization now lives in agent/turn_context.py:222-259, while exhaustion fallback and completion semantics live in agent/turn_finalizer.py:54-157. The counter reset needs to be reworked through those seams.

Suggested changes

  • Rebase the implementation concept onto the current continuation/finalization seams, preserving a valid assistant/tool/user sequence before the next API request, and test an exhausted tool-result tail.
  • Keep total versus per-cycle API-call accounting explicit through finalize_turn.

Automated hermes-sweeper review.

Comment thread agent/chat_completion_helpers.py Outdated
@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users labels Jul 13, 2026
@stefanpieter

Copy link
Copy Markdown
Author

Current-main remediation pushed at a2a9e60b79cc7eee867f51bf82bb36cef60d5cc6.

What changed:

  • Reimplemented bounded max-iteration continuation on the current turn-finalizer/conversation-loop architecture.
  • Opens a fresh provider-safe continuation boundary rather than appending user after a trailing tool result.
  • Preserves the original user target/session semantics across CLI, TUI, gateway, and resumed sessions; replacement prompts do not become the durable target.
  • Clears stale continuation state on completion/error/cleanup and enforces the configured continuation cap.
  • Exposes the current config through CLI/schema and Desktop controls.

Verification on the final tree merged onto current main (36f2a966c7f9f69987494b867c3dcf96b69a5766):

  • 951 Python focused/integration tests passed.
  • Desktop auto-continue tests: 2 passed; Desktop TypeScript typecheck passed.
  • Ruff and Python compilation passed.
  • Exact feature diff: 24 paths; SHA-256 f98e1109ce16daa84fe2af4da1e48f3d60c5e478c52268d852f350e9993775da.
  • Independent exact-diff review: PASS with no security or logic blockers.
  • PR head is live and mergeable.

@stefanpieter

Copy link
Copy Markdown
Author

Final current-main sync: head 1c6e894165ee62d3dceef21b008ee7a7e6b95a85 is merged onto upstream main at 0385e155444d36203a6ef431f635223d78490d34. The exact 24-path feature diff and SHA-256 remain unchanged (f98e1109ce16daa84fe2af4da1e48f3d60c5e478c52268d852f350e9993775da). Reverification on this final tree: 951 Python tests passed, 2 Desktop tests passed, Desktop typecheck passed, and Ruff/Python compilation passed.

@stefanpieter

Copy link
Copy Markdown
Author

@teknium1 current-main merge blocker is resolved on exact head d51a630553210effad4786a9cebf0235e45f1f98.

  • Merged upstream/main f4df260f26c93f15694698869f3ea8e965eea301 into local/hermes-auto-continue-max-turns with a normal fast-forward branch update (no history rewrite / no force-push).
  • Resolved the two conflict sites by preserving both behaviors:
    • conversation_loop -> finalize_turn(...) now passes _pending_verification_response_previewed, _defer_iteration_limit_fallback, and total_api_call_count together.
    • finalize_turn() keeps max-iteration continuation tool-tail closure and verification synthetic-nudge stripping before persistence checks continue.
  • Verification on the merged tree:
    • scripts/run_tests.sh tests/agent/test_turn_finalizer_iteration_limit_exit.py tests/agent/test_turn_finalizer_cleanup_guard.py tests/run_agent/test_verification_continuation_budget.py35 tests passed, 0 failed
    • python3 -m py_compile agent/conversation_loop.py agent/turn_finalizer.py → pass
    • git diff --check → pass
    • ruff check agent/conversation_loop.py agent/turn_finalizer.pyAll checks passed!
    • added-line security scan on the resolved hunks → no findings
    • fresh exact-scope independent review on the resolved conflict regions → PASS
  • Current live PR state: headRefOid=d51a630553210effad4786a9cebf0235e45f1f98, mergeable=MERGEABLE, checks: none reported on this branch.

Please re-review the current head if the branch still looks useful on top of current main.

@stefanpieter
stefanpieter force-pushed the local/hermes-auto-continue-max-turns branch from d51a630 to f015077 Compare July 22, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard comp/dashboard Web dashboard / control panel UI (dashboard/, landing) comp/gateway Gateway runner, session dispatch, delivery comp/tui Terminal UI (ui-tui/ + tui_gateway/) P3 Low — cosmetic, nice to have sweeper:blast-contained Sweeper blast radius: contained — one narrow path / opt-in / few users sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants