谷歌ai智能体解决方案:借助谷歌ADK在本地部署AI智能体

方法1

在Windows powershell中进行ADK的设定,这里第一步就是打开这个环境: .venv\Scripts\Activate.ps1,然后就是俭差我们安装的ADK:pip show google-adk

(base) PS C:\Users\Administrator> pip show google-adk
WARNING: Package(s) not found: google-adk
(base) PS C:\Users\Administrator> .venv\Scripts\Activate.ps1
(.venv) (base) PS C:\Users\Administrator> pip show google-adk
Name: google-adk
Version: 1.0.0
Summary: Agent Development Kit
Home-page: https://google.github.io/adk-docs/
Author:
Author-email: Google LLC <googleapis-packages@google.com>
License:
Location: C:\Users\Administrator\.venv\Lib\site-packages
Requires: authlib, click, fastapi, google-api-python-client, google-cloud-aiplatform, google-cloud-secret-manager, google-cloud-speech, google-cloud-storage, google-genai, graphviz, mcp, opentelemetry-api, opentelemetry-exporter-gcp-trace, opentelemetry-sdk, pydantic, python-dotenv, PyYAML, sqlalchemy, tzlocal, uvicorn
Required-by:
(.venv) (base) PS C:\Users\Administrator>

方法2 

这里有三种方法打开,所以这里我们不能同时开两个powershell,这里只能用一个Cmd来计算。这里使用:adk api_server来进行正常的运行。

(.venv) (base) PS C:\Users\Administrator> adk api_server
INFO:     Started server process [42140]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

创建新的会话

curl -X POST http://localhost:8000/apps/my_sample_agent/users/u_123/sessions/s_123 \
  -H "Content-Type: application/json" \
  -d '{"state": {"key1": "value1", "key2": 42}}'

 http://localhost:8000/apps/my_sample_agent/users/u_123/sessions/s_123 : 这会为您的代理 my_sample_agent 创建一个新的会话,其中 my_sample_agent 是代理文件夹的名称,用于用户 ID( u_123 )和会话 ID( s_123 )。您可以替换 my_sample_agent 为您的代理文件夹的名称。您可以替换 u_123 为一个特定的用户 ID,以及 s_123 为一个特定的会话 ID。

{"state": {"key1": "value1", "key2": 42}} : 这是可选的。您可以使用它来在创建会话时自定义代理的现有状态(dict)。

否则就会报错:

INFO:     Application shutdown complete.
(.venv) (base) PS C:\Users\Administrator> adk api_server
INFO:     Started server process [49508]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
ERROR:    [Errno 10048] error while attempting to bind on address ('127.0.0.1', 8000): [winerror 10048] 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。
INFO:     Waiting for application shutdown.
2025-05-28 15:01:16,837 - INFO - fast_api.py:262 - Server shutdown initiated, cleaning up 0 toolsets
2025-05-28 15:01:16,837 - INFO - fast_api.py:262 - Server shutdown initiated, cleaning up 0 toolsets
INFO:     Application shutdown complete.

无法进行分析

这里的主要问题是因为我们的网络的问题,需要检查我们的网络是否实现了科学上网。 

 

ADK 围绕几个关键的基础元素和概念构建,使其功能强大且灵活。以下是核心要素:

  • Agent: The fundamental worker unit designed for specific tasks. Agents can use language models (LlmAgent) for complex reasoning, or act as deterministic controllers of the execution, which are called "workflow agents" (SequentialAgentParallelAgentLoopAgent).
    智能体:为特定任务设计的根本工作单元。智能体可以使用语言模型( LlmAgent )进行复杂推理,或作为执行过程的确定性控制器,这些控制器被称为"工作流智能体"( SequentialAgent , ParallelAgent , LoopAgent )。
  • Tool: Gives agents abilities beyond conversation, letting them interact with external APIs, search information, run code, or call other services.
    工具:赋予代理超越对话的能力,使其能够与外部 API 交互、搜索信息、运行代码或调用其他服务。
  • Callbacks: Custom code snippets you provide to run at specific points in the agent's process, allowing for checks, logging, or behavior modifications.
    回调:您提供的自定义代码片段,用于在代理处理过程中的特定点执行,允许进行检查、记录或行为修改。
  • Session Management (Session & State): Handles the context of a single conversation (Session), including its history (Events) and the agent's working memory for that conversation (State).
    会话管理( Session & State ):处理单个对话( Session )的上下文,包括其历史( Events )以及该对话的代理工作内存( State )。
  • Memory: Enables agents to recall information about a user across multiple sessions, providing long-term context (distinct from short-term session State).
    记忆:使代理能够跨多个会话回忆有关用户的信息,提供长期上下文(与短期会话 State 不同)。
  • Artifact Management (Artifact): Allows agents to save, load, and manage files or binary data (like images, PDFs) associated with a session or user.
    工件管理( Artifact ):允许代理保存、加载和管理与会话或用户相关的文件或二进制数据(如图像、PDF)。
  • Code Execution: The ability for agents (usually via Tools) to generate and execute code to perform complex calculations or actions.
    代码执行:代理(通常通过工具)生成和执行代码以执行复杂计算或操作的能力。
  • Planning: An advanced capability where agents can break down complex goals into smaller steps and plan how to achieve them like a ReAct planner.
    规划:一种高级功能,代理可以将复杂目标分解为更小的步骤,并像 ReAct 规划器一样规划如何实现它们。
  • Models: The underlying LLM that powers LlmAgents, enabling their reasoning and language understanding abilities.
    模型:为 LlmAgent 提供动力的底层 LLM,使其具备推理和语言理解能力。
  • Event: The basic unit of communication representing things that happen during a session (user message, agent reply, tool use), forming the conversation history.
    事件:通信的基本单元,代表会话期间发生的事情(用户消息、代理回复、工具使用),形成对话历史。
  • Runner: The engine that manages the execution flow, orchestrates agent interactions based on Events, and coordinates with backend services.
    运行器:管理执行流程的引擎,根据事件协调代理交互,并与后端服务进行协调。

    ADK 围绕几个关键的基础元素和概念构建,使其功能强大且灵活。以下是核心要素:

  • Key Capabilities  主要功能 ¶

    ADK offers several key advantages for developers building agentic applications:
    ADK 为开发智能体应用程序提供了几个关键优势:

  • Multi-Agent System Design: Easily build applications composed of multiple, specialized agents arranged hierarchically. Agents can coordinate complex tasks, delegate sub-tasks using LLM-driven transfer or explicit AgentTool invocation, enabling modular and scalable solutions.
    多智能体系统设计:轻松构建由多个、分层的专业智能体组成的应用程序。智能体可以协调复杂任务,使用 LLM 驱动的转移或显式 AgentTool 调用来委派子任务,从而实现模块化和可扩展的解决方案。
  • Rich Tool Ecosystem: Equip agents with diverse capabilities. ADK supports integrating custom functions (FunctionTool), using other agents as tools (AgentTool), leveraging built-in functionalities like code execution, and interacting with external data sources and APIs (e.g., Search, Databases). Support for long-running tools allows handling asynchronous operations effectively.
    丰富的工具生态系统:为智能体配备多样化的功能。ADK 支持集成自定义函数( FunctionTool )、将其他智能体用作工具( AgentTool )、利用代码执行等内置功能,以及与外部数据源和 API(例如,搜索、数据库)交互。对长时间运行的工具的支持可以有效地处理异步操作。
  • Flexible Orchestration: Define complex agent workflows using built-in workflow agents (SequentialAgentParallelAgentLoopAgent) alongside LLM-driven dynamic routing. This allows for both predictable pipelines and adaptive agent behavior.
    灵活的编排:使用内置工作流智能体( SequentialAgent 、 ParallelAgent 、 LoopAgent )和 LLM 驱动的动态路由来定义复杂的工作智能体工作流程。这允许同时实现可预测的管道和自适应的智能体行为。
  • Integrated Developer Tooling: Develop and iterate locally with ease. ADK includes tools like a command-line interface (CLI) and a Developer UI for running agents, inspecting execution steps (events, state changes), debugging interactions, and visualizing agent definitions.
    集成开发者工具:轻松本地开发和迭代。ADK 包含命令行界面(CLI)和开发者 UI 等工具,用于运行代理、检查执行步骤(事件、状态变化)、调试交互以及可视化代理定义。
  • Native Streaming Support: Build real-time, interactive experiences with native support for bidirectional streaming (text and audio). This integrates seamlessly with underlying capabilities like the Multimodal Live API for the Gemini Developer API (or for Vertex AI), often enabled with simple configuration changes.
    原生流式支持:通过原生支持双向流式(文本和音频)构建实时交互体验。这可以与底层能力(如 Gemini 开发者 API 的 Multimodal Live API 或 Vertex AI)无缝集成,通常只需简单的配置更改即可启用。
  • Built-in Agent Evaluation: Assess agent performance systematically. The framework includes tools to create multi-turn evaluation datasets and run evaluations locally (via CLI or the dev UI) to measure quality and guide improvements.
    内置代理评估:系统性地评估代理性能。该框架包含创建多轮评估数据集的工具,并支持本地运行评估(通过 CLI 或开发者 UI),以衡量质量并指导改进。
  • Broad LLM Support: While optimized for Google's Gemini models, the framework is designed for flexibility, allowing integration with various LLMs (potentially including open-source or fine-tuned models) through its BaseLlm interface.
    广泛的 LLM 支持:虽然针对 Google 的 Gemini 模型进行了优化,但该框架设计灵活,允许通过其 BaseLlm 接口集成各种 LLM(可能包括开源或微调模型)。
  • Artifact Management: Enable agents to handle files and binary data. The framework provides mechanisms (ArtifactService, context methods) for agents to save, load, and manage versioned artifacts like images, documents, or generated reports during their execution.
    工件管理:使代理能够处理文件和二进制数据。框架提供了机制( ArtifactService ,上下文方法),供代理在执行期间保存、加载和管理版本化的工件,如图像、文档或生成的报告。
  • Extensibility and Interoperability: ADK promotes an open ecosystem. While providing core tools, it allows developers to easily integrate and reuse tools from other popular agent frameworks including LangChain and CrewAI.
    可扩展性和互操作性:ADK 推广开放生态系统。在提供核心工具的同时,它允许开发者轻松集成和重用来自其他流行代理框架的工具,包括 LangChain 和 CrewAI。
  • State and Memory Management: Automatically handles short-term conversational memory (State within a Session) managed by the SessionService. Provides integration points for longer-term Memory services, allowing agents to recall user information across multiple sessions.
    状态和内存管理:自动处理由 SessionService 管理的短期会话内存( State 在 Session 内)。提供与长期 Memory 服务的集成点,允许代理跨多个会话回忆用户信息。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

此星光明

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值