The OpenAI Agents SDK lets you build and run agents that call language models and custom tools; a minimal agent needs only a name and instructions, and can be executed synchronously with Runner.run_sync(). Function tools are registered via the @tool decorator and passed to an Agent's tools= parameter, letting agents autonomously call your code during execution.
Install the Agents SDK with pip install openai-agents (or an equivalent package-manager command such as uv add openai-agents).[1] Before running any agent, set your OpenAI API key in the OPENAI_API_KEY environment variable (e.g. export OPENAI_API_KEY=sk-...).[1]
A minimal agent is constructed by passing at least name and instructions to Agent; a specific model may also be set at construction time.[1] Running that agent synchronously requires only Agent and Runner from the agents package — call Runner.run_sync(agent, "<prompt>") and read result.final_output.[2]
Function tools are defined with the @tool decorator (from agents.decorators) and passed in the tools= list of an Agent.
from agents.decorators import tool
@tool
def history_fun_fact() -> str:
"""Return a short history fact."""
return "Sharks are older than trees."
agent = Agent(
name="History Tutor",
tools=[history_fun_fact],
)
Sources