Skip to content

About

AI agent local using OpenAI Agent SDK

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

Minimal LM Studio agent with OpenAI Agents SDK

A small, local-only template for building an agent with the Python OpenAI Agents SDK. The application code uses functions and plain data; it defines no custom classes.

The template intentionally uses OpenAIChatCompletionsModel because LM Studio exposes an OpenAI-compatible Chat Completions endpoint. SDK tracing is disabled globally when the agent is created and again for every run, so traces are not exported to OpenAI.

Requirements

  • Python 3.12 or newer
  • Poetry
  • LM Studio running with a model loaded and its local server enabled

Setup

poetry install
cp src/agent/.env.example src/agent/.env

Set LM_STUDIO_MODEL in src/agent/.env to the model identifier reported by LM Studio. The default server URL is http://localhost:1234/v1. The placeholder API key is required by the OpenAI-compatible client but does not leave your machine.

Run the agent:

poetry run python -m agent

Use /new to clear the in-memory conversation and /quit to exit.

Structure

src/agent/
├── agent.py          # LM Studio client, Chat Completions model, and Agent
├── agent_prompt.md   # System instructions
├── cli.py            # Interactive terminal loop
├── config.py         # Environment loading and validation
├── runner.py         # One Agents SDK run
├── mcp_config.py     # Documented future MCP integration point
├── guardrails.py     # Documented future guardrail integration point
└── sessions.py       # Documented future persistent-session integration point

The current conversation is deliberately kept in memory with RunResult.to_input_list(). MCP, guardrails, persistent sessions, tools, and multi-agent handoffs are not enabled; their policies should be defined before implementation.

Local-only guarantees

Two explicit controls prevent the Agents SDK trace exporter from sending run data to OpenAI:

set_tracing_disabled(True)
RunConfig(tracing_disabled=True)

The model is also explicitly constructed as a Chat Completions model:

OpenAIChatCompletionsModel(model=model_id, openai_client=lm_studio_client)

Only LM_STUDIO_BASE_URL is configured as the model endpoint. Adding remote tools or MCP servers later can introduce separate network connections and must be reviewed independently.

Verification

poetry check
poetry run pytest -q

Relevant SDK documentation:

About

AI agent local using OpenAI Agent SDK

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages