Skip to content

Commit 744a580

Browse files
committed
Fix memory tools returning 'unsupported call' in Chat Completions
The Chat Completions handler executed memory tool calls (memory_save, memory_search, etc.) but discarded the results — returning the original response with tool_calls but no tool results. The client saw "unsupported call" because it never received the tool output. Fix: after executing memory tools, send a continuation request to the upstream model with the tool results appended as messages, so the model produces a final user-facing response. Fixes #157
1 parent b501369 commit 744a580

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

headroom/proxy/handlers/openai.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,9 @@ async def handle_openai_chat(
672672
uncached_tokens=uncached_input_tokens,
673673
)
674674

675-
# Memory: handle memory tool calls in OpenAI response
675+
# Memory: handle memory tool calls in OpenAI Chat Completions response.
676+
# After executing tools, send a continuation request so the model
677+
# can produce a final user-facing response (not just tool_calls).
676678
if (
677679
self.memory_handler
678680
and memory_user_id
@@ -684,10 +686,29 @@ async def handle_openai_chat(
684686
tool_results = await self.memory_handler.handle_memory_tool_calls(
685687
resp_json, memory_user_id, "openai"
686688
)
687-
logger.info(
688-
f"[{request_id}] Memory: Handled {len(tool_results)} "
689-
f"tool call(s) for user {memory_user_id}"
690-
)
689+
if tool_results:
690+
# Build continuation: original messages + assistant tool_calls + tool results
691+
assistant_msg = resp_json.get("choices", [{}])[0].get("message", {})
692+
continuation_messages = list(optimized_messages)
693+
continuation_messages.append(assistant_msg)
694+
continuation_messages.extend(tool_results)
695+
696+
continuation_body = {
697+
**body,
698+
"messages": continuation_messages,
699+
}
700+
701+
cont_response = await self._retry_request(
702+
"POST", url, headers, continuation_body
703+
)
704+
if cont_response.status_code == 200:
705+
resp_json = cont_response.json()
706+
response = cont_response
707+
708+
logger.info(
709+
f"[{request_id}] Memory: Handled {len(tool_results)} "
710+
f"tool call(s) with continuation for user {memory_user_id}"
711+
)
691712
except Exception as e:
692713
logger.warning(f"[{request_id}] Memory tool handling failed: {e}")
693714

0 commit comments

Comments
 (0)