ContextGuides

OpenAI Agents SDK

A clone of your agent whose tools enable per turn as skills load. The run context is the session.

skills = context.load_skills("../quickstart/skills", tools=[lookup_order, issue_refund, search_docs])
model = scripted_model(script(load("refunds"), call("lookup_order", order_id="A-1001"), say("Refunded.")))

agent = with_skills(skills, Agent(name="support", instructions="You are a support agent.", model=model))
session = skills.session()  # one per conversation; keep it for the next turn
result = await Runner.run(
    agent, "My order A-1001 arrived damaged.", context=session, run_config=run_options(session)
)  # a call to an unloaded tool is a refusal the model reads
const skills = await loadSkills("../quickstart/skills", { tools: [lookupOrder, issueRefund, searchDocs] });
const model = scriptedModel(script(load("refunds"), call("lookup_order", { order_id: "A-1001" }), say("Refunded.")));

const agent = withSkills(skills, new Agent({ name: "support", instructions: "You are a support agent.", model }));
const session = skills.session(); // one per conversation; keep it for the next turn
const result = await run(agent, "My order A-1001 arrived damaged.", { context: session, ...runOptions(session) });

with_skills(skills, agent) / withSkills(skills, agent) never mutates your agent. The clone carries your tools, then load_skill and every registry tool, each enabled only while a skill binding it is loaded (the runner re-evaluates is_enabled every turn). Instructions become your instructions followed by Context's system prompt, rebuilt each turn.

Pass the run options for the conversation's session: TypeScript spreads runOptions(session) into run(); Python passes run_config=run_options(session) to Runner.run (a registry works too, for its default grant). The runner leaves disabled tools out of the request, and by default a model call to one of them crashes the run with ModelBehaviorError; with these options the model reads Context's refusal ("issue_refund is not available. Load the refunds skill first.") and recovers. A tool outside the session's allow gets the SDK's own not-found message, like a name that does not exist.

Pass one session per conversation as the run context and keep it for the next turn. If your run context is your own type, pass session_from / sessionFrom to find the session inside it.

Routers and input triggers need the user's input, which the SDK does not hand to tools: call await session.prepare(input) before running if your registry uses them.