
01_quickstart/02_respond_directly_router_team.py【免费下载链接】agnoBuild, run, and manage agent platforms.项目地址: https://gitcode.com/GitHub_Trending/ag/agnoStatus:PASSDescription:Executed.venvs/demo/bin/python cookbook/03_teams/01_quickstart/02_respond_directly_router_team.py.Result:Executed successfully.- ### 后为示例文件相对路径相对 cookbook/03_teams/ - Status 为 PASS 或 FAIL - Description 说明执行方式FAIL 时标注 Validation issue: style 或 Validation issue: runtime - Result 给出运行结果失败时附带完整 Traceback。 以 [01_quickstart/05_team_history.py](https://link.gitcode.com/i/516812d952557df3022797d108fc8191) 为例其失败记录完整呈现了 API 变更导致的运行时错误TypeError: Team.init() got an unexpected keyword argument pass_user_input_to_members这说明该示例编写时所依赖的 Team 构造参数pass_user_input_to_members在当前仓库版本的 [libs/agno/agno/team/team.py](https://link.gitcode.com/i/fd138c606a867c837ed0fbaceb6130ee) 中已被移除或改名。对比当前示例源码[05_team_history.py](https://link.gitcode.com/i/516812d952557df3022797d108fc8191#L33-L48)可见现行参数为 respond_directlyTrue、determine_input_for_membersFalse、add_team_history_to_membersTrue —— 日志记录与示例源码形成了历史版本 vs 当前版本的对照证据。 ## 四、团队执行模式TeamMode源码解析 TEST_LOG 中 02_modes/ 目录下的示例按 broadcast、coordinate、route、tasks 四个子目录组织这正是 TeamMode 枚举定义的四种执行模式。查看 [libs/agno/agno/team/mode.py](https://link.gitcode.com/i/d3c3adbc63c5b271959e7731b40f3335) 源码 python class TeamMode(str, Enum): Execution mode for a Team. Controls how the team leader coordinates work with member agents. coordinate coordinate Default supervisor pattern. Leader picks members, crafts tasks, synthesizes responses. route route Router pattern. Leader routes to a specialist and returns the members response directly. broadcast broadcast Broadcast pattern. Leader delegates the same task to every member. arun runs the members concurrently; run runs them in sequence. tasks tasks Autonomous task-based execution. Leader decomposes goals into a shared task list, delegates tasks to members, and loops until all work is complete.四种模式的核心语义coordinate默认经典 supervisor 模式leader 挑选成员、构造任务、综合各成员响应后统一输出route路由模式leader 将请求转发给最合适的专家成员并直接返回该成员的响应broadcast广播模式leader 将同一任务分发给所有成员arun异步并发执行run同步串行执行tasks自主任务模式leader 将目标分解为共享任务列表逐项委派给成员并循环直至全部完成。TEST_LOG 的验证结果印证了这些模式的代码路径均可正常执行01_quickstart/broadcast_mode.py、01_quickstart/task_mode.py、01_quickstart/nested_teams.py均标记 PASS02_modes/下 16 个专项示例则全部因风格校验失败而标记 FAIL但Run: completed表明运行层面是完成的。五、Quickstart 核心示例深度解读01_quickstart/是 TEST_LOG 中验证最密集的目录12 个示例10 个 PASS。下面结合示例源码逐类说明。5.1 基础协调01_basic_coordination.py01_basic_coordination.py 演示最简双成员团队Planner规划任务、拆分步骤与Writer根据讨论撰写摘要共同协作。团队配置要点team Team( modelOpenAIResponses(idgpt-5-mini), namePlanning Team, members[planner, writer], instructions[ Coordinate with the two members to answer the user question., First plan the response, then generate a clear final summary., ], markdownTrue, show_members_responsesTrue, )关键参数members定义团队成员instructions指导 leader 的编排策略show_members_responsesTrue在输出中展示成员响应过程。该示例在 TEST_LOG 中标记 FAIL但失败原因为风格校验code_before_first_section_banner即代码块出现在首个章节横幅之前运行层面Run: completed不影响功能理解。5.2 路由团队02_respond_directly_router_team.pyPASS02_respond_directly_router_team.py 构建了一个多语言路由团队是modeTeamMode.route的典型实现6 个成员分别只使用一种语言作答leader 根据输入语言将请求路由到对应成员multi_language_team Team( nameMulti Language Team, modelOpenAIResponses(idgpt-5-mini), modeTeamMode.route, members[english_agent, spanish_agent, japanese_agent, french_agent, german_agent, chinese_agent], markdownTrue, instructions[ You are a language router that directs questions to the appropriate language agent., If the user asks in a language whose agent is not a team member, respond in English with: I can only answer in the following languages: ..., Always check the language of the users input before routing to an agent., ], show_members_responsesTrue, )示例同时演示同步print_response与异步aprint_responseasyncio.run两种调用方式并通过streamTrue开启流式输出。该示例在 TEST_LOG 中 PASS。5.3 广播协作03_delegate_to_all_members.pyPASS03_delegate_to_all_members.py 演示TeamMode.broadcastReddit Researcher与HackerNews Researcher两个成员同时研究同一主题leader 作为讨论主持人在达成共识时结束讨论。要点成员通过tools[WebSearchTools()]、tools[HackerNewsTools()]获得外部检索能力并通过add_name_to_contextTrue将自身名称注入上下文。5.4 带历史的路由团队04_respond_directly_with_history.pyPASS04_respond_directly_with_history.py 演示路由模式 会话历史的组合geo_search_team Team( nameGeo Search Team, modelOpenAIResponses(idgpt-5-mini), modeTeamMode.route, members[weather_agent, news_agent, activities_agent], instructionsYou are a geo search agent that can answer questions about the weather, news and activities in a city., use_instruction_tagsTrue, dbSqliteDb(db_filetmp/geo_search_team.db), # 存储会话历史 add_history_to_contextTrue, # 确保 leader 知晓之前的请求 )连续三次提问天气 → 该城市新闻 → 该城市活动验证了 leader 能跨轮次记住正在研究东京这一上下文。两个核心参数dbSqliteDb(...)持久化历史历史功能正常工作的前提add_history_to_contextTrue将历史注入 leader 上下文。5.5 团队历史共享05_team_history.pyFAILAPI 变更05_team_history.py 演示add_team_history_to_membersTrue将用户与团队的全部交互同步给成员。TEST_LOG 记录其因pass_user_input_to_members参数已不被Team.__init__接受而运行时失败——这是验证日志中最具价值的一类信息它标记了 cookbook 示例与当前 SDK 之间的 API 漂移。当前源码中该文件已改用respond_directlydetermine_input_for_membersadd_team_history_to_members组合读者以现行源码为准。六、PASS 示例分布通过率最高的功能域TEST_LOG 共记录125 个示例条目其中 62 个 PASS、63 个 FAIL约 46 个为纯风格校验问题约 17 个涉及运行时错误其中 4 个同时命中风格与运行时。以下功能域在验证中全部通过可作为低风险的上手路径会话持久化07_sessionchat_history.py、custom_session_summary.py、persistent_session.py、search_past_sessions.py、session_summary.py、share_session_with_agent.py共 6 个全 PASS仅session_options.py因未设置OPENAI_API_KEY失败属环境问题上下文管理09_context_managementadditional_context.py、custom_system_message.py、few_shot_learning.py、filter_tool_calls_from_history.py、introduction.py、location_context.py共 6 个全 PASS团队记忆06_memory01_team_with_memory_manager.py、02_team_with_agentic_memory.py、03_memories_in_context.py、learning_machine.py共 4 个全 PASS守卫18_guardrailsopenai_moderation.py、pii_detection.py、prompt_injection.py共 3 个全 PASS依赖注入17_dependenciesdependencies_in_context.py、dependencies_in_tools.py、dependencies_to_members.py共 3 个全 PASS流式08_streamingteam_events.py、team_streaming.py共 2 个全 PASS上下文压缩10_context_compressiontool_call_compression.py、tool_call_compression_with_manager.py共 2 个全 PASS运行控制14_run_controlcancel_run.py、model_inheritance.py、remote_team.py、retries.py共 4 个 PASS共享状态21_stateagentic_session_state.py、change_state_on_run.py、overwrite_stored_session_state.py、state_sharing.py共 4 个 PASS多模态19_multimodalaudio_sentiment_analysis.py、audio_to_text.py、generate_image_with_team.py、image_to_text.py共 4 个 PASS团队指标22_metrics01_team_metrics.pyPASS人机协同20_human_in_the_loopconfirmation_required.py、external_tool_execution.py、user_input_required.py共 3 个 PASS工具03_toolsmember_information.py、member_tool_hooks.py、tool_hooks.py共 3 个 PASS分布式 RAG15_distributed_rag01_distributed_rag_pgvector.pyPASSPgVector 路径无额外依赖。七、FAIL 失败模式分析四类典型问题与修复方向7.1 模式一风格校验失败数量最多运行本身完成这是 FAIL 的最大来源特征是Validation issue: style且Run: completed即脚本能跑通但未通过代码风格规则。TEST_LOG 中出现的规则名及含义missing_docstring_underlinedocstring 下方的下划线分隔线缺失常见于02_modes/全部 16 个示例、12_learning/全部 6 个示例及20_human_in_the_loop/9 个示例code_before_first_section_banner第一个章节横幅之前出现了代码块常见于01_quickstart/01_basic_coordination.py、13_hooks/2 个示例、05_knowledge/2 个示例等import_after_first_section_bannerimport 语句位于章节横幅之后如21_state/nested_shared_state.py、02_modes/coordinate/03_structured_output.py。修复方向为示例文件补齐docstring横幅规范、调整 import 与代码块的顺序。功能层面无需改动。7.2 模式二可选依赖未安装运行时 ImportErrorTEST_LOG 中多条运行时失败源于示例使用的外部库未安装且错误信息直接给出了安装命令。可归纳为下表缺失依赖触发路径安装命令来自报错相关示例tantivylibs/agno/agno/vectordb/lancedb/lance_db.py 全文检索初始化pip install tantivy15_distributed_rag/02、0305_knowledge/0116_search_coordination/01、02fal_clientlibs/agno/agno/tools/fal.pyFalTools导入pip install fal-client19_multimodal/image_to_image_transformation.pymoviepylibs/agno/agno/tools/moviepy_video.pyMoviePyVideoTools导入pip install moviepy ffmpeg19_multimodal/video_caption_generation.pye2b_code_interpreterlibs/agno/agno/tools/e2b.pyE2BTools导入pip install e2b_code_interpreter11_reasoning/reasoning_multi_purpose_team.pyinfinity_clientlibs/agno/agno/knowledge/reranker/infinity.pyInfinityReranker导入pip install infinity_client16_search_coordination/03_distributed_infinity_search.pyagentqllibs/agno/agno/tools/agentql.pyAgentQLTools导入pip install agentql03_tools/async_tools.py这类失败的判定方法Traceback 中若出现ModuleNotFoundError: No module named xxx且随后raise ImportError(...not installed. Please install using ...)即为可选依赖缺失按提示安装后即可复跑。其中tantivy出现次数最多5 个示例凡使用LanceDb向量库的示例都依赖它提供全文检索能力。7.3 模式三模型 API Key 未配置环境问题07_session/session_options.py、04_structured_input_output/json_schema_output.py等 5 个示例报OPENAI_API_KEY not set。日志中呈现的报错链路为Model authentication error from OpenAI API→Error in Team run→ 断言失败如AssertionError其中session_options.py还在set_session_name(autogenerateTrue)调用链libs/agno/agno/team/_session.py → libs/agno/agno/utils/agent.py 的set_session_name_util中中断。修复方式按 cookbook/03_teams/README.md 要求用direnv allow加载OPENAI_API_KEY后重跑。7.4 模式四API 兼容性变更示例滞后于 SDK01_quickstart/05_team_history.py报Team.__init__() got an unexpected keyword argument pass_user_input_to_members属于示例代码使用了已被移除的构造参数。这类失败无法通过装依赖或配环境解决需对照当前 libs/agno/agno/team/team.py 的Team签名更新示例参数该文件现行用法见 05_team_history.py。八、如何复现验证运行命令与操作流程TEST_LOG 中每条 PASS 记录都给出了可直接复用的运行命令统一模式为# 1. 加载环境变量例如 OPENAI_API_KEY direnv allow # 2. 使用 demo 虚拟环境运行目标示例 .venvs/demo/bin/python cookbook/03_teams/01_quickstart/02_respond_directly_router_team.py # 3. 如需复现失败示例例如分布式 RAG 全文检索先补齐依赖 pip install tantivy .venvs/demo/bin/python cookbook/03_teams/15_distributed_rag/02_distributed_rag_lancedb.py【免费下载链接】agnoBuild, run, and manage agent platforms.项目地址: https://gitcode.com/GitHub_Trending/ag/agno创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考