Home › LLM apps & agents › OpenAI Agents SDK rules

OpenAI Agents SDK rules

Cursor rules for the OpenAI Agents SDK (Python 0.2x): agents, function tools, handoffs, guardrails, sessions, and tracing.

CursorLLM apps & agents

How to use

Save this as .cursor/rules/openai-agents.mdc in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

.cursor/rules/openai-agents.mdcDownload  
---
description: OpenAI Agents SDK conventions
globs: ["app/**/*.py","**/*agent*.py"]
alwaysApply: false
---

# OpenAI Agents SDK (Python)

- Imports from `agents`: `Agent`, `Runner`, `function_tool`, `handoff`, `input_guardrail`, `output_guardrail`, `SQLiteSession`. Pin the version in `pyproject.toml`; it's pre-1.0 and changes between minors.
- Define agents in `app/agents/*.py` with `name`, focused `instructions`, `model` from config, `tools`, and `output_type` (a Pydantic model) when you need structured results.
- Tools: `@function_tool` on typed functions with docstrings; the docstring and type hints become the schema. Validate inputs and return short, useful results. Tools with side effects require approval (`needs_approval=True` if available in your version, or a confirmation step).
- Handoffs for routing to specialist agents (`handoffs=[billing_agent, refunds_agent]`) with clear `handoff_description`s; use agents-as-tools (`agent.as_tool(...)`) when the caller should keep control.
- Guardrails: input guardrails for off-topic/abuse checks, output guardrails for policy; handle `InputGuardrailTripwireTriggered` / `OutputGuardrailTripwireTriggered`.
- Run with `await Runner.run(agent, input, session=session, max_turns=10)`; stream with `Runner.run_streamed` for UIs.
- Conversation memory via sessions (`SQLiteSession(user_id)` locally, a persistent backend in prod) rather than manually concatenating history.
- Keep tracing on in dev; disable or redact for sensitive data (`RunConfig(trace_include_sensitive_data=False)`).
- Use `context` (a typed dataclass passed to `Runner.run`) for dependencies like DB handles and the current user.

## Done when
`pytest` passes with tools tested directly and agent runs mocked or behind an opt-in flag.

More: all LLM apps & agents rules · all Cursor rules

Related rules

Claude Agent SDK CLAUDE.md

CLAUDE.md for building agents with the Claude Agent SDK (Python/TypeScript): options, tools, permissions, and hooks.

Claude Code (CLAUDE.md)LLM apps & agents

CrewAI multi-agent AGENTS.md

AGENTS.md for CrewAI 1.x projects: YAML agents and tasks, crews and flows, tools, and cost-aware runs.

AGENTS.mdLLM apps & agents

LangGraph agent rules

Cursor rules for building agents with LangGraph in Python: typed state, nodes, tools, checkpointers, and tests.

CursorLLM apps & agents

LLM app (Python) AGENTS.md

AGENTS.md for Python apps that call LLM APIs (OpenAI, Anthropic, Gemini): prompts, structured output, evals, and cost.

AGENTS.mdLLM apps & agents

Vercel AI SDK rules

Cursor rules for the Vercel AI SDK 5 in TypeScript: streamText, structured output, tools, and useChat UIs.

CursorLLM apps & agents

Jupyter notebook hygiene rules

Cursor rules for Jupyter notebooks in data projects: reproducible cells, small outputs, and moving code into modules.

CursorPython Data & ML

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.