TOOL WIKI · AGENT SDKS
OpenAI Agents SDK
Defines agents and runs tool-use loops with support for handoffs and guardrails.
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
Authenticate the request and define the goal before calling the framework.
A direct model-and-tools application with a clear runner abstraction. Decide how session state, tool authorization, and run limits will be managed.
invokeTo 03 · Model providertool callTo 04 · Tool servicemeasureTo 06 · EvaluationThe application supplies provider credentials, model selection, and budgets.
decisionBack to 02 · OpenAI Agents SDKValidate each operation and return authoritative observations.
Choose the checkpoint or session store and its retention policy deliberately.
Result or stopping pointCheck completion, cost, latency, and tool behavior against fixtures.
Result or stopping point
A direct model-and-tools application with a clear runner abstraction. Decide how session state, tool authorization, and run limits will be managed.
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.
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
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
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.
Keep exploring
Explore the same layer
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.