mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
Merge pull request #2303 from NousResearch/hermes/hermes-31d7db3b
fix: remove synthetic error message injection, fix session resume after repeated failures
This commit is contained in:
commit
58b52dfb2f
5 changed files with 37 additions and 15 deletions
20
run_agent.py
20
run_agent.py
|
|
@ -6942,20 +6942,18 @@ class AIAgent:
|
|||
pending_handled = True
|
||||
break
|
||||
|
||||
if not pending_handled:
|
||||
# Error happened before tool processing (e.g. response parsing).
|
||||
# Choose role to avoid consecutive same-role messages.
|
||||
last_role = messages[-1].get("role") if messages else None
|
||||
err_role = "assistant" if last_role == "user" else "user"
|
||||
sys_err_msg = {
|
||||
"role": err_role,
|
||||
"content": f"[System error during processing: {error_msg}]",
|
||||
}
|
||||
messages.append(sys_err_msg)
|
||||
|
||||
# Non-tool errors don't need a synthetic message injected.
|
||||
# The error is already printed to the user (line above), and
|
||||
# the retry loop continues. Injecting a fake user/assistant
|
||||
# message pollutes history, burns tokens, and risks violating
|
||||
# role-alternation invariants.
|
||||
|
||||
# If we're near the limit, break to avoid infinite loops
|
||||
if api_call_count >= self.max_iterations - 1:
|
||||
final_response = f"I apologize, but I encountered repeated errors: {error_msg}"
|
||||
# Append as assistant so the history stays valid for
|
||||
# session resume (avoids consecutive user messages).
|
||||
messages.append({"role": "assistant", "content": final_response})
|
||||
break
|
||||
|
||||
if final_response is None and (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue