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.
- Python 3.12 or newer
- Poetry
- LM Studio running with a model loaded and its local server enabled
poetry install
cp src/agent/.env.example src/agent/.envSet 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 agentUse /new to clear the in-memory conversation and /quit to exit.
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.
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.
poetry check
poetry run pytest -qRelevant SDK documentation: