跳到主要内容

使用 OpenAI Agents SDK 进行追踪

OpenAI Agents SDK 允许你构建由 OpenAI 模型驱动的 Agent 应用。

安装

信息

需要 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.wrappers 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())

Agent 的执行流程,包括所有 span 及其详细信息,都将被记录到 LangSmith。

OpenAI Agents SDK Trace in LangSmith


此页是否对您有帮助?


您可以留下详细的反馈 在 GitHub 上.