Google Cloud Agent Starter Pack

项目标题与描述

Google Cloud Agent Starter Pack 是一个专为Google Cloud设计的生成式AI代理模板集合。该项目旨在加速生成式AI代理的开发过程,提供从原型到生产的完整解决方案。

核心价值:

  • 提供多种预构建代理模板(ReAct、RAG、多代理、实时API等)
  • 内置Vertex AI评估和交互式测试环境
  • 生产级基础设施(监控、可观测性)
  • 支持快速定制和扩展

功能特性

核心功能

  • 多种代理模板:包括基础代理、研究代理、多模态代理等多种模板
  • 生产就绪架构:内置监控、日志和可观测性功能
  • 灵活的数据存储选项:支持Vertex AI Search和Vertex AI Vector Search
  • 自动化数据管道:自动化的数据摄取和处理流程
  • 开发工具集成:与LangChain、CrewAI等流行框架集成

特色代理

  • ADK基础代理:展示Agent Development Kit核心概念
  • 全栈研究代理:复杂的研究工作流,支持人机交互
  • 多模态实时代理:处理音频、视频和文本交互
  • RAG代理:增强检索能力的问答代理
  • CrewAI编码代理:协作式代码生成代理

安装指南

系统要求

  • Python 3.10+
  • Google Cloud SDK
  • Terraform (用于基础设施部署)

安装步骤

  1. 克隆仓库:

    git clone https://github.com/GoogleCloudPlatform/agent-starter-pack.git
    cd agent-starter-pack
    
  2. 安装依赖:

    make install
    
  3. 设置GCP项目:

    export GOOGLE_CLOUD_PROJECT=your-project-id
    gcloud config set project $GOOGLE_CLOUD_PROJECT
    
  4. 启用所需API:

    make enable-apis
    
  5. 部署基础设施:

    make deploy-infra
    

使用说明

基础使用

启动交互式测试环境:

make playground

运行数据摄取管道

export PROJECT_ID="your-project-id"
make data-ingestion

部署代理到Cloud Run

make deploy-cloud-run

API示例

基础代理调用示例:

from app.agent import root_agent

response = root_agent.invoke("What's the weather in San Francisco?")
print(response)

核心代码

基础代理实现

import datetime
import os
from zoneinfo import ZoneInfo

import google.auth
from google.adk.agents import Agent

_, project_id = google.auth.default()
os.environ.setdefault("GOOGLE_CLOUD_PROJECT", project_id)
os.environ.setdefault("GOOGLE_CLOUD_LOCATION", "global")
os.environ.setdefault("GOOGLE_GENAI_USE_VERTEXAI", "True")

def get_weather(query: str) -> str:
    """模拟天气查询"""
    if "sf" in query.lower() or "san francisco" in query.lower():
        return "It's 60 degrees and foggy."
    return "It's 90 degrees and sunny."

def get_current_time(query: str) -> str:
    """模拟时间查询"""
    if "sf" in query.lower() or "san francisco" in query.lower():
        tz_identifier = "America/Los_Angeles"
    else:
        return f"Sorry, I don't have timezone information for query: {query}."

    tz = ZoneInfo(tz_identifier)
    now = datetime.datetime.now(tz)
    return f"The current time for query {query} is {now.strftime('%Y-%m-%d %H:%M:%S %Z%z')}"

root_agent = Agent(
    name="root_agent",
    model="gemini-2.5-flash",
    instruction="You are a helpful AI assistant designed to provide accurate and useful information.",
    tools=[get_weather, get_current_time],
)

数据摄取管道

from kfp import dsl

@dsl.pipeline(description="Data ingestion pipeline into datastore")
def pipeline(
    project_id: str,
    location: str,
    is_incremental: bool = True,
    look_back_days: int = 1,
    chunk_size: int = 1500,
    chunk_overlap: int = 20,
    destination_table: str = "incremental_questions_embeddings",
    deduped_table: str = "questions_embeddings",
    destination_dataset: str = "stackoverflow_data",
    data_store_region: str = "",
    data_store_id: str = "",
) -> None:
    """Processes data and ingests it into a datastore for RAG Retrieval"""
    processed_data = process_data(
        project_id=project_id,
        schedule_time=dsl.PIPELINE_JOB_SCHEDULE_TIME_UTC_PLACEHOLDER,
        is_incremental=is_incremental,
        look_back_days=look_back_days,
        chunk_size=chunk_size,
        chunk_overlap=chunk_overlap,
        destination_dataset=destination_dataset,
        destination_table=destination_table,
        deduped_table=deduped_table,
        location=location,
        embedding_column="embedding",
    ).set_retry(num_retries=2)
    
    ingest_data(
        project_id=project_id,
        data_store_region=data_store_region,
        input_files=processed_data.output,
        data_store_id=data_store_id,
        embedding_column="embedding",
    ).set_retry(num_retries=2)

更多精彩内容 请关注我的个人公众号 公众号(办公AI智能小助手)
公众号二维码

posted @ 2025-07-09 22:01  qife  阅读(25)  评论(0)    收藏  举报