教程9.1:顺序代理——商业实施计划生成器


文档摘要

教程 9.1:顺序代理——商业实施计划生成器 您将学到的内容 顺序代理的组合:如何按顺序协调多个专业代理 代理工具集成:将代理封装为工具以增强功能 网络搜索集成:通过搜索代理获取实时市场情报 商业分析流程:从市场研究到实施规划 Streamlit Web 界面:用于商业规划的用户友好型应用 核心概念:具备搜索能力的顺序代理 根据ADK 工作流代理文档的描述,顺序代理会依次执行多个子代理。本教程展示了一个结合了网络搜索功能与顺序分析的商业实施计划生成器: 关键创新:市场研究代理使用了一个专门的搜索代理(封装为代理工具),以访问实时网络搜索功能,获取当前的市场情报。

教程 9.1:顺序代理——商业实施计划生成器

您将学到的内容

  • 顺序代理的组合:如何按顺序协调多个专业代理
  • 代理工具集成:将代理封装为工具以增强功能
  • 网络搜索集成:通过搜索代理获取实时市场情报
  • 商业分析流程:从市场研究到实施规划
  • Streamlit Web 界面:用于商业规划的用户友好型应用

核心概念:具备搜索能力的顺序代理

根据ADK 工作流代理文档的描述,顺序代理会依次执行多个子代理。本教程展示了一个结合了网络搜索功能与顺序分析的商业实施计划生成器

Business Topic → SequentialAgent → 4 Sub-agents (Sequential Execution) ↓ [Market Research + Web Search] → [SWOT Analysis] → [Strategy] → [Implementation] ↓ Complete Business Implementation Plan

关键创新:市场研究代理使用了一个专门的搜索代理(封装为代理工具),以访问实时网络搜索功能,获取当前的市场情报。

项目结构

9_1_sequential_agent/ ├── agent.py # Business implementation plan generator with search capabilities ├── app.py # Streamlit web interface for business planning ├── requirements.txt # Python dependencies └── README.md # This documentation

开始使用

1. 安装依赖项

cd 9_1_sequential_agent pip install -r requirements.txt

2. 设置环境

创建一个 .env 文件,并在其中填写您的 Google API 密钥:

echo "GOOGLE_API_KEY=your_ai_studio_key_here" > .env

重要提示:请从 Google AI Studio 获取您的 API 密钥

3. 运行 Streamlit 应用

streamlit run app.py

这将启动商业实施计划生成器代理的 Web 界面!

工作原理

商业实施计划生成流程

该代理通过一套复杂的四步顺序工作流处理商业机会:

  1. ** 市场分析**——利用网络搜索获取当前市场信息和竞争研究
  2. ** SWOT 分析**——对优势、劣势、机会和威胁进行战略评估
  3. ** 战略制定**——确定战略目标与行动方案
  4. ** 实施规划**——制定详细的执行路线图与资源需求

关键创新:市场分析代理可访问一个专门的搜索代理(封装为代理工具),该代理能够使用 google_search tool. This provides current market intelligence that feeds into the sequential analysis pipeline.

The SequentialAgent ensures each step builds upon the previous step's output, creating a comprehensive business implementation plan ready for execution.

Result: A complete business implementation plan with market research, strategic analysis, and execution roadmap.

ADK Concepts Demonstrated

1. SequentialAgent Pattern

The core workflow orchestrator that executes sub-agents in sequence, ensuring each step builds upon the previous step's output.

2. AgentTool Integration

Advanced pattern where one agent (Search Agent) is wrapped as a tool and used by another agent (Market Researcher) to enhance capabilities.

3. Web Search Capabilities

Real-time market intelligence through integrated search functionality, providing current data rather than relying on training data.

4. Sub-agent Specialization

Each sub-agent specializes in a specific business analysis phase, creating a modular and maintainable system.

5. Session Management

Maintains conversation state across the entire analysis pipeline, ensuring context flows between agents.

6. Runner Execution

Processes the complete business implementation workflow with proper error handling and response management.

Sample Topics to Try

  • Electric vehicle charging stations in urban areas
  • AI-powered healthcare diagnostics and patient care
  • Sustainable food delivery services and packaging
  • Remote work collaboration tools and platforms
  • Renewable energy storage solutions

Expected Output

The sequential agent will provide:

  1. Market Research: Competitive analysis and market trends
  2. SWOT Analysis: Strategic assessment with actionable insights
  3. Strategy Plan: Clear objectives and implementation steps
  4. Implementation Roadmap: Practical execution guidance

Learning Objectives

  • ✅ Understand how SequentialAgent orchestrates sub-agents
  • ✅ Learn to execute sequential agents with Runner and Session management
  • ✅ See how sub-agents can build upon each other's output
  • ✅ Experience a working, executable sequential workflow
  • ✅ Understand AgentTool integration for enhanced capabilities

Next Steps

  • Try different business topics to see the sequential workflow in action
  • Experiment with reordering the sub-agents
  • Add more specialized agents to the pipeline
  • Explore other ADK workflow patterns (Parallel, Branching)

Troubleshooting

Common Issues:

  • API Key Error: Ensure GOOGLE_API_KEY is set in .env
  • Import Errors: Make sure you're in the correct directory
  • Search Tool Errors: Verify your API key has access to search capabilities

Pro Tips:

  • Start with simple topics to understand the flow
  • Use the Streamlit app for easy testing and visualization
  • The sequential pattern is great for predictable, step-by-step processes
  • Web search integration provides real-time market intelligence

Key Takeaways

  • SequentialAgent is perfect for workflows that must happen in order
  • AgentTool integration allows agents to enhance each other's capabilities
  • Web search capabilities provide current market intelligence
  • Sub-agents can be simple LlmAgent 实例或复杂工具驱动的代理进行实时网络搜索。
  • 简洁、易读的代码使理解和修改变得轻松
  • Streamlit 界面为用户提供友好的方式来访问复杂的代理工作流

免责声明
本文档采用基于机器的 AI 翻译服务进行翻译。尽管我们力求准确,但请注意,自动翻译可能存在错误或不准确之处。应以原文语言版本的文档作为权威依据。如需获取关键信息,建议使用专业的人工翻译。对于因使用本翻译而产生的任何误解或误读,我们概不负责。


发布者: 作者: 转发
评论区 (0)
U