Skip to content

fix(agent): chat() surfaces error instead of KeyError on no-final_response result - #25

Merged
OmarB97 merged 1 commit into
mainfrom
fix/agent-chat-missing-final-response-fork-mirror
May 29, 2026
Merged

fix(agent): chat() surfaces error instead of KeyError on no-final_response result#25
OmarB97 merged 1 commit into
mainfrom
fix/agent-chat-missing-final-response-fork-mirror

Conversation

@OmarB97

@OmarB97 OmarB97 commented May 29, 2026

Copy link
Copy Markdown
Owner

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() raised KeyError: 'final_response' whenever run_conversation returned 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 no final_response key, so return result["final_response"] crashed — masking the real error behind a KeyError traceback. This was observed in a non-interactive hermes -z oneshot drain (the launcher recorded the KeyError instead of the underlying error).

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • run_agent.pyAIAgent.chat() returns result.get("final_response") or result.get("error") or ""; guard the CLI summary printer with result.get('final_response').
  • tests/test_chat_final_response_resilience.py — regression tests (error path, happy path, empty case).

How to Test

  1. pytest tests/test_chat_final_response_resilience.py → 3 passed.

…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>
@github-actions

Copy link
Copy Markdown

🔎 Lint report: fix/agent-chat-missing-final-response-fork-mirror 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: 9581 on HEAD, 9581 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5050 pre-existing issues carried over.

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

@OmarB97
OmarB97 merged commit dc5b7c9 into main May 29, 2026
18 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant