mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-23 10:42:00 +00:00
fix(agent): complete final text on last turn
This commit is contained in:
parent
0f741cef28
commit
3972701424
2 changed files with 28 additions and 5 deletions
|
|
@ -122,10 +122,14 @@ def finalize_turn(
|
|||
)
|
||||
|
||||
# Determine if conversation completed successfully
|
||||
normal_text_response = str(_turn_exit_reason).startswith("text_response(")
|
||||
completed = (
|
||||
final_response is not None
|
||||
and api_call_count < agent.max_iterations
|
||||
and not failed
|
||||
and (
|
||||
api_call_count < agent.max_iterations
|
||||
or normal_text_response
|
||||
)
|
||||
)
|
||||
|
||||
# Post-loop cleanup must never lose the response. Trajectory save,
|
||||
|
|
|
|||
|
|
@ -100,7 +100,13 @@ class _StubAgent:
|
|||
pass
|
||||
|
||||
|
||||
def _run(agent):
|
||||
def _run(
|
||||
agent,
|
||||
*,
|
||||
final_response=None,
|
||||
api_call_count=3,
|
||||
turn_exit_reason="unknown",
|
||||
):
|
||||
messages = [
|
||||
{"role": "user", "content": "do a thing"},
|
||||
{
|
||||
|
|
@ -114,8 +120,8 @@ def _run(agent):
|
|||
]
|
||||
return finalize_turn(
|
||||
agent,
|
||||
final_response=None, # forces the max-iterations summary path
|
||||
api_call_count=3,
|
||||
final_response=final_response,
|
||||
api_call_count=api_call_count,
|
||||
interrupted=False,
|
||||
failed=False,
|
||||
messages=messages,
|
||||
|
|
@ -125,7 +131,7 @@ def _run(agent):
|
|||
user_message="do a thing",
|
||||
original_user_message="do a thing",
|
||||
_should_review_memory=False,
|
||||
_turn_exit_reason="unknown",
|
||||
_turn_exit_reason=turn_exit_reason,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -162,4 +168,17 @@ def test_clean_turn_has_no_cleanup_errors_key():
|
|||
agent = _StubAgent(raise_in=())
|
||||
result = _run(agent)
|
||||
assert result["final_response"] == "PARTIAL SUMMARY FROM MODEL"
|
||||
assert result["completed"] is False
|
||||
assert "cleanup_errors" not in result
|
||||
|
||||
|
||||
def test_text_response_on_last_allowed_call_is_completed():
|
||||
agent = _StubAgent(raise_in=())
|
||||
result = _run(
|
||||
agent,
|
||||
final_response="final report",
|
||||
api_call_count=agent.max_iterations,
|
||||
turn_exit_reason="text_response(finish_reason=stop)",
|
||||
)
|
||||
assert result["final_response"] == "final report"
|
||||
assert result["completed"] is True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue