ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

在 Conductor 中运行 OpenAI Agents 构建的 Python Agent:framework bridge 实战指南

2026/9/10 1:00:00 拓冰建站 浏览量
在 Conductor 中运行 OpenAI Agents 构建的 Python Agent:framework bridge 实战指南 在 Conductor 中运行 OpenAI Agents 构建的 Python Agentframework bridge 实战指南【免费下载链接】conductorConductor is an event driven agentic workflow engine providing durable and highly resilient execution engine for applications and AI Agents项目地址: https://gitcode.com/GitHub_Trending/co/conductorConductor 是一个事件驱动的 agentic 工作流引擎为应用和 AI Agent 提供 durable持久化与高弹性的执行能力。本指南讲解如何把你已经用OpenAI Agents SDK写好的 Python Agent 原封不动地接入 Conductor只需修改一个 import即可让 Agent 以可检视的持久化执行inspectable durable execution方式运行。读完本文你将掌握conductor-python[openai-agents]的安装与配置、Runner.run/Runner.run_sync/Runner.run_streamed三种运行方式以及如何在 Conductor UI 中验证执行结果、排查失败任务。本文依据仓库中的官方指引文档 ui-next/src/pages/agent/guides/python/openai.md并结合 docs/quickstart/framework-agents.md、docs/quickstart/first-agent.md 等文档展开。为什么要把 Framework Agent 交给 Conductor 运行在 Bring Your Framework Agent 中明确说明这个场景面向已经用其他框架OpenAI Agents、LangChain、LangGraph、Google ADK 等构建好 Agent的开发者。你不必重写 Agent 对象——保留框架自己定义的 Agent由 Conductor SDK 将它编译并运行成一个 durable、可检视的 Conductor 执行you keep the agent object your framework already defines, and the Conductor SDK compiles and runs it as a durable, inspectable Conductor execution。这意味着 Agent 的每次运行都会留下一条完整的执行记录任务时间线、输入、输出、重试情况都能在 Conductor UI 中查看执行过程具备崩溃恢复与自动重试能力不再依赖一个常驻的长生命周期进程。这也是 Your First Agent 中强调的同一套 durable execution 模型。前置条件连接到 Conductor 服务器运行任何 Agent 之前先保证运行时可以访问到你的 Conductor 服务器。参考 Connect to Conductor使用 Orkes Developer Edition推荐创建账号与应用获取 access key然后导出export CONDUCTOR_SERVER_URLhttps://developer.orkescloud.com/api export CONDUCTOR_AUTH_KEYyour-access-key export CONDUCTOR_AUTH_SECRETyour-access-secret使用本地服务器需要 Java 21 与 Node.jsconductor server start export CONDUCTOR_SERVER_URLhttp://localhost:8080/api使用 Dockerdocker run --rm -p 8080:8080 conductoross/conductor:latest export CONDUCTOR_SERVER_URLhttp://localhost:8080/api同时要确保服务器能调用你的模型供应商Developer Edition 上需要把模型供应商添加为 AI/LLM integration本地服务器则在启动前导出供应商 API Key例如export OPENAI_API_KEYyour-openai-api-key conductor server start第一步安装并配置打开终端安装带 OpenAI Agents 支持扩展的 Conductor Python SDKpython -m pip install conductor-python[openai-agents]然后配置连接信息与默认模型export CONDUCTOR_SERVER_URL{{CONDUCTOR_SERVER_URL}} # For authenticated Conductor servers: # export CONDUCTOR_AUTH_KEYYOUR_AUTH_KEY # export CONDUCTOR_AUTH_SECRETYOUR_AUTH_SECRET export CONDUCTOR_AGENT_LLM_MODELopenai/gpt-4o-mini环境变量说明环境变量作用说明CONDUCTOR_SERVER_URLConductor 服务器 API 地址本地开发通常为http://localhost:8080/api托管版为对应 API 端点CONDUCTOR_AUTH_KEY/CONDUCTOR_AUTH_SECRET服务器认证凭据仅当服务器开启了认证如 Developer Edition时需要CONDUCTOR_AGENT_LLM_MODEL默认 LLM 模型标识形如openai/gpt-4o-miniSDK 默认使用的模型注意{{CONDUCTOR_SERVER_URL}}是文档模板占位符实际使用时请替换为你的真实服务器地址。Provider 凭据应放在环境或密钥系统中不要放进 workflow input见 docs/quickstart/first-agent.md。第二步只改一个 import运行你的 OpenAI Agent关键设计在于你不需要改变 OpenAI Agents SDK 的 Agent 构造方式唯一的改动是把 runner 的 import 从框架自带改为 Conductor 的from conductor.ai import Runner from agents import Agent agent Agent( namehaiku_agent, modelgpt-4o-mini, instructionsAnswer only in haiku., ) result Runner.run_sync(agent, Write about durable execution.) print(result.final_output) print(result.execution_id)保存为openai_agent.py后运行python openai_agent.py运行完成后程序会打印 Agent 的最终输出final_output以及这次执行的 IDexecution_id。后者可以让你在 Conductor UI 中精确定位到这条可检视的执行记录。Runner 的三种运行方式原文档明确指出Runner.run,Runner.run_sync, andRunner.run_streamedaccept existing OpenAI Agents SDK agents.也就是说conductor.ai.Runner提供了与 OpenAI Agents SDK 风格一致的三种入口且都接受你已有的 OpenAI Agents SDK Agent 对象Runner.run异步运行适用于 await 风格的调用场景Runner.run_sync同步阻塞运行适合脚本式、快速验证的场景上文的 haiku 示例即为此类Runner.run_streamed流式运行适用于需要边生成边消费输出如流式响应的场景。与 native Agent 示例 中AgentRuntime的runtime.run()不同OpenAI Agents 桥接走的是conductor.ai.Runner这一入口而无论哪种入口最终都是把 Agent 编译并运行为 durable 的 Conductor 执行从而获得 execution 记录与恢复能力。进阶示例带工具调用的天气 Agent仅仅能跑还不够Agent 的常见形态是携带工具function tool。框架桥接完整保留了 OpenAI Agents SDK 的function_tool装饰器能力参见 docs/quickstart/framework-agents.md 中的完整示例from conductor.ai import Runner from agents import Agent, function_tool function_tool def get_weather(city: str) - str: return f72F and sunny in {city} agent Agent( nameweather_assistant, modelgpt-4o-mini, tools[get_weather], instructionsYou are a helpful assistant., ) result Runner.run_sync(agent, Whats the weather in NYC?) print(result.final_output)这里的关键点Agent 的tools参数、instructions参数都沿用 OpenAI Agents SDK 的原生写法工具函数照常被 LLM 动态选择调用而整段 Agent 逻辑由 Conductor 以 durable 方式托管执行。如果你是从头新建 Agent而非迁移既有框架 Agent也可以参考 native 指南 使用conductor.ai.agents.Agent的原生方式。验证与故障恢复运行完python openai_agent.py之后务必回到 Conductor UI 做两件事参见 docs/quickstart/first-agent.md 的 Verify and recover 章节定位执行通过打印出的execution_id在 UI 中找到对应的执行记录确认其最终状态terminal status并检查任务时间线、输入与输出失败排查如果 Agent 无法触达模型优先检查 worker 环境中的服务器 URL 与模型供应商凭据CONDUCTOR_SERVER_URL、OPENAI_API_KEY等再进入该执行的失败任务中查看具体错误后重试。针对多框架场景docs/quickstart/framework-agents.md 还补充了一条重要运维纪律在未弄清操作的幂等性与恢复策略之前不要重试可能产生外部副作用的 Agent 动作。把 Agent 编排进工作流AGENT 任务Agent 调试通过、部署之后还可以被工作流作为AGENT任务调用——工作流负责持久的业务过程API 调用、检索、审批、重试、分支、并行Agent 负责其中模型驱动的决策或动作见 docs/quickstart/first-agent.md{ name: ask_agent, taskReferenceName: ask_agent_ref, type: AGENT, inputParameters: { agentType: conductor, name: greeter, prompt: Summarize this workflow context: ${fetch_context.output.response.body}, pollIntervalSeconds: 5 } }该任务会记录 Agent 的 execution ID、状态、文本与结构化输出运维人员可以同时检视父工作流与 Agent 运行。完整的工作流 Agent示例见 first-ai-agent.mdAGENT任务集成说明见 conductor-agents.md。相关资源本指南出处ui-next/src/pages/agent/guides/python/openai.md多框架 Agent 快速上手docs/quickstart/framework-agents.md连接 Conductor 服务器docs/quickstart/connect.md第一个 Agent原生方式docs/quickstart/first-agent.mdPython SDK 完整指南docs/documentation/clientsdks/python-sdk.md生产级 Agent 架构治理、评估、部署、运维docs/devguide/ai/production-agent-architecture.md可运行的 Agent 模式集handoffs、memory、guardrails、并行 Agent 等docs/devguide/ai/cookbook/index.md下一步你可以把 LangChain、LangGraph、Google ADK 等其他框架的 Agent 用同样方式接入 Conductor多语言、多框架的 Agent 将共享同一套 durable 执行与可观测性底座。【免费下载链接】conductorConductor is an event driven agentic workflow engine providing durable and highly resilient execution engine for applications and AI Agents项目地址: https://gitcode.com/GitHub_Trending/co/conductor创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考