【LLM】Agents
Agents智能体是一个独立的执行单元旨在自主行动以实现特定目标。智能体可以执行任务、与用户互动、使用外部工具以及与其他智能体协调。基于BaseAgent扩展成LlmAgent、WorkflowAgent、CustomAgentLLM agentsLearn more about LLM Agents…code_writer_agent LlmAgent( nameCodeWriterAgent, modelGEMINI_MODEL, # Change 3: Improved instruction instructionYou are a Python Code Generator. Based *only* on the users request, write Python code that fulfills the requirement. Output *only* the complete Python code block, enclosed in triple backticks (python ... ). Do not add any other text before or after the code block. , descriptionWrites initial Python code based on a specification., output_keygenerated_code # Stores output in state[generated_code] )Workflow agentsLearn more about Workflow Agents…Sequential agentscode_pipeline_agent SequentialAgent( nameCodePipelineAgent, sub_agents[code_writer_agent, code_reviewer_agent, code_refactorer_agent], descriptionExecutes a sequence of code writing, reviewing, and refactoring., # The agents will run in the order provided: Writer - Reviewer - Refactorer )Loop agents# Part of agent.py -- Follow https://google.github.io/adk-docs/get-started/quickstart/ to learn the setup import asyncio import os from google.adk.agents import LoopAgent, LlmAgent, BaseAgent, SequentialAgent from google.genai import types from google.adk.runners import InMemoryRunner from google.adk.agents.invocation_context import InvocationContext from google.adk.tools.tool_context import ToolContext from typing import AsyncGenerator, Optional from google.adk.events import Event, EventActions # --- Constants --- APP_NAME doc_writing_app_v3 # New App Name USER_ID dev_user_01 SESSION_ID_BASE loop_exit_tool_session # New Base Session ID GEMINI_MODEL gemini-2.0-flash STATE_INITIAL_TOPIC initial_topic # --- State Keys --- STATE_CURRENT_DOC current_document STATE_CRITICISM criticism # Define the exact phrase the Critic should use to signal completion COMPLETION_PHRASE No major issues found. # --- Tool Definition --- def exit_loop(tool_context: ToolContext): Call this function ONLY when the critique indicates no further changes are needed, signaling the iterative process should end. print(f [Tool Call] exit_loop triggered by {tool_context.agent_name}) tool_context.actions.escalate True # Return empty dict as tools should typically return JSON-serializable output return {} # --- Agent Definitions --- # STEP 1: Initial Writer Agent (Runs ONCE at the beginning) initial_writer_agent LlmAgent( nameInitialWriterAgent, modelGEMINI_MODEL, include_contentsnone, # MODIFIED Instruction: Ask for a slightly more developed start instructionfYou are a Creative Writing Assistant tasked with starting a story. Write the *first draft* of a short story (aim for 2-4 sentences). Base the content *only* on the topic provided below. Try to introduce a specific element (like a character, a setting detail, or a starting action) to make it engaging. Topic: {{initial_topic}} Output *only* the story/document text. Do not add introductions or explanations. , descriptionWrites the initial document draft based on the topic, aiming for some initial substance., output_keySTATE_CURRENT_DOC ) # STEP 2a: Critic Agent (Inside the Refinement Loop) critic_agent_in_loop LlmAgent( nameCriticAgent, modelGEMINI_MODEL, include_contentsnone, # MODIFIED Instruction: More nuanced completion criteria, look for clear improvement paths. instructionfYou are a Constructive Critic AI reviewing a short document draft (typically 2-6 sentences). Your goal is balanced feedback. **Document to Review:** {{current_document}} **Task:** Review the document for clarity, engagement, and basic coherence according to the initial topic (if known). IF you identify 1-2 *clear and actionable* ways the document could be improved to better capture the topic or enhance reader engagement (e.g., Needs a stronger opening sentence, Clarify the characters goal): Provide these specific suggestions concisely. Output *only* the critique text. ELSE IF the document is coherent, addresses the topic adequately for its length, and has no glaring errors or obvious omissions: Respond *exactly* with the phrase {COMPLETION_PHRASE} and nothing else. It doesnt need to be perfect, just functionally complete for this stage. Avoid suggesting purely subjective stylistic preferences if the core is sound. Do not add explanations. Output only the critique OR the exact completion phrase. , descriptionReviews the current draft, providing critique if clear improvements are needed, otherwise signals completion., output_keySTATE_CRITICISM ) # STEP 2b: Refiner/Exiter Agent (Inside the Refinement Loop) refiner_agent_in_loop LlmAgent( nameRefinerAgent, modelGEMINI_MODEL, # Relies solely on state via placeholders include_contentsnone, instructionfYou are a Creative Writing Assistant refining a document based on feedback OR exiting the process. **Current Document:** {{current_document}} **Critique/Suggestions:** {{criticism}} **Task:** Analyze the Critique/Suggestions. IF the critique is *exactly* {COMPLETION_PHRASE}: You MUST call the exit_loop function. Do not output any text. ELSE (the critique contains actionable feedback): Carefully apply the suggestions to improve the Current Document. Output *only* the refined document text. Do not add explanations. Either output the refined document OR call the exit_loop function. , descriptionRefines the document based on critique, or calls exit_loop if critique indicates completion., tools[exit_loop], # Provide the exit_loop tool output_keySTATE_CURRENT_DOC # Overwrites state[current_document] with the refined version ) # STEP 2: Refinement Loop Agent refinement_loop LoopAgent( nameRefinementLoop, # Agent order is crucial: Critique first, then Refine/Exit sub_agents[ critic_agent_in_loop, refiner_agent_in_loop, ], max_iterations5 # Limit loops ) # STEP 3: Overall Sequential Pipeline # For ADK tools compatibility, the root agent must be named root_agent root_agent SequentialAgent( nameIterativeWritingPipeline, sub_agents[ initial_writer_agent, # Run first to create initial doc refinement_loop # Then run the critique/refine loop ], descriptionWrites an initial document and then iteratively refines it with critique using an exit tool. )Parallel agentsCustom agentsMulti-agent systems

相关新闻

Jellium Desktop睡眠模式控制:如何防止播放时电脑休眠

Jellium Desktop睡眠模式控制:如何防止播放时电脑休眠

Jellium Desktop睡眠模式控制:如何防止播放时电脑休眠 【免费下载链接】jellium-desktop An unofficial desktop client for Jellyfin 项目地址: https://gitcode.com/GitHub_Trending/je/jellium-desktop Jellium Desktop是一款非官方的Jellyfin桌面客户端&…

2026/9/23 2:11:10 阅读更多 →
深入解析L4总线互联:防火墙机制与错误处理实战指南

深入解析L4总线互联:防火墙机制与错误处理实战指南

1. 项目概述:为什么需要深入理解L4总线互联?在嵌入式系统,尤其是复杂的片上系统(SoC)设计中,我们常常会面对一个核心挑战:如何让一个或多个处理器核心(如Cortex-A8、DSP)…

2026/9/24 7:03:56 阅读更多 →
BitWHIP未来路线图:即将支持的x11grab与QuickSync编码功能

BitWHIP未来路线图:即将支持的x11grab与QuickSync编码功能

BitWHIP未来路线图:即将支持的x11grab与QuickSync编码功能 【免费下载链接】bitwhip CLI Native WebRTC Agent in Rust 项目地址: https://gitcode.com/gh_mirrors/bi/bitwhip BitWHIP作为一款基于Rust开发的CLI WebRTC Agent,正持续扩展其功能边…

2026/9/21 18:11:29 阅读更多 →

最新新闻

dirsearch工程化目录扫描实战:从配置到WAF绕过

dirsearch工程化目录扫描实战:从配置到WAF绕过

1. 为什么我坚持用 dirsearch 而不是其他目录扫描工具?在渗透测试、安全评估和日常资产梳理中,目录扫描从来不是“点开就扫”的傻瓜操作。它是一门需要平衡速度、隐蔽性、准确率和资源消耗的精细活。我从2016年开始接触这类工具,用过 dirb、g…

2026/9/25 7:28:50 阅读更多 →
甘肃排名前五的武术训练基地、少儿武术学校、武术学院用户力荐

甘肃排名前五的武术训练基地、少儿武术学校、武术学院用户力荐

甘肃很多想给孩子找正规武术学习平台的家长,都会搜:甘肃排名前五的武术训练基地有没有靠谱推荐?想找适合少儿的武术学校应该看哪些点?外地孩子去河南学武术,有没有用户力荐的正规院校?甘肃排名前五的武术训练基地有没有靠谱推荐?其实很多…

2026/9/25 7:28:50 阅读更多 →
Agenta SSTI漏洞深度解析:Jinja2沙箱逃逸与RCE利用链

Agenta SSTI漏洞深度解析:Jinja2沙箱逃逸与RCE利用链

1. 这不是普通模板注入:Agenta的{{ }}背后是沙箱逃逸RCE链的完整复现你有没有试过,在一个标榜“安全沙箱”的LLMOps平台里,只输入一行{{ 7*7 }},页面就返回了49——然后你顺手改成{{ .__class__.__mro__[2].__subclasses__() }}&a…

2026/9/25 7:28:50 阅读更多 →
OCS网课助手题库API配置全攻略:从原理到实战提升答题正确率

OCS网课助手题库API配置全攻略:从原理到实战提升答题正确率

1. 从“手动刷课”到“自动答题”:OCS网课助手到底在解决什么问题如果你正在看这篇文章,大概率是手里已经装了 OCS 网课助手,或者正准备装,卡在了“题库 API 怎么配”这一步。先说结论:OCS 本身只是一个“壳”&#xf…

2026/9/25 7:28:50 阅读更多 →
哈尔滨省考辅导机构选择指南:友恒公考客户口碑力荐

哈尔滨省考辅导机构选择指南:友恒公考客户口碑力荐

哈尔滨市南岗区友恒教育培训学校有限公司是一家深耕黑龙江公职考试培训的专业机构,依托12年本土教研经验,打造覆盖笔试、面试全链条的公考培训体系,适配国省联考、事业单位、选调生等多种公职考试备考需求。作为黑龙江本土正规办学的公考机构…

2026/9/25 7:28:50 阅读更多 →
FlexGen 仓库内 HuggingFace Transformers PyTorch 示例全指南:从任务清单到分布式训练与实验追踪

FlexGen 仓库内 HuggingFace Transformers PyTorch 示例全指南:从任务清单到分布式训练与实验追踪

推理引擎大模型 【免费下载链接】FlexGen Running large language models on a single GPU for throughput-oriented scenarios. 项目地址: https://gitcode.com/gh_mirrors/fl/FlexGen 点击查看 免费下载 本篇指南以 FlexGen 仓库中随附的 HuggingFace Transforme…

2026/9/25 7:27:50 阅读更多 →

日新闻

AI元人文:从工具使用到思维重构的深度探索

AI元人文:从工具使用到思维重构的深度探索

最近半年我一直在琢磨一件事:AI元人文到底是什么?说白了,就是“用元视角重新审视人与AI的关系”,也在“探索AI如何反向逼着我们发现自己的思考边界”。标题里的“元探索”,在我看就是一层套一层的追问——当你用AI解决…

2026/9/25 0:00:41 阅读更多 →
Python+CNN车牌识别实战:从数据预处理到模型训练与部署

Python+CNN车牌识别实战:从数据预处理到模型训练与部署

简介:基于Python与卷积神经网络的车牌识别项目,面向计算机视觉初学者及智能交通开发者,目标是帮助用户掌握从数据预处理、模型构建到实际部署的完整流程。压缩包共25个文件,包含jpg/png图像样本、py训练脚本、md说明文档、dat数据…

2026/9/25 0:00:41 阅读更多 →
Vim基础操作全攻略:保存退出、模式切换与高频命令实战

Vim基础操作全攻略:保存退出、模式切换与高频命令实战

1. 项目概述1.1 核心需求解析今天聊聊Vim。写这个题目的原因是:几乎每个后端开发者、运维人员、数据工程师某天都会遇到一个场景——深夜加班,服务器登录界面只有黑底白字,编辑器只有vi/vim,你必须在五分钟内完成一次配置修改并保…

2026/9/25 0:00:41 阅读更多 →

周新闻

Flutter for OpenHarmony游戏卡片渐变背景实战:从原理到性能优化

Flutter for OpenHarmony游戏卡片渐变背景实战:从原理到性能优化

直接铺开项目本身吧。这几个月我一直在折腾一件事:用Flutter给OpenHarmony做一款游戏集合类的App,说白了就是把若干小游戏塞进一个壳里,用统一入口分发。这个方向本身不算新鲜,真正让我花了不少心思的,是首页那堆游戏卡…

2026/9/24 14:34:13 阅读更多 →
Word表格编号全攻略:从列表编号到题注交叉引用

Word表格编号全攻略:从列表编号到题注交叉引用

写Word文档,最让人头疼的往往是那些“看起来不起眼”的小问题。比如表格编号这事:今天在表后面多加了两个空白行,明天给客户交稿前发现整个章节的编号全部错位,光是挨个改序号就能耗掉大半个下午。我前阵子帮人整理一份上百页的技…

2026/9/24 9:10:42 阅读更多 →
从第一个站到第二个站:独立开发者的静态网站选型与落地实践

从第一个站到第二个站:独立开发者的静态网站选型与落地实践

1. 项目概述1.1 核心需求解析做独立开发者这几年,说实话,第一个网站上线的那天晚上我兴奋得没睡着。但等它跑了半年,流量惨淡、功能臃肿、代码自己都懒得看第二遍之后,我才慢慢琢磨明白一个道理:第一个网站是练手&…

2026/9/24 14:33:56 阅读更多 →

月新闻

持续集成 流水线自动化与 声明式交付 实践:原型怎样变成可用功能

持续集成 流水线自动化与 声明式交付 实践:原型怎样变成可用功能

持续集成 流水线自动化与 声明式交付 实践:原型怎样变成可用功能分类:[AI/大模型]细分主题:AI 增强型 CI/CD 流水线自动化与 GitOps 实践:Agent 工作流、工具调用与任务拆解:从原型到生产的验收清单很多团队在尝试用大…

2026/9/24 12:50:34 阅读更多 →
容器编排 生产环境运维与排障实战:复盘记录怎样真正派上用场

容器编排 生产环境运维与排障实战:复盘记录怎样真正派上用场

容器编排 生产环境运维与排障实战:复盘记录怎样真正派上用场分类:[工程技术]细分主题:Kubernetes 生产环境运维与排障实战:可复制的项目复盘模板与决策记录大部分团队的事故复盘报告,最后都变成了躺在 Confluence 或钉…

2026/9/24 14:33:48 阅读更多 →
容器 容器化技术与镜像安全管理:核心链路应该先拆哪一步

容器 容器化技术与镜像安全管理:核心链路应该先拆哪一步

容器 容器化技术与镜像安全管理:核心链路应该先拆哪一步分类:[工程技术]细分主题:Docker 容器化技术与镜像安全管理:核心链路的逐步实现与关键代码取舍面对一个积累了五六年历史包袱的单体架构应用(包含 Web 接口、后台…

2026/9/24 12:49:17 阅读更多 →