Fix intermittent UnboundLocalError for 'thinking' variable in ConversationalAgent.chat() - initialize thinking=None before conditional assignment to handle API responses missing message field

This commit is contained in:
shokollm
2026-04-14 03:34:36 +00:00
parent f705269e34
commit b1ddad0808

View File

@@ -894,6 +894,10 @@ class ConversationalAgent:
result = resp result = resp
# Initialize thinking to None to handle cases where API response
# doesn't have the expected message structure (intermittent issue)
thinking = None
if result.get("choices") and len(result.get("choices", [])) > 0: if result.get("choices") and len(result.get("choices", [])) > 0:
choice = result["choices"][0] choice = result["choices"][0]
if "message" in choice: if "message" in choice: