LLMAdapter implementation. It enables MeshAgent agents to use the OpenAI Responses API, handling streaming, tool calls, and model-specific settings.
Key features
- Model defaults: Reads the model name from the constructor (
model=) or theOPENAI_MODELenvironment variable. Override per message by passingmodelin the chat payload;ChatBotforwards it tonext(). - Chat context defaults: Creates
AgentChatContext(system_role=None)so system/developer prompts are driven by the caller or wrapper agent. - Tool bundling: Converts the supplied toolkits into OpenAI tool definitions (both standard JSON function tools and OpenAI-native tools like
computer_use_preview,web_search_preview,image_generation). - Streaming support: Consumes the streaming response API, emitting events such as reasoning summaries, partial content, and tool call updates.
- Parallel tool calls: Optionally enables OpenAI’s
parallel_tool_callssetting (disabled automatically for models that do not support it). - Structured output: If
output_schemais provided tonext(), requests JSON schema output and validates the result. - Automatic compaction: Uses the OpenAI Responses compaction API to shrink the context when the next request would exceed the model window.
Constructor parameters
Python
model– default model name; can be overridden per message.parallel_tool_calls– request parallel tool execution when supported.client– reuse an existingAsyncOpenAIclient; otherwise the adapter creates one viameshagent.openai.proxy.get_client.response_options– extra parameters passed toresponses.create.reasoning_effort– populates the Responses APIreasoningoptions.provider– label emitted in telemetry and logs.log_requests– when true, logs HTTP requests for debugging.max_output_tokens– cap output tokens per response; also used when deciding whether to compact the context.
Tool provider integration
The adapter includes several builders and tools for OpenAI native tools. Agents can use them directly, or override them with agent-specific wrappers that add persistence (for example, the ChatBot’s thread-aware image generation builder that saves partial/final images to room storage and updates the thread document).- Image generation –
ImageGenerationConfig,ImageGenerationToolkitBuilder,ImageGenerationTool - Local shell –
LocalShellConfig,LocalShellToolkitBuilder,LocalShellTool - MCP –
MCPConfig,MCPToolkitBuilder,MCPTool - Web search preview –
WebSearchConfig,WebSearchToolkitBuilder,WebSearchTool - File Search -
FileSearchTool - Code Interpreter -
CodeInterpreterTool - Reasoning -
ReasoningTool
Handling a turn
Whennext() is called it:
- Bundles tools - Collects the tools from your toolkits and packages them for OpenAI’s API
- Calls the model - Sends messages and tools to OpenAI’s API
- Handles responses - Processes text, tool calls, or structured output
- Executes tools - When the model requests tools, executes them and formats results
- Loops - Continues calling the model with tool results until it produces a final answer
- Returns Result - Gives you the final output (text or structured data)
Context compaction
OpenAIResponsesAdapter stores token usage from the last response in the chat context metadata. Before issuing the next request it checks whether the prior input + output usage would overflow the model’s context window (while reserving max_output_tokens for the reply). If so, it calls responses.compact, replaces the context messages with the compacted output, and then proceeds with the new request. This is automatic; you do not need to call compaction manually.
Related Topics
- Adapters Overview: Understand LLMAdapters and ToolResponseAdapters
- LLM Proxy: How requests are routed and metered inside rooms
- OpenAI Tool Response Adapter: How tool outputs are rendered back into the chat transcript.
- ChatBot Overview: Shows where the adapter is invoked in the overall agent flow.