diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index e78de87f..00000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -name: Bug report -about: Report a bug -title: '' -labels: bug -assignees: '' - ---- - -### Please read this first - -- **Have you read the docs?**[Agents SDK docs](https://openai.github.io/openai-agents-python/) -- **Have you searched for related issues?** Others may have faced similar issues. - -### Describe the bug -A clear and concise description of what the bug is. - -### Debug information -- Agents SDK version: (e.g. `v0.0.3`) -- Python version (e.g. Python 3.10) - -### Repro steps - -Ideally provide a minimal python script that can be run to reproduce the bug. - - -### Expected behavior -A clear and concise description of what you expected to happen. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index 73586eaa..00000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project -title: '' -labels: enhancement -assignees: '' - ---- - -### Please read this first - -- **Have you read the docs?**[Agents SDK docs](https://openai.github.io/openai-agents-python/) -- **Have you searched for related issues?** Others may have had similar requests - -### Describe the feature -What is the feature you're requesting? How would it work? Please provide examples and details if possible. diff --git a/.github/ISSUE_TEMPLATE/model_provider.md b/.github/ISSUE_TEMPLATE/model_provider.md deleted file mode 100644 index b56cb24e..00000000 --- a/.github/ISSUE_TEMPLATE/model_provider.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -name: Custom model providers -about: Questions or bugs about using non-OpenAI models -title: '' -labels: bug -assignees: '' - ---- - -### Please read this first - -- **Have you read the custom model provider docs, including the 'Common issues' section?** [Model provider docs](https://openai.github.io/openai-agents-python/models/#using-other-llm-providers) -- **Have you searched for related issues?** Others may have faced similar issues. - -### Describe the question -A clear and concise description of what the question or bug is. - -### Debug information -- Agents SDK version: (e.g. `v0.0.3`) -- Python version (e.g. Python 3.10) - -### Repro steps -Ideally provide a minimal python script that can be run to reproduce the issue. - -### Expected behavior -A clear and concise description of what you expected to happen. diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md deleted file mode 100644 index 6c639d72..00000000 --- a/.github/ISSUE_TEMPLATE/question.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -name: Question -about: Questions about the SDK -title: '' -labels: question -assignees: '' - ---- - -### Please read this first - -- **Have you read the docs?**[Agents SDK docs](https://openai.github.io/openai-agents-python/) -- **Have you searched for related issues?** Others may have had similar requests - -### Question -Describe your question. Provide details if available. diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md deleted file mode 100644 index 0fdeab1e..00000000 --- a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +++ /dev/null @@ -1,18 +0,0 @@ -### Summary - - - -### Test plan - - - -### Issue number - - - -### Checks - -- [ ] I've added new tests (if relevant) -- [ ] I've added/updated the relevant documentation -- [ ] I've run `make lint` and `make format` -- [ ] I've made sure tests pass diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml deleted file mode 100644 index bf015247..00000000 --- a/.github/workflows/docs.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Deploy docs - -on: - workflow_run: - workflows: ["Tests"] - types: - - completed - -permissions: - contents: write # This allows pushing to gh-pages - -jobs: - deploy_docs: - if: ${{ github.event.workflow_run.conclusion == 'success' }} - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Setup uv - uses: astral-sh/setup-uv@v5 - with: - enable-cache: true - - name: Install dependencies - run: make sync - - name: Deploy docs - run: make deploy-docs diff --git a/.github/workflows/issues.yml b/.github/workflows/issues.yml deleted file mode 100644 index 6447f83e..00000000 --- a/.github/workflows/issues.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Close inactive issues -on: - schedule: - - cron: "30 1 * * *" - -jobs: - close-issues: - runs-on: ubuntu-latest - permissions: - issues: write - pull-requests: write - steps: - - uses: actions/stale@v9 - with: - days-before-issue-stale: 7 - days-before-issue-close: 3 - stale-issue-label: "stale" - stale-issue-message: "This issue is stale because it has been open for 7 days with no activity." - close-issue-message: "This issue was closed because it has been inactive for 3 days since being marked as stale." - any-of-issue-labels: 'question,needs-more-info' - days-before-pr-stale: 10 - days-before-pr-close: 7 - stale-pr-label: "stale" - stale-pr-message: "This PR is stale because it has been open for 10 days with no activity." - close-pr-message: "This PR was closed because it has been inactive for 7 days since being marked as stale." - repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index fa098204..00000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Publish to PyPI - -on: - release: - types: - - published - -permissions: - contents: read - -jobs: - publish: - environment: - name: pypi - url: https://pypi.org/p/openai-agents - permissions: - id-token: write # Important for trusted publishing to PyPI - runs-on: ubuntu-latest - env: - OPENAI_API_KEY: fake-for-tests - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Setup uv - uses: astral-sh/setup-uv@v5 - with: - enable-cache: true - - name: Install dependencies - run: make sync - - name: Build package - run: uv build - - name: Publish to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index edd0d898..00000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,88 +0,0 @@ -name: Tests - -on: - push: - branches: - - main - pull_request: - # All PRs, including stacked PRs - -env: - UV_FROZEN: "1" - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Setup uv - uses: astral-sh/setup-uv@v5 - with: - enable-cache: true - - name: Install dependencies - run: make sync - - name: Run lint - run: make lint - - typecheck: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Setup uv - uses: astral-sh/setup-uv@v5 - with: - enable-cache: true - - name: Install dependencies - run: make sync - - name: Run typecheck - run: make mypy - - tests: - runs-on: ubuntu-latest - env: - OPENAI_API_KEY: fake-for-tests - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Setup uv - uses: astral-sh/setup-uv@v5 - with: - enable-cache: true - - name: Install dependencies - run: make sync - - name: Run tests with coverage - run: make coverage - - build-docs: - runs-on: ubuntu-latest - env: - OPENAI_API_KEY: fake-for-tests - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Setup uv - uses: astral-sh/setup-uv@v5 - with: - enable-cache: true - - name: Install dependencies - run: make sync - - name: Build docs - run: make build-docs - - old_versions: - runs-on: ubuntu-latest - env: - OPENAI_API_KEY: fake-for-tests - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Setup uv - uses: astral-sh/setup-uv@v5 - with: - enable-cache: true - - name: Install dependencies - run: make sync - - name: Run tests - run: make old_version_tests diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 2e9b9237..00000000 --- a/.gitignore +++ /dev/null @@ -1,145 +0,0 @@ -# macOS Files -.DS_Store - -# Byte-compiled / optimized / DLL files -__pycache__/ -**/__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -cover/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -.pybuilder/ -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pdm -.pdm.toml -.pdm-python -.pdm-build/ - -# PEP 582 -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ -.venv39 -.venv_res - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# Cython debug symbols -cython_debug/ - -# PyCharm -.idea/ - -# Ruff stuff: -.ruff_cache/ - -# PyPI configuration file -.pypirc -.aider* diff --git a/examples/financial_research_agent/__init__.py b/.nojekyll similarity index 100% rename from examples/financial_research_agent/__init__.py rename to .nojekyll diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index 32ab3e75..00000000 --- a/.prettierrc +++ /dev/null @@ -1,11 +0,0 @@ -{ - "tabWidth": 4, - "overrides": [ - { - "files": "*.yml", - "options": { - "tabWidth": 2 - } - } - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 9b388533..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "python.testing.pytestArgs": [ - "tests" - ], - "python.testing.unittestEnabled": false, - "python.testing.pytestEnabled": true -} \ No newline at end of file diff --git a/404.html b/404.html new file mode 100644 index 00000000..bf925d2d --- /dev/null +++ b/404.html @@ -0,0 +1,942 @@ + + + +
+ + + + + + + + + + + + + + +Agents are the core building block in your apps. An agent is a large language model (LLM), configured with instructions and tools.
+The most common properties of an agent you'll configure are:
+instructions
: also known as a developer message or system prompt.model
: which LLM to use, and optional model_settings
to configure model tuning parameters like temperature, top_p, etc.tools
: Tools that the agent can use to achieve its tasks.from agents import Agent, ModelSettings, function_tool
+
+@function_tool
+def get_weather(city: str) -> str:
+ return f"The weather in {city} is sunny"
+
+agent = Agent(
+ name="Haiku agent",
+ instructions="Always respond in haiku form",
+ model="o3-mini",
+ tools=[get_weather],
+)
+
Agents are generic on their context
type. Context is a dependency-injection tool: it's an object you create and pass to Runner.run()
, that is passed to every agent, tool, handoff etc, and it serves as a grab bag of dependencies and state for the agent run. You can provide any Python object as the context.
@dataclass
+class UserContext:
+ uid: str
+ is_pro_user: bool
+
+ async def fetch_purchases() -> list[Purchase]:
+ return ...
+
+agent = Agent[UserContext](
+ ...,
+)
+
By default, agents produce plain text (i.e. str
) outputs. If you want the agent to produce a particular type of output, you can use the output_type
parameter. A common choice is to use Pydantic objects, but we support any type that can be wrapped in a Pydantic TypeAdapter - dataclasses, lists, TypedDict, etc.
from pydantic import BaseModel
+from agents import Agent
+
+
+class CalendarEvent(BaseModel):
+ name: str
+ date: str
+ participants: list[str]
+
+agent = Agent(
+ name="Calendar extractor",
+ instructions="Extract calendar events from text",
+ output_type=CalendarEvent,
+)
+
Note
+When you pass an output_type
, that tells the model to use structured outputs instead of regular plain text responses.
Handoffs are sub-agents that the agent can delegate to. You provide a list of handoffs, and the agent can choose to delegate to them if relevant. This is a powerful pattern that allows orchestrating modular, specialized agents that excel at a single task. Read more in the handoffs documentation.
+from agents import Agent
+
+booking_agent = Agent(...)
+refund_agent = Agent(...)
+
+triage_agent = Agent(
+ name="Triage agent",
+ instructions=(
+ "Help the user with their questions."
+ "If they ask about booking, handoff to the booking agent."
+ "If they ask about refunds, handoff to the refund agent."
+ ),
+ handoffs=[booking_agent, refund_agent],
+)
+
In most cases, you can provide instructions when you create the agent. However, you can also provide dynamic instructions via a function. The function will receive the agent and context, and must return the prompt. Both regular and async
functions are accepted.
def dynamic_instructions(
+ context: RunContextWrapper[UserContext], agent: Agent[UserContext]
+) -> str:
+ return f"The user's name is {context.context.name}. Help them with their questions."
+
+
+agent = Agent[UserContext](
+ name="Triage agent",
+ instructions=dynamic_instructions,
+)
+
Sometimes, you want to observe the lifecycle of an agent. For example, you may want to log events, or pre-fetch data when certain events occur. You can hook into the agent lifecycle with the hooks
property. Subclass the AgentHooks
class, and override the methods you're interested in.
Guardrails allow you to run checks/validations on user input, in parallel to the agent running. For example, you could screen the user's input for relevance. Read more in the guardrails documentation.
+By using the clone()
method on an agent, you can duplicate an Agent, and optionally change any properties you like.
pirate_agent = Agent(
+ name="Pirate",
+ instructions="Write like a pirate",
+ model="o3-mini",
+)
+
+robot_agent = pirate_agent.clone(
+ name="Robot",
+ instructions="Write like a robot",
+)
+
Supplying a list of tools doesn't always mean the LLM will use a tool. You can force tool use by setting ModelSettings.tool_choice
. Valid values are:
auto
, which allows the LLM to decide whether or not to use a tool.required
, which requires the LLM to use a tool (but it can intelligently decide which tool).none
, which requires the LLM to not use a tool.my_tool
, which requires the LLM to use that specific tool.Note
+To prevent infinite loops, the framework automatically resets tool_choice
to "auto" after a tool call. This behavior is configurable via agent.reset_tool_choice
. The infinite loop is because tool results are sent to the LLM, which then generates another tool call because of tool_choice
, ad infinitum.
If you want the Agent to completely stop after a tool call (rather than continuing with auto mode), you can set [Agent.tool_use_behavior="stop_on_first_tool"
] which will directly use the tool output as the final response without further LLM processing.