LLM and agent services
VoiceStudio provides one language-model layer for translation, timing, dictation, glossary work, direction parsing, and live agents. The layer separates provider choice from feature use, so a workflow can use a local model, a hosted service, or an installed desktop agent without changing its product-level behavior. This page complements Backend API platform, Speech platform integration, Desktop agent browser, and Electron workspaces.
Service boundary
The service boundary connects VoiceStudio workflows to model providers and agent runtimes. The backend owns provider and skill state. The Electron process supplies local CLI agents through a private bridge. Voice and speech clients use the OpenAI-compatible API when an external agent runtime needs VoiceStudio audio.
Capability flow
The following flow shows how a workflow selects a skill, resolves a provider, and reaches either a model transport or a local desktop agent.
flowchart LR
W[VoiceStudio workflow] --> S[LLM skill]
S --> R[Provider resolution]
R --> O[OpenAI-compatible service]
R --> K[SDK adapter]
R --> C[Electron CLI bridge]
O --> A[Completion result]
K --> A
C --> A
A --> W
References: backend/…/llm_skills.py• L1-37 backend/…/llm_transport.py• L78-121 backend/…/llm_cli.py• L1-42 electron/…/llm-agent-bridge.ts• L36-131
Provider configuration
Provider configuration describes where a model runs and how VoiceStudio reaches it. A provider can be a local OpenAI-compatible server, a hosted OpenAI-compatible endpoint, a native SDK service, or an installed command-line agent.
Provider registry
The provider registry gives all LLM features one view of provider identity, model choice, endpoint, account data, and transport type. For provider fields, resolution uses an environment override first, then a saved setting, and then a built-in default. Saved API keys use protected storage and never form part of the client-facing provider description.
Active-provider selection uses an environment pin first and then the user's saved choice. If neither exists, a legacy custom endpoint can select the custom provider. Otherwise the registry may select the first configured remote provider with a usable key. Local providers are not selected only because their software is installed or their local server might be running.
Local providers are treated as user-controlled resources. They do not need a cloud key and are selected explicitly or through a per-skill route. This keeps local use offline unless the user chooses a remote provider and a workflow feature permits the model call.
For a provider with no reliable built-in model name, the registry can discover a usable chat model. An explicit model setting always wins. Discovery is short-lived, and failed discovery is also remembered for a short time, so a missing local server does not add a network delay to every workflow segment. Editing the endpoint or model clears the related discovery result.
The registry also supports account-scoped endpoints and keeps account values separate from their URL templates. This lets a later account change affect the resolved endpoint instead of leaving a saved URL with stale account data.
References: backend/…/llm_providers.py• L1-20 backend/…/llm_providers.py• L43-70 backend/…/llm_providers.py• L243-287 backend/…/llm_providers.py• L291-323 backend/…/llm_providers.py• L389-478 backend/…/llm_providers.py• L481-506 backend/…/llm_providers.py• L617-670 backend/…/llm_providers.py• L718-756
Provider settings contract
The settings API lets the desktop list providers, save provider fields, test a provider, list models where supported, connect a provider, and select the active provider. A test proves that the current configuration can produce a usable answer. A failed test does not enable the provider.
The API returns provider status and safe markers such as has_key; it does not return key material. Environment pins can make fields or selection read-only because a saved UI value cannot override them.
References: backend/…/settings.py• L543-646 backend/…/settings.py• L648-827 electron/…/llm-providers.tsx• L44-75 electron/…/llm-providers.tsx• L205-426
Transport adapters
Transport adapters turn the common completion request into the form expected by a provider. The rest of VoiceStudio uses the same chat-completion shape whether the request goes to an OpenAI-compatible endpoint, a native SDK, or an Electron-owned CLI process.
OpenAI-compatible transport
The OpenAI-compatible transport serves local servers and hosted endpoints through the same completion interface. It resolves the active provider's endpoint and model, keeps retries and time limits under VoiceStudio control, checks credential transport before sending a request, and treats loopback HTTP as local while requiring HTTPS for credentialed remote services.
The backend supports one-shot completions, full message lists, and streamed text. It removes model reasoning blocks from completed answers so private reasoning does not enter transcripts, translations, or other user-facing text. If a provider rejects the optional reasoning control, the backend retries without that control and remembers the endpoint's limitation.
References: backend/…/llm_transport.py• L19-35 backend/…/llm_transport.py• L78-121 backend/…/llm_backend.py• L37-84 backend/…/llm_backend.py• L229-313 backend/…/llm_providers.py• L538-566
SDK transport
The SDK transport covers providers whose native protocol or identity rules do not fit a plain OpenAI endpoint. It uses a shared completion result for skill callers while keeping provider-specific identity and setup rules inside the transport boundary.
SDK configuration is checked before a request starts. A missing package, missing model, missing account identity, or unsafe endpoint is a configuration problem rather than a partial completion.
References: backend/…/llm_transport.py• L68-121 backend/…/llm_providers.py• L569-614 tests/test_llm_transports.py• L29-54
CLI transport
The CLI transport uses the running Electron process as a local adapter for tools such as Codex, Claude Code, Pi, and OpenCode. The backend does not start these tools or pass provider credentials to them. It sends a bounded completion request to a loopback bridge owned by Electron.
This path lets backend skills use a desktop agent as a model source while keeping process discovery, login state, and process lifetime in the desktop layer.
References: backend/…/llm_cli.py• L1-42 electron/…/repair-agents.ts• L43-55 electron/…/repair-agents.ts• L1002-1021
LLM skills
An LLM skill is a named product capability that may use a language model. The skill registry gives each capability an independent enabled state and provider route while preserving the workflow's existing non-LLM behavior.
Skill routing
The registry currently covers direct dubbing translation, cinematic translation, slot fitting, glossary extraction, direction parsing, and dictation refinement. A skill uses a provider override when one exists. Otherwise it uses the active provider. A skill is ready only when it is enabled and its effective provider is configured.
The settings API exposes this state to the desktop. The desktop can turn a skill off or route it to a configured provider such as a local Ollama or LM Studio service without changing the global provider.
References: backend/…/llm_skills.py• L8-37 backend/…/llm_skills.py• L54-81 backend/…/llm_skills.py• L143-191 backend/…/settings.py• L829-874 electron/…/llm-skills.tsx• L21-35
Workflow fallback
Disabled or unavailable skills follow the same path as a workflow with no LLM. Cinematic translation keeps its literal translation, dictation refinement passes through the transcript, direction parsing uses its heuristic path, slot fitting reports that no LLM is available, and glossary auto-extraction reports that the service is unavailable.
This contract keeps model failure local to the optional enhancement. A language-model outage must not turn a normal speech or dubbing workflow into an unexpected data loss or silent replacement.
References: backend/…/llm_skills.py• L22-37 backend/…/translator.py• L206-223 backend/…/translator.py• L336-369 backend/…/refinement.py• L305-325 tests/test_llm_skills.py• L244-365
Agent services
Agent services add model-driven actions to VoiceStudio without giving an agent unrestricted access to the desktop or backend. The main agent paths are local repair and app-operation agents, agent-assisted dubbing translation, and voice pipelines that call the public speech contract.
Desktop agent bridge
Electron discovers installed agent commands and owns their process lifetime. It exposes a short-lived loopback completion bridge only to the backend. The bridge requires a private bearer capability, rejects browser-origin requests, validates the agent name and message shape, limits request size and duration, and serializes work through the shared runner.
The bridge returns safe error classes instead of subprocess output. This keeps login details, source text, and agent diagnostics out of backend responses while still allowing the backend to report authentication, rate-limit, model, or busy failures.
References: electron/…/llm-agent-bridge.ts• L5-34 electron/…/llm-agent-bridge.ts• L36-115 electron/…/llm-agent-bridge.test.ts• L14-80
Agent translation
The desktop agent translation path accepts bounded timed segments and asks an installed agent to return one complete JSON result. The result must contain every input segment ID exactly once and must contain non-empty text. This lets the dubbing workflow use an agent for translation or timing fit without losing segment identity.
The agent runs with tools and unrelated context disabled for this operation. VoiceStudio validates the request before launch and validates the structured result before it returns to the dubbing workflow.
References: electron/…/repair-agents.ts• L356-429 electron/…/repair-agents.ts• L432-475 electron/…/repair-agents.ts• L529-581 electron/…/translation-agent-dock.tsx• L1-40
Voice agent contract
External agent runtimes can use VoiceStudio as their speech provider through the OpenAI-compatible audio API. The runtime sends text, a model alias or engine ID, a voice, and an output format. VoiceStudio returns audio while keeping engine selection and saved voice-profile resolution inside the speech platform.
This separates the agent's conversation model from VoiceStudio's speech services. The agent can use its own language model while VoiceStudio supplies speech recognition and voice output. See Speech platform integration for the full external-client and MCP boundary.
References: electron/…/openai-agents-setup.ts• L7-67 tests/test_agentic_provider_contract.py• L62-109 backend/…/openai_compat.py• L1-20
Backend contracts
The backend contracts keep provider selection, skill readiness, model completion, and workflow fallback independent. Callers should depend on these stable meanings instead of depending on one provider or one agent executable.
Completion interface
The internal completion interface supports one-shot chat, full message lists, and streamed text. Callers can provide system and user context or a complete message sequence. The backend returns assistant text or raises a provider error so the owning workflow can choose its fallback.
Backends can also receive generation controls such as temperature and reasoning effort. A backend without full-message support keeps the system and final user turns as a safe fallback, while callers that depend on examples need a backend that preserves the complete message list. Streaming returns text deltas and leaves reasoning-block handling to the streaming caller.
Completed non-streamed replies remove leading reasoning blocks before they reach user-facing workflows. If a provider rejects the reasoning hint, the backend retries once without it and remembers that limitation for the endpoint. The OffBackend represents an intentional no-model state, so callers can detect unavailable language-model support before they send a request.
Backend selection first honors an explicit backend setting, then checks whether the configured OpenAI-compatible backend is available. When no configured provider is available, selection resolves to the explicit off state rather than failing during setup.
References: backend/…/llm_backend.py• L37-84 backend/…/llm_backend.py• L87-156 backend/…/llm_backend.py• L160-313 backend/…/llm_backend.py• L316-344 backend/…/llm_backend.py• L418-434
Settings interface
The settings interface reports both configured state and readiness. A provider can be saved but not active. A skill can be enabled but not ready. The desktop uses these separate states to show setup needs without claiming that a network or model call has succeeded.
Provider tests classify failures as configuration, authentication, missing model or endpoint, rate limit, network, or general error. Public failure details are scrubbed so credentials, private paths, and subprocess output do not cross the API boundary.
References: backend/…/settings.py• L666-769 backend/…/llm_skills.py• L146-191 electron/…/llm-providers.tsx• L36-54
Speech and agent interface
The public speech interface is the contract for agent runtimes that need audio. It accepts OpenAI-shaped speech requests and forwards supported voice, timing, and quality controls to the active VoiceStudio engine. Agent clients must treat model readiness, format support, capacity, and authentication as explicit service results.
The local CLI interface has a different trust model. It is backend-only, loopback-only, token-protected, and limited to text completion. It must not become a general-purpose command or browser-accessible proxy.
References: backend/…/openai_compat.py• L1-20 tests/test_agentic_provider_contract.py• L62-147 electron/…/llm-agent-bridge.ts• L36-60 backend/…/llm_cli.py• L19-35
Change checklist
When these files or sections are changed, remember to consider these:
- Keep provider IDs, transport labels, field precedence, model discovery behavior, account fields, environment pins, and safe status fields aligned between backend/…/llm_providers.py, the settings router, and the provider settings panel.
- Keep the active-provider rules aligned with backend selection. In particular, do not let a local server or a legacy
TRANSLATE_*setting silently replace an explicit user choice. - When changing model discovery, preserve the distinction between an explicit model, a discovered model, and a remembered failed probe. Clear discovery state when endpoint or model settings change.
- Keep the skill registry IDs aligned with each workflow's skill lookup and with the settings UI's readiness and fallback meaning.
- When adding a transport, preserve the common completion result, timeout bounds, credential transport checks, and safe error classes.
- When changing completion controls or reasoning cleanup, preserve the fallback for providers that reject optional controls and keep private reasoning out of non-streamed user text.
- When changing the CLI bridge, keep its token, loopback, origin, queue, request-size, and timeout rules aligned with llm_cli.py.
- When changing agent translation output, update both the segment validation rules and the complete-ID result contract used by the dubbing workflow.
- When changing the OpenAI-compatible speech shape, review external agent setup examples and the audio contract used by voice runtimes.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A provider is saved but not verified or activated | Skills remain unavailable or continue using the old provider | The connect path tests a usable completion before it enables the LLM engine |
| A local provider is merely installed or reachable | Startup may select a server the user did not choose | Local providers require explicit selection or a skill route |
| A skill override names a provider that is no longer registered | The skill could silently use stale settings | Stale overrides fall back to the active provider and unknown new overrides are rejected |
| A local server changes its loaded model while discovery is cached | A short period of requests can use an old or unavailable model | Discovery has bounded success and failure lifetimes, and provider edits clear the cache |
| A credentialed provider uses remote HTTP | A provider key could cross the network in clear text | Provider and SDK transport checks allow HTTPS or local loopback only |
| A CLI request reaches the bridge without its private capability or with a browser origin | An untrusted local client could invoke an agent | The bridge checks the bearer capability and rejects all origin-bearing requests |
| A shared CLI runner is already busy or a request exceeds its deadline | The workflow waits without a valid agent result | The bridge serializes work, caps the queue, and returns retryable busy or expiry errors |
| An agent returns partial or altered segment IDs | Dubbing could attach text to the wrong source segment | Agent translation requires every expected ID exactly once before returning success |
| A model emits only a reasoning block | Private reasoning could replace user-facing text | Completion handling strips leading reasoning blocks and treats an empty answer as no result |
| A provider rejects the optional reasoning control | A supported model call could fail even though basic completion works | The backend retries without the control and remembers the endpoint limitation |
Key files
| File | Why to read it |
|---|---|
| backend/…/llm_providers.py | Defines provider identity, configuration precedence, account data, model discovery, activation, migration, and readiness. |
| backend/…/llm_skills.py | Defines per-workflow LLM routing, enablement, readiness, and fallback selection. |
| backend/…/llm_backend.py | Defines the common completion interface, provider-backed completion behavior, streaming, reasoning cleanup, and explicit no-model behavior. |
| backend/…/llm_transport.py | Connects the common interface to OpenAI-compatible and SDK transports. |
| backend/…/llm_cli.py | Connects backend completion calls to the Electron-owned CLI bridge. |
| backend/…/settings.py | Exposes provider tests, activation, model discovery, and skill settings to the desktop. |
| electron/…/llm-agent-bridge.ts | Defines the private loopback contract between the backend and desktop agents. |
| electron/…/repair-agents.ts | Defines agent discovery, process ownership, repair work, and structured dubbing translation. |
| electron/…/llm-providers.tsx | Shows how the desktop configures and verifies providers. |
| electron/…/llm-skills.tsx | Shows how the desktop controls skill enablement and provider overrides. |
| electron/…/openai-agents-setup.ts | Shows how an external voice agent uses VoiceStudio's speech contract. |
| tests/test_llm_providers_router.py | Verifies provider setup, activation, probes, model discovery, and safe failure classification. |
| tests/test_llm_skills.py | Verifies skill routing and the workflow behavior when a skill is disabled or unavailable. |
| tests/test_llm_transports.py | Verifies SDK, local, CLI, HTTPS, redirect, proxy, and credential transport rules. |