ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

Sample Inputs

Sample Inputs Sample Inputs【免费下载链接】adk-pythonAn open-source, code-first Python toolkit for building, evaluating, and deploying sophisticated AI agents with flexibility and control.项目地址: https://gitcode.com/GitHub_Trending/ad/adk-pythonHello WorldADK workflowstesting concurrent nodes而带解释的写法来自 [readme-template.md](https://link.gitcode.com/i/301da51ced07421cd770d113a7158af4) 的模板 markdown - Prompt example 2 *Explanation or expected behavior*其中*Explanation or expected behavior*前有两个空格缩进且与提示词列表项之间隔了一个空行。这种格式在 Markdown 渲染后会形成提示词 附注的独立列表项对屏幕阅读器和 LLM 解析都更友好。另外需要注意并非所有样本都需要输入。例如 sequence/README.md 明确写着 This sample does not require any input to run.——如实说明即可不要硬凑提示词。Graph画结构拓扑而不是请求/响应时序Graph 小节是模板中最容易被误解的部分。模板的规则是A Mermaid diagram of the structure, not of the request/response flow.即画结构而非请求/响应流程。模板明确警告user - agent - API - tool - user这样的时序图是噪音它没有表达出拓扑图已经表达的任何信息。具体绘图规则分两种形态Workflow根 agent画节点与边的图nodes and edges。编排工具或子 agent 的 agentLlmAgent、ManagedAgent画该 agent 与其工具/子 agent 的拓扑而不是内部工作流节点。图中保持少量节点和边即可。仓库中的工作流样本都遵循了这一规则例如 dynamic_nodes/README.md它用虚线箭头-.-标注ctx.run_node的动态调用关系用实线箭头表达静态边用br/在节点内补充类型说明PYTHON FUNCTION让读者一眼看懂orchestrate 是驱动节点通过上下文动态调度两个 agent。再如 fan_out_fan_in/README.md三路并行分支汇入join_node节点标注 Waits for all 3再进入聚合节点。整个图不超过 6 个节点信息一目了然。How To展示样本用到的关键技术点How To 小节列出样本使用的关键技术例如ctx.run_node并附上展示每个技术点的少量关键代码行。目标是让读者不用通读整个agent.py就能抓住核心手法。以 dynamic_nodes/agent.py 为例其 How To 拆解为两个要点1. 启用可恢复性Python 节点若想使用ctx.run_node必须用node(rerun_on_resumeTrue)声明。这告诉引擎如果任何动态调度的节点被中断例如等待人工介入 human-in-the-loop编排节点需要暂停并可能重跑。from google.adk.workflow import node node(rerun_on_resumeTrue) async def orchestrate(ctx: Context, node_input: str) - str: # ...2. 从 Context 运行节点把ctx: Context注入 Python 节点定义await ctx.run_node(node_to_run)的返回值就是那次执行的最终输出循环内还可以用yield Event(state{...})在进入下一轮迭代前更新状态node(rerun_on_resumeTrue) async def orchestrate(ctx: Context, node_input: str) - str: yield Event(state{topic: node_input}) while True: headline await ctx.run_node(generate_headline) feedback Feedback.model_validate( await ctx.run_node(evaluate_headline, node_inputheadline) ) if feedback.grade tech-related: yield headline break再看 fan_out_fan_in/agent.py 对应的 How To定义JoinNodejoin_node JoinNode(namejoin_for_results)在edges中用元组先扇出、再经join_node扇入、最后交给聚合节点( START, (make_uppercase, count_characters, reverse_string), join_node, aggregate, )JoinNode之后的节点会收到一个dict作为输入键是上游节点名值是各自输出async def aggregate(node_input: dict[str, Any]): uppercase_result node_input[make_uppercase] # ...How To 的写作原则是少而准每个要点配几行能独立说明问题的代码而不是粘贴整个文件。更完整的图论语义如max_concurrency、rerun_on_resume覆盖规则应交由 Related Guides 中的指南文档承担。Related Guides指向 docs/guides/ 的链接与四级路径转换Related Guides 小节把样本与 docs/guides/README.md 下解释相关类的指南一一对应每个链接附带一行摘要。模板给出了路径计算的规则样本位于contributing/samples/{category}/{sample_name}/指南在docs/guides/下二者在仓库树中的相对关系是向上四级因此相对链接写法为- [Workflow](https://link.gitcode.com/i/0178e92c01dc459f56f8864ec349c721) - Explains building complex multi-step graphs.模板中的占位形式为- Guide Title - Brief description of what the guide covers.需要特别强调在输出面向仓库整体的文章时这类从样本目录出发的四级相对路径应转换为以仓库根目录为起点的路径即[Workflow](https://link.gitcode.com/i/c91656541202f31fdb11fb0158d0dd95)避免链接因解析基准不同而 404。实际样本可以链接的指南非常丰富从 docs/guides/README.md 的索引看与工作流样本直接相关的有Workflow —— 图驱动的多步 agent 编排含edges、max_concurrency、rerun_on_resume等配置项表格Workflow Graphs —— 节点、边与图结构以及运行前校验的九条规则Function Nodes —— 将普通 Python 函数与生成器包装为工作流节点JoinNode —— 同步并行执行路径Dynamic Nodes —— 运行时动态调度节点RetryConfig —— 为节点配置重试策略。Template可直接复制的空白骨架模板readme-template.md在文档末尾提供了完整可复制的 Markdown 骨架是新增样本 README 的起点# ADK Sample Name ## Overview Brief description. ## Sample Inputs - Prompt example 1 - Prompt example 2 *Explanation or expected behavior* ## Graph For a Workflow root agent: ![mermaid](https://web-api.gitcode.com/mermaid/svg/eNpLL0osyFAIceFSAILgEMegEAVdXTsF30q__JRUAHehCAc) For an agent orchestrating tools or sub-agents: ![mermaid](https://web-api.gitcode.com/mermaid/svg/eNpLL0osyFAIceFSAALfSsf01LyS6NzK-EQQI1ZBV9euJjkxJ6e4BigZkp-fowGUKwHSmgAglhOt) ## How To Explain the details. ## Related Guides - Guide Title - Brief description of what the guide covers.【免费下载链接】adk-pythonAn open-source, code-first Python toolkit for building, evaluating, and deploying sophisticated AI agents with flexibility and control.项目地址: https://gitcode.com/GitHub_Trending/ad/adk-python创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表