0

LM Studio Provider

LM Studio Provider explains the local layer of MTPX with practical guidance for building inspectable, tool-using agents.

LM
LM Studio Provider
Chapter 034ProvidersLocalIndex
01Orientation

LM Studio Provider belongs to the providers track. The page breaks the idea into responsibilities, implementation rules, failure modes, and the signals you should expose in a product UI.

Use this when

Use this when you need to understand how lm studio provider affects a real MTPX agent before you wire it into an application.

  • What lm studio provider owns in the runtime.
  • How it connects to planning, tool execution, events, providers, or storage.
  • What to log, test, and expose to users when this layer is active.
  • Common mistakes that make agent systems hard to inspect.
02 / syntax starter
from mtp import Agent
from mtp.providers import Groq

agent = Agent.MTPAgent(
    provider=Groq(model="llama-3.3-70b-versatile"),
    tools=tools,
)
03 / manual

Read the system

The complete source manual—syntax, examples, linked references, edge cases, and implementation notes.

Documentation index ↗

LM Studio runs models locally with an OpenAI-compatible server. No cloud API key required.

Install

bashpip install "mtpx[lmstudio]"

This installs the openai SDK (used for the OpenAI-compatible API).

bashpip install openai

Setup

  1. Download LM Studio from lmstudio.ai
  2. Download a tool-capable model (e.g., Qwen 3, Llama 3.2)
  3. Start the local server (default: http://127.0.0.1:1234/v1)
  4. Load a model in the LM Studio UI

No API key is required for local usage. A dummy "lm-studio" key is used by default. If your LM Studio instance requires auth, set LMSTUDIO_API_KEY in your .env file.

Quick Start

pythonfrom mtp import Agent
from mtp.providers import LMStudio

# No API key needed for local LM Studio
provider = LMStudio(model="qwen3-4b-thinking-2507")
tools = Agent.ToolRegistry()
agent = Agent(provider=provider, tools=tools)

reply = agent.run_loop("What is 25 * 4 + 10?")
print(reply)

Parameters

ParameterTypeDefaultDescription
modelstr"qwen3"Model name as loaded in LM Studio
base_urlstr"http://127.0.0.1:1234/v1"LM Studio server URL
api_keystr | NoneNoneAPI key (falls back to LMSTUDIO_API_KEY env var, then "lm-studio")
temperaturefloat0.0Sampling temperature
tool_choicestr | dict"auto"Tool selection strategy
parallel_tool_callsboolTrueAllow parallel tool calls
clientAny | NoneNonePre-configured openai.OpenAI client instance

Capabilities

CapabilityValue
Tool callingYes (if model supports it)
Parallel tool callsYes (configurable)
Input modalitiestext, image
StreamingYes (both stream_next_action and finalize_stream)
Usage metricsRich
Reasoning metadataNo
Native asyncNo (uses thread fallback)

Streaming

LM Studio supports both planning and finalization streaming with reasoning chunk support:

pythonfor event in agent.run_loop_events(
    "Calculate 25 * 4",
    max_rounds=2,
    stream_final=True,
):
    if isinstance(event, dict):
        if event.get("type") == "reasoning_chunk":
            print("[thinking]", event["chunk"])
        elif event.get("type") == "text_chunk":
            print(event["chunk"], end="", flush=True)

Full Example

pythonfrom mtp import Agent
from mtp.providers import LMStudio

provider = LMStudio(
    model="qwen3-4b-thinking-2507",
    base_url="http://127.0.0.1:1234/v1",
    temperature=0.0,
    tool_choice="auto",
    parallel_tool_calls=True,
)

tools = Agent.ToolRegistry()
agent = Agent(provider=provider, tools=tools, debug_mode=True)

reply = agent.run_loop(
    "Calculate (25 * 4) + 10",
    max_rounds=3,
)
print(reply)

Notes

  • LM Studio uses the OpenAI SDK under the hood, pointed at the local server.
  • Tool calling support depends on the loaded model. Use Qwen 3, Llama 3.2, or other tool-capable models.
  • The parallel_tool_calls parameter may be ignored by some model/SDK versions (handled gracefully with fallback).

Source

src/mtp/providers/lmstudio_provider.py

01

Read

Understand where LM Studio Provider sits in the agent loop before adding abstractions.

02

Wire

Connect the smallest useful provider, registry, store, or event stream first.

03

Observe

Expose events, logs, results, and failure states while the runtime is still moving.

04

Harden

Add policy, tests, retries, and audit traces after the behavior is visible.

Next docMistral Provider