Agent class plus a Runner that drives the LLM loop. xpander supplies the agent’s identity (instructions, skills, model, knowledge bases); this page wires the two together. In the SDK, skills are exposed as tools, the name agent loops use for them. This SDK integration is optional: agents created in Xpander Chat or through the API run on Claude Code, Codex or OpenCode by default.
What doesn’t come built in
Unlike Agno, some capabilities aren’t auto-wired. Configure them yourself:Prerequisites
- Complete the Quickstart so the CLI, SDK, and
xpander loginare already set up. - Python 3.12+ for the local handler.
OPENAI_API_KEYin your shell. The OpenAI Agents SDK uses its own OpenAI client and does not pick up the LLM credentials configured on the agent in Xpander Chat. If you’ve set a custom key on the agent, mirror it into your.envso the runner uses it.
1. Install
Both packages are required. The OpenAI Agents SDK ships under theopenai-agents distribution but imports as agents.
2. Set up scaffolding
xpander_config.json reference
xpander_config.json
3. Create task handler
The full pattern, wrapped in@on_task so xpander routes tasks to it. The highlighted lines are the integration’s load-bearing reads:
xpander_handler.py
Agents(configuration=...).aget(agent_id=...)calls the xpander control plane and returns a fully-hydratedAgentobject. Its instructions, skill repository, model, and knowledge-base links are all populated.xpander_agent.instructions.fullis a single string that wraps the agent’sgeneraldescription,rolelist, andgoallist in<description>,<instructions>, and<goals>tags. Drop it straight into the OpenAI Agents SDK’sinstructionsparameter.xpander_agent.openai_agents_sdk_toolsis a computed property that wraps every xpander skill (catalog skills, custom@register_toolfunctions, skills served over MCP) as aFunctionToolfromagents.tool. Each wrapper’son_invoke_toolcalls back into xpander’s skill execution path, so connected-account auth, observability, and retries still work.xpander_agent.model_nameis the model identifier configured on the agent (e.g.gpt-4.1,gpt-4o). Pass it to the OpenAI Agents SDK’smodelparameter.Runner.run(native, input=task.to_message())drives the LLM loop.task.to_message()returns the task’s user message (text plus any attachments) in the shape the runner expects.- Writing back to
task.resultlets xpander store the output and surface it in the API, Xpander Chat, and any wired channels.
4. Edit the agent’s system prompt
agent_instructions.json contains the agent’s system prompt and has exactly three fields:
agent_instructions.json
xpander agent dev syncs it to the control plane.
5. Wire knowledge-base retrieval (optional)
The OpenAI Agents SDK doesn’t auto-wire xpander’s knowledge bases, so expose the retriever as a@function_tool the runner can call. The highlighted lines show the two integration points: building the retriever and concatenating it onto the auto-wired skill list.
xpander_handler.py
6. Set up streaming (optional)
For token-by-token output, decorate anasync def that yields TaskUpdateEvent objects instead of returning a Task. The decorator detects the difference automatically.
streaming_handler.py
Runner.run_streamed(native, input=task.to_message())returns aRunResultStreaming. Iteratingstreaming.stream_events()yields raw response events, run-item events, and a final completion event.- The
Chunkevent forwards each text delta to xpander’s SSE stream so clients render output as it arrives. - The
TaskFinishedevent signals the end of the stream and carries the final task back to xpander.
POST /invoke, returning Server-Sent Events. xpander’s SSE listener for cloud-deployed agents expects a regular handler that returns a Task. So if you need both an interactive streaming experience and xpander-routed tasks, run two handlers, or have your streaming endpoint proxy through a regular handler.
7. Test local development
Run the handler with the dev server. Tasks created from any channel (REST, Slack, Xpander Chat) route to your laptop:--output_format and --output_schema are useful for testing structured output without changing the agent’s settings in the control plane.
Troubleshooting
Wrong model or wrong key used at runtime
Wrong model or wrong key used at runtime
The OpenAI Agents SDK instantiates its own OpenAI client and reads
OPENAI_API_KEY from the environment. It does not pick up a custom LLM key configured on the agent in Xpander Chat. If the runner is using the wrong key, mirror the cloud-side custom key into your local .env as OPENAI_API_KEY.Why doesn't Backend.aget_args() work for the OpenAI Agents SDK?
Why doesn't Backend.aget_args() work for the OpenAI Agents SDK?
Backend.aget_args() currently dispatches only to the Agno builder. For every other agent loop, including the OpenAI Agents SDK, you load the Agent yourself with Agents().aget(...) and read the fields you need.How do I keep conversation history across turns?
How do I keep conversation history across turns?
There’s no built-in session storage for the OpenAI Agents SDK. The runner exposes
result.to_input_list(), which returns the full conversation as input items you can persist (Postgres, Redis, your own store) and pass back as input=previous_items + new_message on the next turn. If you’d rather not build that yourself, switch to the Agno integration.Can I use the runner's built-in handoffs?
Can I use the runner's built-in handoffs?
Yes.
xpander_agent.openai_agents_sdk_tools only supplies skills, not the runner’s handoff configuration. You declare handoffs on the native Agent exactly as you would in any OpenAI Agents SDK app. Each agent in the handoff chain can independently load its own xpander skills.Does this work with non-OpenAI models?
Does this work with non-OpenAI models?
The OpenAI Agents SDK supports other model clients through its model-agnostic interface.
xpander_agent.model_name is just a string. Pass it to whichever client you instantiate. The underlying model has to support function calling for the integration to work end to end.Next steps
Quickstart
The 10-minute scaffold-to-deploy walkthrough that produced the handler shown above.
Custom skills
Wrap private APIs as skills with
@register_tool and ship them through openai_agents_sdk_tools.Compare with Agno
What you’d gain by switching: session storage, knowledge-base auto-wiring,
Backend.aget_args().Core Concepts
The SDK class names mapped onto agents, tasks, threads, and memory.
SDK integrations overview
What’s auto-wired vs. manual for Agno, OpenAI Agents SDK, LangChain, and AWS Strands.

