DeepTutor icon indicating copy to clipboard operation
DeepTutor copied to clipboard

[Bug]:GTP Luna, Terra, and Sol fail to call tools

Open graysonlee123 opened this issue 4 months ago • 12 comments

Do you need to file an issue?

  • [x] I have searched the existing issues and this bug is not already filed.
  • [x] I believe this is a legitimate bug, not just a question or feature request.

Describe the bug

DeepTutor 1.5.4, OpenAI binding, direct api.openai.com/v1.

GPT 5.4 successfully invokes web_search with the same settings and DuckDuckGo provider configuration.

gpt-5.6-terra, gpt-5.6-sol, and gpt-5.6-luna report that web_search / web_fetch is unavailable or fail to issue tool calls.

Container outbound HTTPS is healthy: curl -I -L https://example.com succeeds.

Please check tool/function-call support and tool-call response parsing for the gpt-5.6 model family, especially any Chat Completions vs Responses API response-shape mismatch.

Steps to reproduce

  1. Configure an OpenAI model from the gpt-5.6 family
  2. Create a fresh chat and ask it "Use the web_search tool to search for DeepTutor GitHub repository. Return the repository URL and the title of the first result. Do not answer from prior knowledge."

Expected Behavior

Tools should be called and handled properly.

Related Module

Dashboard

Configuration Used

No response

Logs and screenshots

No response

Additional Information

  • DeepTutor Version: 1.5.4
  • Operating System: Docker
  • Python Version: 3.11.15
  • Node.js Version: 22.23.1
  • Browser (if applicable):
  • Related Issues:

graysonlee123 avatar Jul 26 '26 18:07 graysonlee123

Thanks — I dug into this and can rule out the obvious suspect, but I can't reproduce it without gpt-5.6 access, so I need one more thing from you.

What I ruled out. Tool calling is not gated off for this family:

  • can_use_native_tool_calling(binding="openai", …) returns True — PROVIDER_CAPABILITIES["openai"]["supports_tools"] is True (deeptutor/services/llm/capabilities.py:24-32), so the tool schemas are being attached.
  • More decisively: no code path in the repo distinguishes gpt-5.6 from gpt-5.4. The only occurrence of the string gpt-5.6 anywhere is an unrelated default constant; every other check is a "gpt-5" prefix match that treats both identically. So whatever differs, it isn't a DeepTutor-side gate.

The one real asymmetry — and it matches your hunch. For a direct api.openai.com base with a gpt-5* model, the non-agentic completion path routes to the Responses API (deeptutor/services/llm/provider_core/openai_compat_provider.py:317-343), but the tool-calling chat loop is hardwired to Chat Completions (deeptutor/agents/chat/agent_loop.py:625). If the gpt-5.6 family only emits tool calls reliably through the Responses API, that is exactly the seam — and it would explain why the model answers in prose claiming web_search is unavailable instead of erroring.

Second candidate: reasoning tokens consuming the round's max_completion_tokens budget (agents/chat/agentic_pipeline.py:289-301), leaving no room for the tool call.

What would settle it. Could you run one failing turn with backend debug logging on and attach the raw request/response for that round?

DEEPTUTOR_LOG_LEVEL=DEBUG deeptutor start

The two things I need from the log are whether tools is present in the outgoing request body, and what finish_reason plus usage come back. That distinguishes the two candidates immediately. Keeping this open.

pancacake avatar Jul 27 '26 13:07 pancacake

Correction and a sharper lead — please ignore the DEEPTUTOR_LOG_LEVEL command in my previous comment, that env var doesn't exist. Debug logging is a settings key, not an env var:

# data/user/settings/main.yaml
logging:
  level: DEBUG

Restart, reproduce once, and the round lands in data/user/logs/deeptutor.jsonl.

But there may be a faster answer. Digging further, the chat loop has a silent-degradation path I'd missed (deeptutor/agents/chat/agent_loop.py:643-646): if the provider rejects the request and the error looks tool-related, it strips tools/tool_choice and retries the same round without them. The model then genuinely has no tools and answers in prose — exactly what you're seeing.

That path emits a visible notice in the chat: "Provider rejected native tool schemas; retrying without tools."

So, before touching any logs: did you see that message in the failing conversations? If yes, this is confirmed and the question becomes what gpt-5.6 is actually rejecting. If no, the reasoning-token-budget candidate from my previous comment is the remaining one.

Worth flagging either way: the detector behind that fallback (deeptutor/services/llm/request_compat.py:36-51) matches on the bare substring "tool" anywhere in the error text. Any 400 from a new model family that merely mentions the word — an unsupported parameter, a schema-shape complaint — would trip it and silently disable tool calling for the turn. I'm not narrowing that matcher without a confirmed repro, since it was written for real provider quirks, but your answer to the question above decides whether that's the bug.

pancacake avatar Jul 27 '26 13:07 pancacake

I captured a failing gpt-5.6-luna round at DEBUG.

Round 1 — tools present → 400:

POST https://api.openai.com/v1/chat/completions
model=gpt-5.6-luna, stream=true, temperature=1.0, tool_choice=auto,
tools=[brainstorm, paper_search, reason, web_search, list_notebook,
       write_note, read_skill, exec, code_execution, write_memory,
       web_fetch, github, ask_user, cron]
→ HTTP/1.1 400 Bad Request  (Content-Length: 298)

Round 2 — same round retried, tools/tool_choice stripped → 200:

POST https://api.openai.com/v1/chat/completions
model=gpt-5.6-luna, stream=true   (no tools, no tool_choice)
→ HTTP/1.1 200 OK

The model then answered in prose: "I'm unable to access that GitHub issue link from the available tools right now.".

So: OpenAI rejects the Chat Completions payload for the 5.6 family with a 400, the substring-"tool" matcher in request_compat.py:36-51 trips, tools get stripped, and the turn degrades to prose. gpt-5.4 doesn't 400 on the same payload, which is why it works.

One gap: my client logged the 400 status/headers but not the response body (the 298-byte error payload), so I can't yet tell you which parameter or schema OpenAI is objecting to. That body is the thing that decides whether this is:

  • a param the 5.6 Chat Completions endpoint no longer accepts (e.g. temperature, max_completion_tokens, tool_choice shape), or
  • a genuine "tools only via Responses API for this family" signal, matching your first-comment seam (agent_loop.py:625 hardwired to Chat Completions).

If there's a quick way to get the client to log response bodies on 4xx, point me at it and I'll grab it.

P.S.: Sorry I thought I responded to this about a week ago, but for some reason GitHub never actually posted my comment.

graysonlee123 avatar Aug 08 '26 21:08 graysonlee123

I captured a failing round at DEBUG.gpt-5.6-luna

Round 1 — tools present → 400:

POST https://api.openai.com/v1/chat/completions
model=gpt-5.6-luna, stream=true, temperature=1.0, tool_choice=auto,
tools=[brainstorm, paper_search, reason, web_search, list_notebook,
       write_note, read_skill, exec, code_execution, write_memory,
       web_fetch, github, ask_user, cron]
→ HTTP/1.1 400 Bad Request  (Content-Length: 298)

Round 2 — same round retried, tools/tool_choice stripped → 200:

POST https://api.openai.com/v1/chat/completions
model=gpt-5.6-luna, stream=true   (no tools, no tool_choice)
→ HTTP/1.1 200 OK

The model then answered in prose: "I'm unable to access that GitHub issue link from the available tools right now.".

So: OpenAI rejects the Chat Completions payload for the 5.6 family with a 400, the substring- matcher in trips, tools get stripped, and the turn degrades to prose. gpt-5.4 doesn't 400 on the same payload, which is why it works."tool"``request_compat.py:36-51

One gap: my client logged the 400 status/headers but not the response body (the 298-byte error payload), so I can't yet tell you which parameter or schema OpenAI is objecting to. That body is the thing that decides whether this is:

  • a param the 5.6 Chat Completions endpoint no longer accepts (e.g. , , shape), ortemperature``max_completion_tokens``tool_choice
  • a genuine "tools only via Responses API for this family" signal, matching your first-comment seam ( hardwired to Chat Completions).agent_loop.py:625

If there's a quick way to get the client to log response bodies on 4xx, point me at it and I'll grab it.

I captured a failing round at DEBUG.gpt-5.6-luna

Round 1 — tools present → 400:

POST https://api.openai.com/v1/chat/completions
model=gpt-5.6-luna, stream=true, temperature=1.0, tool_choice=auto,
tools=[brainstorm, paper_search, reason, web_search, list_notebook,
       write_note, read_skill, exec, code_execution, write_memory,
       web_fetch, github, ask_user, cron]
→ HTTP/1.1 400 Bad Request  (Content-Length: 298)

Round 2 — same round retried, tools/tool_choice stripped → 200:

POST https://api.openai.com/v1/chat/completions
model=gpt-5.6-luna, stream=true   (no tools, no tool_choice)
→ HTTP/1.1 200 OK

The model then answered in prose: "I'm unable to access that GitHub issue link from the available tools right now.".

So: OpenAI rejects the Chat Completions payload for the 5.6 family with a 400, the substring- matcher in trips, tools get stripped, and the turn degrades to prose. gpt-5.4 doesn't 400 on the same payload, which is why it works."tool"``request_compat.py:36-51

One gap: my client logged the 400 status/headers but not the response body (the 298-byte error payload), so I can't yet tell you which parameter or schema OpenAI is objecting to. That body is the thing that decides whether this is:

  • a param the 5.6 Chat Completions endpoint no longer accepts (e.g. , , shape), ortemperature``max_completion_tokens``tool_choice
  • a genuine "tools only via Responses API for this family" signal, matching your first-comment seam ( hardwired to Chat Completions).agent_loop.py:625

If there's a quick way to get the client to log response bodies on 4xx, point me at it and I'll grab it.

P.S.: Sorry I thought I responded to this about a week ago, but for some reason GitHub never actually posted my comment.

"I have the same issue and logs as you.

P.S.: Sorry I thought I responded to this about a week ago, but for some reason GitHub never actually posted my comment.

I have the same issue and logs as you!!!deeptutor v1.5.9, I asked my Codex, and it suggested that the DeepTutor code changed the web search tool's ID from 400 to 200.

Yenomal avatar Aug 11 '26 03:08 Yenomal

thanks for your comments!

pancacake avatar Aug 16 '26 15:08 pancacake

Traced the seam: AgentLoop._create_response_stream (deeptutor/agents/chat/agent_loop.py:883) calls the raw AsyncOpenAI client's chat.completions.create directly — that client is built independently in agentic_pipeline.py:342 and never goes through OpenAICompatProvider._should_use_responses_api (openai_compat_provider.py:329), which already routes gpt-5*/o1/o3/o4 on a direct OpenAI base through the Responses API for every other call path (chat()/chat_stream()). The agentic tool-calling loop is the one path that skips that routing entirely. Given @graysonlee123's captured log — 400 with tools on Chat Completions, 200 without — this divergence looks like the most likely root cause: gpt-5.6 may reject something on Chat Completions that Responses API accepts.

Also confirmed the substring-"tool" matcher gap you flagged is still live at request_compat.py:64 — unrelated to root-causing this, but it's why the failure degrades silently instead of surfacing.

PR up for the diagnostic half: #930 — logs the provider's raw error body when the tool-schema fallback trips, so the exact 400 payload (still missing from this thread) gets captured automatically on the next occurrence, no special repro steps needed.

The actual fix — routing the agentic loop through the same Responses-API path — is a hot-path refactor touching every chat turn, and I can't verify it without gpt-5.6 access. @graysonlee123, if you're willing to test a branch against your account once I have one up, I'll take a swing at it; otherwise leaving it open for whoever has access to confirm against.

sjagadee avatar Aug 20 '26 02:08 sjagadee

deeptutor.jsonl.zip I have uploaded the error reproduction logs. My current version is v1.5.14. I hope this information proves useful.

Yenomal avatar Aug 25 '26 05:08 Yenomal

Thanks for the log. A concrete detail from it: the request goes through https://api.toskaxy.xyz/v1/chat/completions, not direct OpenAI, and the replayed conversation contains a repeated concatenation of the same tool_call_id (hundreds of characters). That matches #937, where a gateway re-sent complete tool-call IDs on every stream chunk and the old accumulator appended them into an invalid Chat Completions payload.

The latest code no longer does this: ToolCallAccumulator now assigns complete id/name fields and concatenates only arguments, with regression coverage in tests/core/agentic/test_tool_call_stream.py. The attached log is from v1.5.14, before that fix.

Could you retest on a build that includes #937? If the same provider still returns the generic new_api_error/upstream_error after the oversized ID is gone, the remaining direct-OpenAI Responses-routing theory is still worth tracking separately, but this log itself appears explained by #937 rather than #708.

evan188199-tech avatar Aug 27 '26 13:08 evan188199-tech

Thanks for the detailed logs. The direct-OpenAI side of this should already be fixed by #882, which routes direct OpenAI gpt-5* models (including the 5.6 family) through the Responses API in the agentic tool loop instead of Chat Completions.

The fix landed in commit dae3c4ef and is included in v1.5.13, v1.5.14, v1.5.17, and the current v1.6.0 / dev branches. I verified against clean origin/dev at bd9f6a76:

uv run --python 3.13 --extra dev pytest -q tests/core/test_agentic_client_provider_kwargs.py
30 passed in 0.78s

That suite includes test_direct_openai_gpt5_agentic_tools_use_provider_adapter, which specifically asserts that gpt-5.6-luna tool calls use the Responses API and do not fall back to Chat Completions.

Could you retest with:

  1. an image/build that genuinely matches DeepTutor v1.6.0;
  2. a direct https://api.openai.com/v1 endpoint; and
  3. one of gpt-5.6-luna, gpt-5.6-terra, or gpt-5.6-sol.

If it still fails on direct OpenAI, please include the model, exact base URL, and the first failing 4xx response body. The api.toskaxy.xyz log above points to a gateway-specific Chat Completions payload issue and matches #937 rather than this direct-OpenAI routing bug.

evan188199-tech avatar Aug 28 '26 17:08 evan188199-tech

Status check against current dev (bd9f6a76): this appears to be fixed by two merged changes rather than needing a new patch.

  • #882 routes direct OpenAI GPT-5/o-series agentic calls through the Responses API. Its merge commit (dae3c4ef) is an ancestor of current dev.
  • #1008 stops the schema-fallback detector from matching a bare tool mention, so an unrelated provider error no longer silently strips tools. Its merge commit (22b70c3a) is also in current dev.

Could you retest with the latest build and the same web_search prompt? If it still fails, please attach the server log lines containing Provider rejected native tool schemas plus the provider response body logged by the current code; those should identify whether another gateway-specific request shape needs handling.

evan188199-tech avatar Aug 28 '26 18:08 evan188199-tech

Hooray, this seems to be working! On Docker 1.6.0 sha256:53807413c2cd943b7bd1c9b85b3834c4a05c03586d5694a07172b3a93519439a:

Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   openai._base_client - Sending HTTP Request: POST https://api.openai.com/v1/responses
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.connection - close.started
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.connection - close.complete
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.connection - connect_tcp.started host='api.openai.com' port=443 local_address=None timeout=5.0 socket_options=None
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.connection - connect_tcp.complete return_value=<httpcore._backends.anyio.AnyIOStream object at 0x71591be3ab90>
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.connection - start_tls.started ssl_context=<ssl.SSLContext object at 0x71592221d0a0> server_hostname='api.openai.com' timeout=5.0
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.connection - start_tls.complete return_value=<httpcore._backends.anyio.AnyIOStream object at 0x71591be63590>
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.http11 - send_request_headers.started request=<Request [b'POST']>
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.http11 - send_request_headers.complete
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.http11 - send_request_body.started request=<Request [b'POST']>
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.http11 - send_request_body.complete
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.http11 - receive_response_headers.started request=<Request [b'POST']>
Aug 29 11:04:16 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.http11 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Date', b'Sat, 29 Aug 2026 15:04:16 GMT'), (b'Content-Type', b'text/event-stream; charset=utf-8'), ...

Receiving a 200 with successful web search tool call.

graysonlee123 avatar Aug 29 '26 15:08 graysonlee123

Hooray, this seems to be working! On Docker 1.6.0 sha256:53807413c2cd943b7bd1c9b85b3834c4a05c03586d5694a07172b3a93519439a:

Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   openai._base_client - Sending HTTP Request: POST https://api.openai.com/v1/responses
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.connection - close.started
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.connection - close.complete
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.connection - connect_tcp.started host='api.openai.com' port=443 local_address=None timeout=5.0 socket_options=None
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.connection - connect_tcp.complete return_value=<httpcore._backends.anyio.AnyIOStream object at 0x71591be3ab90>
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.connection - start_tls.started ssl_context=<ssl.SSLContext object at 0x71592221d0a0> server_hostname='api.openai.com' timeout=5.0
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.connection - start_tls.complete return_value=<httpcore._backends.anyio.AnyIOStream object at 0x71591be63590>
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.http11 - send_request_headers.started request=<Request [b'POST']>
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.http11 - send_request_headers.complete
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.http11 - send_request_body.started request=<Request [b'POST']>
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.http11 - send_request_body.complete
Aug 29 11:04:15 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.http11 - receive_response_headers.started request=<Request [b'POST']>
Aug 29 11:04:16 sulaco docker-deeptutor-start[1722906]: DEBUG   httpcore.http11 - receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Date', b'Sat, 29 Aug 2026 15:04:16 GMT'), (b'Content-Type', b'text/event-stream; charset=utf-8'), ...

Receiving a 200 with successful web search tool call.

Lets go!!!

pancacake avatar Aug 29 '26 15:08 pancacake