在 Conductor 中运行 Google ADK Agent:TypeScript 框架桥接实战指南
【免费下载链接】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
导读
本文介绍如何把使用 Google Agent Development Kit(ADK)编写的 LLM Agent,通过 Conductor 官方 TypeScript/JavaScript SDK 的框架桥接能力编译为持久的、可观测的 Conductor 执行,并最终部署为可在工作流中复用的 Conductor Agent。读完本文,你将掌握安装与环境变量配置、编写可运行的 ADK Agent 脚本、理解run/plan/deploy/serve生命周期,以及通过AGENT任务在工作流中调用已部署 Agent 的完整路径。
什么是框架桥接(Framework Bridge)
Conductor 是一个事件驱动的 Agentic 工作流引擎,为应用与 AI Agent 提供持久、高弹性的执行环境。框架桥接的核心理念是:你继续使用 Google ADK 编写 Agent 对象,Conductor SDK 负责把它编译成普通的工作流定义并在 Conductor 上执行。由于编译结果是工作流,每一次 LLM 调用、工具调用、等待、重试和分支都能在 Conductor UI 与 API 中完整可见(参见 Bring Your Framework Agent)。
TypeScript 生态下,@io-orkes/conductor-javascript包内置了 Google ADK 的支持:从@io-orkes/conductor-javascript/agents导入AgentRuntime,即可把@google/adk的LlmAgent交给它运行。同类桥接还覆盖 OpenAI Agents、LangChain、LangGraph 与 Vercel AI SDK,各语言入口可在 Agent Guides 清单 中查看。
第一步:安装与配置
安装 Conductor JavaScript SDK 与 Google ADK 两个依赖包:
npm install @io-orkes/conductor-javascript @google/adk随后配置运行环境变量。CONDUCTOR_SERVER_URL指向你的 Conductor 服务器({{CONDUCTOR_SERVER_URL}}为占位符,需替换为实际地址);对于需要认证的服务器,还需要提供访问密钥;CONDUCTOR_AGENT_LLM_MODEL指定 Agent 编译后在服务器端使用的 LLM 模型:
export CONDUCTOR_SERVER_URL={{CONDUCTOR_SERVER_URL}} # For authenticated Conductor servers: # export CONDUCTOR_AUTH_KEY=<YOUR_AUTH_KEY> # export CONDUCTOR_AUTH_SECRET=<YOUR_AUTH_SECRET> export CONDUCTOR_AGENT_LLM_MODEL=google_gemini/gemini-2.5-flash各环境变量的作用如下:
| 环境变量 | 作用 |
|---|---|
CONDUCTOR_SERVER_URL | Conductor 服务器 API 地址。使用 Orkes Developer Edition 时形如https://developer.orkescloud.com/api;本地服务器为http://localhost:8080/api(见 Connect to Conductor) |
CONDUCTOR_AUTH_KEY/CONDUCTOR_AUTH_SECRET | 访问受保护服务器所需的密钥对,仅对启用了认证的服务器必填 |
CONDUCTOR_AGENT_LLM_MODEL | Agent 的默认 LLM 模型,使用provider/model形式(此处为 Google Gemini 提供方下的gemini-2.5-flash) |
配置模型的另一条前提是服务器端能够调用你的模型提供商:Developer Edition 需要在 Integrations 中添加 AI/LLM 集成;自建本地服务器则需在启动前导出提供商的 API Key(例如export OPENAI_API_KEY=...),服务器继承该环境变量后即可调用模型(详见 framework-agents 前置要求)。
第二步:编写并运行 ADK Agent
将以下代码保存为adk-agent.ts:
import { LlmAgent } from "@google/adk"; import { AgentRuntime } from "@io-orkes/conductor-javascript/agents"; const agent = new LlmAgent({ name: "adk_greeter", model: "gemini-2.5-flash", instruction: "You are friendly and concise.", }); const runtime = new AgentRuntime(); try { const result = await runtime.run(agent, "Share a machine learning fact."); result.printResult(); } finally { await runtime.shutdown(); }代码要点:
LlmAgent是 Google ADK 提供的 LLM Agent 构造器,字段与原生 ADK 完全一致:name为 Agent 名称,model为模型名(此处为 Gemini),instruction为系统提示词。你完全可以继续用它添加tools、memory等 ADK 能力。AgentRuntime来自 Conductor SDK,是框架桥接的运行时入口。runtime.run(agent, prompt)会把 ADK Agent 编译为工作流图并在 Conductor 上执行一次,返回的结果对象通过printResult()打印。runtime.shutdown()放在finally中,确保进程退出前释放运行时资源。
使用tsx直接运行 TypeScript 文件:
npx tsx adk-agent.ts运行后,除了终端打印的结果,你还可以在 Conductor UI 中找到这次对应的持久执行记录,逐项查看 Agent 的每一步行为——这就是框架桥接相对直接调用模型的最大差异。
生命周期:从本地运行到生产部署
本地run只是起点。一个 ADK Agent 在 Conductor 中遵循统一的四步生命周期(详见 From framework object to workflow step):
- Run(迭代):开发期把 Agent 对象交给
AgentRuntime.run(),编译并执行一次,执行过程从第一次运行起就在 UI 中可见。 - Plan(检查):查看 Agent 将要编译成的工作流图,适合在 CI 中、任何部署动作之前做静态校验。
- Deploy(发布):把编译后的 Agent 注册到服务器,成为带名称与版本号的 Conductor Agent。此后调用方无需引入 Google ADK 及其依赖即可调用它。
- Serve(服务):启动 worker 进程执行 Agent 的工具。当 SDK 以本地函数方式运行工具时,必须保持该进程存活,才能支撑已部署 Agent 的持续调用。
部署后在 workflow 中调用
agentType决定执行模式而非编写框架:agentType: "conductor"表示运行一个按name选择的已部署 Conductor Agent,agentType: "a2a"(默认)则调用远程 A2A 端点。Google ADK 只是 SDK 的编写路径,并不是agentType取值。父工作流通过AGENT任务调用已部署 Agent,与调用其他持久步骤完全一致:
{ "name": "run_agent", "taskReferenceName": "run_agent_ref", "type": "AGENT", "inputParameters": { "agentType": "conductor", "name": "<deployed-agent-name>", "prompt": "${workflow.input.prompt}", "pollIntervalSeconds": 5 } }首次调用时name与prompt必填;version可固定版本(缺省使用最新版);sessionId、runId、context、media、model、timeoutSeconds、idempotencyKey按需使用,未提供幂等键时运行时自动创建重启稳定的幂等键。AGENT任务的输出包含executionId、agentName、state、text及完成后的结构化output,其state采用标准化 A2A 生命周期取值(working、input-required、completed、failed、canceled),详细状态映射见 Output and durable execution contract。服务器还需开启conductor.integrations.ai.enabled=true才能使用已部署 Agent 的控制面(见 Server requirement)。
从示例到真实场景:ADK 编排故障分诊
仓库中的 Google ADK 分诊 Cookbook 展示了更完整的实战形态:用 ADK 编写一个“订单异常分诊”Agent,它通过 MCP 工具获取证据、输出处置建议但绝不执行处置,再通过 Conductor SDK 部署与调用:
from conductor.ai.agents import AgentRuntime from google.adk.agents import Agent from google.adk.tools.mcp_tool import McpToolset, StreamableHTTPConnectionParams agent = Agent( name="adk_order_exception_triage", model="openai/gpt-4o", instruction="Use MCP evidence to recommend a disposition; never execute it.", tools=[McpToolset(connection_params=StreamableHTTPConnectionParams(url="http://127.0.0.1:3001/mcp"))], ) with AgentRuntime() as runtime: runtime.run(agent, "Order O-42 arrived damaged.")该示例同时给出了生产注意事项:agentType应取conductor而非adk;使用服务器实际配置的模型;限制工具访问与迭代预算;处置建议必须经过人工审批路由;按“订单 ID + 异常事件 ID”对账。这些原则同样适用于 TypeScript 场景。
多语言对照与进一步阅读
同样的桥接思路在各语言 SDK 中保持一致,便于团队跨栈复用:
- Python:
pip install 'conductor-python[adk]',从conductor.ai.agents导入AgentRuntime,见 Python Google ADK 指南; - Java:依赖
org.conductoross:conductor-ai与com.google.adk:google-adk,通过AdkBridge.toAgentspan(adkAgent)转换,见 Java Google ADK 指南; - TypeScript/JavaScript:即本文所述,
@io-orkes/conductor-javascript/agents的AgentRuntime。
遇到运行失败时,按 Verify and recover 的顺序排查:先核对运行时服务器 URL、框架包与提供商凭据,再在 UI 中定位失败任务后重试;若 Agent 动作可能产生外部副作用,需先明确幂等与恢复策略再重试。更完整的框架桥接参考、维护中的 SDK 示例矩阵与 AGENT 任务契约,可继续阅读 Framework Agents 与 Conductor Agents。
【免费下载链接】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),仅供参考