OpenAI Agents SDK 允许您构建由 OpenAI 模型驱动的智能体应用程序。 了解如何使用 OpenAI Agents SDK 和 LangSmith 跟踪您的 LLM 应用程序。

安装

需要 Python SDK 版本 langsmith>=0.3.15
安装支持 OpenAI Agents 的 LangSmith:
pip install "langsmith[openai-agents]"
这将安装 LangSmith 库和 OpenAI Agents SDK。

快速入门

您可以通过使用 OpenAIAgentsTracingProcessor 类将 LangSmith 跟踪与 OpenAI Agents SDK 集成。
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())
智能体的执行流程,包括所有跨度及其详细信息,都将记录到 LangSmith。 OpenAI Agents SDK Trace in LangSmith
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.