You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将基于Python的Google ADK代理部署至Google Cloud Agent Engine?

基于Google ADK的AI Agent部署至Cloud Agent Engine指南

一、代理代码准备方法

  • 遵循ADK规范实现核心逻辑
    继承ADK提供的Agent基类,重写handle_request等关键方法,处理用户请求并返回结构化响应,示例核心代码片段:
    from google.adk import Agent
    
    class MyCustomAgent(Agent):
        def handle_request(self, request):
            user_query = request.get("query")
            return {"response": f"Received your query: {user_query}"}
    
    agent = MyCustomAgent()
    
  • 配置Agent元数据文件agent.yaml
    在代码根目录创建该文件,指定Agent的基础信息与运行配置:
    name: "my-custom-agent"
    description: "自定义AI代理示例"
    runtime: "python3.11"
    entrypoint: "main.py:agent"
    
  • 整理依赖清单requirements.txt
    包含google-adk及项目所需其他依赖:
    google-adk>=0.1.0
    # 其他项目依赖,如flask、requests等
    
  • 规范代码目录结构
    保持目录清晰,便于部署工具识别:
    my-agent-project/
    ├── main.py
    ├── agent.yaml
    └── requirements.txt
    

二、部署所需gcloud命令

  • 初始化gcloud环境(首次使用时执行)
    gcloud init
    
  • 设置目标Google Cloud项目
    gcloud config set project YOUR_PROJECT_ID
    
  • 部署Agent至Cloud Agent Engine
    gcloud agent-engine agents deploy my-custom-agent --source=./my-agent-project --region=us-central1
    
  • 查看Agent部署状态
    gcloud agent-engine agents describe my-custom-agent --region=us-central1
    
  • 调用已部署的Agent进行测试
    gcloud agent-engine agents invoke my-custom-agent --region=us-central1 --input='{"query": "测试请求"}'
    

内容的提问来源于stack exchange,提问作者Vidya Ravindran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 10:42:42