Skip to content

Studio: enable local tool calling for self-hosted OAI-compat connections - #8626

Closed
khalidejaz wants to merge 2 commits into
unslothai:mainfrom
khalidejaz:feat/self-hosted-local-tools
Closed

khalidejaz wants to merge 2 commits into
unslothai:mainfrom
khalidejaz:feat/self-hosted-local-tools

Conversation

@khalidejaz

Copy link
Copy Markdown
Contributor

Summary

Self-hosted connections (llama.cpp / vLLM / Ollama / Custom) had Search / Code / MCP greyed out, so tool requests were proxied without any tool schemas and the models answered "I can't browse/search." This declares a provider-level studio_tools capability in PROVIDER_REGISTRY (the "*" wildcard in model_capabilities), which flows through the same registry-driven pipeline the Codex loop uses (providerModelSupportsStudioTools / supportsStudioToolsForThisTurn), so the pills light up and requests enter Unsloth's local tool loop against the remote endpoint.

What's included

  • Backend: provider_runs_local_tools() reads the registry; the gate follows the explicit enable_tools/enabled_tools/mcp_enabled signal, keeps client-supplied tools on passthrough, honors a zero tool-call budget, caps per-turn fan-out, and supports interactive confirm via the shared approval gate (same as the GGUF/safetensors loops). Hidden registry entries are now served with a hidden flag so the capability reaches the frontend.
  • Frontend: providerModelSupportsStudioTools() falls back to the provider-level capability; Search/Code pills consult it. No hardcoded provider-type list.

Motivation

Fixes #7282. Supersedes the independently-written #7330 — this implementation expresses the self-hosted capability through the registry rather than a hardcoded provider list, so it rides the exact mechanism upstream uses for Codex.

Test plan

  • pytest on test_external_agentic.py, test_external_local_tool_gate.py, test_permission_mode.py, test_tool_confirm_loop.py (+ full external/codex suites) — all pass.
  • ruff check + repo format hook clean; tsc -b and frontend unit tests pass.
  • Manual: llama.cpp/vLLM connection → Search/Code/MCP enabled → web search + Python execution through the loop; confirm_tool_calls shows the approval dialog.

…ons (unslothai#7282)

Self-hosted connections (llama.cpp / vLLM / Ollama / custom) advertise the
registry's provider-level studio_tools capability, so their Search / Code /
MCP toggles light up and tool requests enter Unsloth's local tool loop
against the remote endpoint instead of being proxied tool-less.

Two halves:

- Backend: provider_runs_local_tools() reads PROVIDER_REGISTRY's
  model_capabilities "*" wildcard; the loop gate follows the explicit
  enable_tools / enabled_tools / mcp_enabled signal (never a CLI policy
  alone), keeps client-supplied tools on the pure passthrough, honors a
  zero tool-call budget, caps per-turn fan-out, and supports interactive
  confirm through the shared approval gate like the local GGUF /
  safetensors loops.
- Frontend: providerModelSupportsStudioTools() falls back to the
  provider-level capability and the Search/Code pills consult it, so the
  same registry-driven mechanism the Codex loop uses decides self-hosted
  tool support. No hardcoded provider-type list.

Hidden registry entries are now served (with a hidden flag) so the
capability reaches the frontend through the existing /registry pipeline.

Fixes unslothai#7282. Supersedes the independently-written
unslothai#7330.
@mahiatlinux

Copy link
Copy Markdown
Contributor

Thanks @khalidejaz. We incorporated the provider-level studio_tools wildcard and shared _select_request_tools approach from this PR into #8630, and credited you in the #8630 description.

#8630 now supersedes this implementation with the same registry-driven Search, Code, MCP, and RAG coverage plus an explicit per-connection trust opt-in, correct automatic high-risk approvals, separately flushed Tauri approval cards, usage and finish-reason preservation, reasoning support, forced-choice and budget correctness, partial-markup suppression, provisional cards, and stalled-model recovery.

Manually verified both external-provider and native approval flows in the Tauri desktop app.

@khalidejaz

Copy link
Copy Markdown
Contributor Author

Superseded by #8630, which incorporates the registry-driven studio_tools approach from this PR and adds the per-connection Local tools safety opt-in, high-risk auto-approval, usage/provisional-card handling, and broader edge-case coverage. Closing in favor of #8630.

@khalidejaz khalidejaz closed this Aug 13, 2026
danielhanchen added a commit that referenced this pull request Aug 14, 2026
The squash merge of #8665 kept only two trailers, so the four PRs that work was
built out of are not attributed anywhere in main's history. Recording them here.

#8626 (@khalidejaz) contributed the registry capability and the hidden-entry
exposure, down to the provider_runs_local_tools() name.

#8630 (@mahiatlinux) contributed the loop internals: the user-turn append, the
tool-stream advance and drain, usage merging, the approval flush delay, the
budget-exhausted nudge and the streamed tool-name fix, plus a number of its test
cases. They also built the merged branch and drove it in a browser against a
control worktree, which found several real defects before release, including a
truncated turn discarding a healed call together with the text describing it.

#7805 (@Etherll) contributed the hosted-provider reach.

#7330 (@Souravrajvi0) is the original OpenAI-compatible framing the work started
from.

Two things were deliberately not taken, and the difference is worth recording:
the per-connection framing from #8630 and the studio_tool_execution column from
#7805. #8665 shipped a static disclosure instead while widening the capability
from four self-hosted types to thirteen.

Co-authored-by: Malik Khalid Ejaz <[email protected]>
Co-authored-by: Maheswar Kumar <[email protected]>
Co-authored-by: Etherl <[email protected]>
Co-authored-by: Souravrajvi0 <[email protected]>
danielhanchen added a commit that referenced this pull request Aug 14, 2026
)

The squash merge of #8665 kept only two trailers, so the four PRs that work was
built out of are not attributed anywhere in main's history. Recording them here.

#8626 (@khalidejaz) contributed the registry capability and the hidden-entry
exposure, down to the provider_runs_local_tools() name.

#8630 (@mahiatlinux) contributed the loop internals: the user-turn append, the
tool-stream advance and drain, usage merging, the approval flush delay, the
budget-exhausted nudge and the streamed tool-name fix, plus a number of its test
cases. They also built the merged branch and drove it in a browser against a
control worktree, which found several real defects before release, including a
truncated turn discarding a healed call together with the text describing it.

#7805 (@Etherll) contributed the hosted-provider reach.

#7330 (@Souravrajvi0) is the original OpenAI-compatible framing the work started
from.

Two things were deliberately not taken, and the difference is worth recording:
the per-connection framing from #8630 and the studio_tool_execution column from
#7805. #8665 shipped a static disclosure instead while widening the capability
from four self-hosted types to thirteen.

Co-authored-by: Malik Khalid Ejaz <[email protected]>
Co-authored-by: Maheswar Kumar <[email protected]>
Co-authored-by: Etherl <[email protected]>
Co-authored-by: Souravrajvi0 <[email protected]>
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.

[Bug] Remote Models not able to do Tool Calling

2 participants