TOOL WIKI · AGENT SDKS

OpenAI Agents SDK

Defines agents and runs tool-use loops with support for handoffs and guardrails.

Download example files Code + setup + checks in a ZIP
Jump to a section 10 sections

EXAMPLE USE CASE

Answer an order question through a tool

A developer needs a small, observable agent or retrieval step before connecting real business services.

Input
Question about A104, lookup_order and a configured provider model.
Expected output
Packed; awaiting courier pickup, grounded in a tool observation.
  • Success check: The answer reports that A104 is packed and awaiting courier pickup.
  • Try a failure: Ask about A999. The model must preserve Order not found.

Example scope: Actual SDK loop with one read-only fixture; no production order backend.

Official reference · OpenAI Agents SDK

WHAT IT ISAgent SDK
WHERE IT FITSAgent SDKs
SEE HOW THE SYSTEM FITS TOGETHERSELECT A COMPONENT
taskinvokedecisiontool callresultstatemeasureApplicationTask + identityOpenAI Agents SDKAgent SDKModel providerConfigured API modelTool serviceAuthorization + executionState storageRun and thread progressEvaluationOutcome + evidence
  1. Authenticate the request and define the goal before calling the framework.

  2. A direct model-and-tools application with a clear runner abstraction. Decide how session state, tool authorization, and run limits will be managed.

  3. The application supplies provider credentials, model selection, and budgets.

  4. Validate each operation and return authoritative observations.

  5. Choose the checkpoint or session store and its retention policy deliberately.

    Result or stopping point
  6. Check completion, cost, latency, and tool behavior against fixtures.

    Result or stopping point
OpenAI Agents SDK

A direct model-and-tools application with a clear runner abstraction. Decide how session state, tool authorization, and run limits will be managed.

Follow the arrows, then select a component to inspect its responsibility. On mobile, downward arrows connect the next step; bent arrows identify branches and return paths. Select a destination to jump to that component.

When to consider it

  • A direct model-and-tools application with a clear runner abstraction.

A design decision to make

  • Decide how session state, tool authorization, and run limits will be managed.

Prerequisites and setup

  • Python 3.11+ in an empty directory. A compatible model and provider credentials are required.
  • Running the model-backed example can incur API charges; this website displays it without calling a provider.
  • Save the code at the displayed path, then use the corresponding run command.
Shell
python3 -m venv .venv
source .venv/bin/activate
python -m pip install openai-agents
export OPENAI_API_KEY="your-api-key"
export OPENAI_MODEL="your-enabled-model-id"

Try a small integration

agent.py

Python · agent.py
import asyncio
import os
from agents import Agent, Runner
from agents.decorators import tool

@tool
def lookup_order(order_id: str) -> str:
    """Read an order status from a local demonstration fixture."""
    orders = {"A104": "Packed; awaiting courier pickup"}
    return orders.get(order_id, "Order not found")

agent = Agent(
    name="Order assistant",
    model=os.environ["OPENAI_MODEL"],
    instructions=(
        "Use lookup_order for status questions. "
        "Report only the returned status; do not invent dates."
    ),
    tools=[lookup_order],
)

async def main():
    result = await Runner.run(
        agent, "What is the status of A104?", max_turns=5
    )
    print(result.final_output)

if __name__ == "__main__":
    asyncio.run(main())

Run and check the result

Shell
python agent.py
  • The answer reports that A104 is packed and awaiting courier pickup.
  • Ask about A999: it should report Order not found, without inventing a replacement record.

Common failures

  • 401: check which API project owns the key. A consumer chat subscription is separate from API access.
  • Model-not-found: select a model enabled for that API project. A turn-limit error means the loop did not finish within five turns.

Production decisions

  • Replace the local fixture with a service that enforces authenticated tenant and resource permissions.
  • Add timeouts, bounded retries, tracing redaction, and a regression case for each observed failure.
  • Model calls consume provider API usage when you run this example; this website only displays the code.
Read the OpenAI Agents SDK walkthrough

Keep exploring

Workflow, single agent, or multiple agents?Build an explicit agent loop with LangGraph

Explore the same layer

Claude Agent SDKGoogle ADKLangGraphLangChain

Compare candidates on your own workload. This entry describes a product’s role; it is not a claim that products in the category are interchangeable.