Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.langchain.com/llms.txt

Use this file to discover all available pages before exploring further.

The OpenAI Agents SDK lets you build agentic applications powered by OpenAI models. Use LangSmith to trace OpenAI Agents SDK runs, including agent steps, model calls, tool calls, and handoffs.

Installation

Requires Python SDK version langsmith>=0.3.15.
Install LangSmith with OpenAI Agents support:
pip install "langsmith[openai-agents]"
This installs both the LangSmith library and the OpenAI Agents SDK.

Environment configuration

Shell
export LANGSMITH_API_KEY=<your-api-key>
export OPENAI_API_KEY=<your-openai-api-key>

# Optional: set a project for your traces
export LANGSMITH_PROJECT=<your-project-name>

# For LangSmith API keys linked to multiple workspaces, set the LANGSMITH_WORKSPACE_ID environment variable to specify which workspace to use.
export LANGSMITH_WORKSPACE_ID=<your-workspace-id>

Quick start

Integrate LangSmith tracing with the OpenAI Agents SDK by using the OpenAIAgentsTracingProcessor class.
import asyncio

from agents import Agent, Runner, set_trace_processors
from langsmith.integrations.openai_agents_sdk import OpenAIAgentsTracingProcessor


async def main():
    agent = Agent(
        name="Captain Obvious",
        instructions="You are Captain Obvious, the world's most literal technical support agent.",
    )

    question = "Why is my code failing when I try to divide by zero? I keep getting this error message."
    result = await Runner.run(agent, question)
    print(result.final_output)


if __name__ == "__main__":
    set_trace_processors([OpenAIAgentsTracingProcessor()])
    asyncio.run(main())
The agent’s execution flow, including spans and their details, is logged to LangSmith.