Skip to content

perf(run_agent): accumulate length-continuation prefix via list+join#26237

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-e2fa3190
May 15, 2026
Merged

perf(run_agent): accumulate length-continuation prefix via list+join#26237
teknium1 merged 2 commits into
mainfrom
hermes/hermes-e2fa3190

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvages the run_conversation portion of #2717 (@InB4DevOps).

Summary

Replace truncated_response_prefix += content in the length-continuation retry path with list-append + "".join(). Functionally equivalent; matches the idiom used elsewhere in the codebase.

Changes

  • run_agent.py (3 sites in run_conversation): rename to truncated_response_parts: List[str], switch accumulation/use to list + join.
  • tests/run_agent/test_anthropic_truncation_continuation.py: update doc comment to match new variable name.
  • scripts/release.py: AUTHOR_MAP entries for InB4DevOps.

What was dropped from the original PR

The trajectory-builder refactor in _convert_to_trajectory_format() contained a silent regression — it replaced tool_response += "\n</tool_response>" with tool_response_parts.append("\n</think>"), which would have produced malformed trajectory XML on every save. Trajectory section dropped; only the truncated_response_prefix rename retained.

Validation

  • scripts/run_tests.sh tests/run_agent/test_anthropic_truncation_continuation.py → 7/7 pass (pre-existing tests, no regressions).
  • py_compile.compile("run_agent.py", doraise=True) clean.
  • grep truncated_response_prefix run_agent.py → 0 hits (all 6 references migrated).

Closes #2717.

InB4DevOps and others added 2 commits May 15, 2026 01:40
Replace O(n²) string concatenation of truncated_response_prefix in the
length-continuation retry loop with a list + ''.join(). Functionally
equivalent: same partial response on early return, same prepend on
final assembly. The legacy retry path is capped at 3 iterations, so
the practical wall-clock win is small, but the new idiom matches the
rest of the codebase and removes a needless repeated allocation.

Salvaged from PR #2717 (the run_conversation portion only — trajectory
refactor dropped because it silently rewrote </tool_response> to </think>).

Co-authored-by: Teknium <127238744+teknium1@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-e2fa3190 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 8258 on HEAD, 8258 on base (➖ 0)

🆕 New issues (2):

Rule Count
unresolved-attribute 1
invalid-argument-type 1
First entries
run_agent.py:15545: [unresolved-attribute] unresolved-attribute: Attribute `rstrip` is not defined on `None` in union `None | str | (Unknown & ~AlwaysFalsy)`
run_agent.py:15499: [invalid-argument-type] invalid-argument-type: Argument to function `len` is incorrect: Expected `Sized`, found `None | str | (Unknown & ~AlwaysFalsy)`

✅ Fixed issues (2):

Rule Count
unresolved-attribute 1
invalid-argument-type 1
First entries
run_agent.py:15545: [unresolved-attribute] unresolved-attribute: Attribute `rstrip` is not defined on `None` in union `None | str | Unknown`
run_agent.py:15499: [invalid-argument-type] invalid-argument-type: Argument to function `len` is incorrect: Expected `Sized`, found `None | str | Unknown`

Unchanged: 4310 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@teknium1 teknium1 merged commit 647cc0b into main May 15, 2026
15 of 17 checks passed
@teknium1 teknium1 deleted the hermes/hermes-e2fa3190 branch May 15, 2026 08:42
@alt-glitch alt-glitch added type/perf Performance improvement or optimization P3 Low — cosmetic, nice to have comp/agent Core agent loop, run_agent.py, prompt builder labels May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P3 Low — cosmetic, nice to have type/perf Performance improvement or optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants