fix: use reasoning content as response when model only produces think blocks
Local models (especially Qwen 3.5) sometimes wrap their entire response inside <think> tags, leaving actual content empty. Previously this caused 3 retries and then an error, wasting tokens and failing the request. Now when retries are exhausted and reasoning_text contains the response, it is used as final_response instead of returning an error. The user sees the actual answer instead of "Model generated only think blocks."
This commit is contained in:
parent
ec5fdb8b92
commit
746abf5e28
1 changed files with 17 additions and 3 deletions
20
run_agent.py
20
run_agent.py
|
|
@ -6532,7 +6532,21 @@ class AIAgent:
|
||||||
self._response_was_previewed = True
|
self._response_was_previewed = True
|
||||||
break
|
break
|
||||||
|
|
||||||
# No fallback -- append the empty message as-is
|
# No fallback -- if reasoning_text exists, the model put its
|
||||||
|
# entire response inside <think> tags; use that as the content.
|
||||||
|
if reasoning_text:
|
||||||
|
self._vprint(f"{self.log_prefix}Using reasoning as response content (model wrapped entire response in think tags).", force=True)
|
||||||
|
final_response = reasoning_text
|
||||||
|
empty_msg = {
|
||||||
|
"role": "assistant",
|
||||||
|
"content": final_response,
|
||||||
|
"reasoning": reasoning_text,
|
||||||
|
"finish_reason": finish_reason,
|
||||||
|
}
|
||||||
|
messages.append(empty_msg)
|
||||||
|
break
|
||||||
|
|
||||||
|
# Truly empty -- no reasoning and no content
|
||||||
empty_msg = {
|
empty_msg = {
|
||||||
"role": "assistant",
|
"role": "assistant",
|
||||||
"content": final_response,
|
"content": final_response,
|
||||||
|
|
@ -6540,10 +6554,10 @@ class AIAgent:
|
||||||
"finish_reason": finish_reason,
|
"finish_reason": finish_reason,
|
||||||
}
|
}
|
||||||
messages.append(empty_msg)
|
messages.append(empty_msg)
|
||||||
|
|
||||||
self._cleanup_task_resources(effective_task_id)
|
self._cleanup_task_resources(effective_task_id)
|
||||||
self._persist_session(messages, conversation_history)
|
self._persist_session(messages, conversation_history)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"final_response": final_response or None,
|
"final_response": final_response or None,
|
||||||
"messages": messages,
|
"messages": messages,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue