fix(agent): chat() surfaces error instead of KeyError on no-final_response result - #25
Merged
Conversation
…ponse result
AIAgent.chat() did `return result["final_response"]`, but several error/failure
return paths in agent.conversation_loop.run_conversation (API error after max
retries, billing/credits exhaustion, policy/toolguard halt, interrupts) return a
result dict with {messages, completed, api_calls, error, failed} and NO
'final_response' key. On those paths chat() raised `KeyError: 'final_response'`
instead of surfacing the error, so callers saw a traceback rather than the
actual failure (e.g. an API error).
Return `result.get("final_response") or result.get("error") or ""` so the error
message is surfaced and the call degrades gracefully. Also guard the CLI summary
printer with `result.get('final_response')`.
Adds tests for the error path, the happy path, and the empty case.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🔎 Lint report:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fork mirror of upstream PR NousResearch#34770 — lands the fix in the daily-driver fork ahead of upstream review.
What does this PR do?
AIAgent.chat()raisedKeyError: 'final_response'wheneverrun_conversationreturned via an error/failure path (API error after max retries, billing/credits exhaustion, policy/toolguard halt, interrupts). Those paths return a result dict with{messages, completed, api_calls, error, failed}and nofinal_responsekey, soreturn result["final_response"]crashed — masking the real error behind aKeyErrortraceback. This was observed in a non-interactivehermes -zoneshot drain (the launcher recorded theKeyErrorinstead of the underlying error).Type of Change
Changes Made
run_agent.py—AIAgent.chat()returnsresult.get("final_response") or result.get("error") or ""; guard the CLI summary printer withresult.get('final_response').tests/test_chat_final_response_resilience.py— regression tests (error path, happy path, empty case).How to Test
pytest tests/test_chat_final_response_resilience.py→ 3 passed.