【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/10/16 14:22:59 阅读更多 →
深入解析L4总线互联:防火墙机制与错误处理实战指南

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

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

2026/10/13 14:40:10 阅读更多 →
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/10/16 5:26:58 阅读更多 →

最新新闻

宝官并非稳赢:扑克牌概率、庄家优势与规则设计的数学真相

宝官并非稳赢:扑克牌概率、庄家优势与规则设计的数学真相

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/17 6:05:34 阅读更多 →
遥感影像传统分割:GDAL+scikit-image快速提取水体农田

遥感影像传统分割:GDAL+scikit-image快速提取水体农田

简介:本资源是一份面向遥感图像处理初学者与地理信息科学学习者的Python实践指南,聚焦于利用GDAL与scikit-image库完成遥感影像的传统图像分割、区域合并及初步矢量化全流程。资源以可运行代码为核心,完整实现影像读取(含地理坐标…

2026/10/17 6:05:34 阅读更多 →
OpenCV kmeans图像色彩量化实战:从原理到嵌入式部署

OpenCV kmeans图像色彩量化实战:从原理到嵌入式部署

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/17 6:05:34 阅读更多 →
用Unity框架为C语言工程搭建自动化单元测试与回归防线

用Unity框架为C语言工程搭建自动化单元测试与回归防线

简介:一份面向 C 语言开发者的自动测试入门资料,围绕轻量级测试框架 Unity 展开,重点解决测试代码与产品代码如何分离、测试容器如何生成、如何通过 make 一键编译运行等问题。文档首先给出 proj/src/test 的标准工程结构,并说明 …

2026/10/17 6:05:34 阅读更多 →
用Unity从零开发贪吃蛇2D:完整流程与避坑指南

用Unity从零开发贪吃蛇2D:完整流程与避坑指南

先别急着到处找教程,也别一上来就啃引擎官方文档。很多人第一次用Unity做小游戏,问我的第一句话通常是“到底做什么才能快速上手”。我一般只推荐一个答案:贪吃蛇2D。原因很简单,它足够小,但该有的东西一样不少。小到你…

2026/10/17 6:05:34 阅读更多 →
深入浅出Linux网卡驱动:DMA、NAPI与多队列调优

深入浅出Linux网卡驱动:DMA、NAPI与多队列调优

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/17 6:04:33 阅读更多 →

日新闻

DeepSeek选型与部署:V3/R1、Ollama、API全攻略

DeepSeek选型与部署:V3/R1、Ollama、API全攻略

简介:《DeepSeek使用方法.pdf》是一份面向DeepSeek入门及进阶用户的完整使用指南,重点围绕V3与R1两款模型的能力差异与适用场景展开,帮助读者根据任务类型与成本选择合适的模型。资源共1个PDF文件,压缩包大小约311KB,篇…

2026/10/17 0:00:25 阅读更多 →
200+Deepseek润色指令拆解:从底层原理到场景落地的完整指南

200+Deepseek润色指令拆解:从底层原理到场景落地的完整指南

简介:这是一份聚焦DeepSeek提示词优化的《200Deepseek润色指令》PDF文档,共收录两百余条可直接套用的润色指令,涵盖语法修正、风格统一、逻辑梳理、表达精炼等维度,并针对商务写作、学术论文、广告文案等场景给出差异化建议。文档…

2026/10/17 0:00:25 阅读更多 →
OpenCV轮廓法物体计数系统:轻量、可控、可落地的工业级实现

OpenCV轮廓法物体计数系统:轻量、可控、可落地的工业级实现

简介:本资源是一份基于OpenCV的本科课程设计完整报告,面向计算机视觉初学者、图像处理学习者及高校通信/信息类专业学生,解决物体智能计数与检测结果结构化记录的实际问题。项目覆盖图像预处理、轮廓检测、边界框绘制、轨迹栏交互式参数调节、…

2026/10/17 0:00:25 阅读更多 →

周新闻

流感时间序列预测实战:ARIMA/LSTM全流程拆解与避坑指南

流感时间序列预测实战:ARIMA/LSTM全流程拆解与避坑指南

简介:基于 ARIMA、LSTM、Transformer 等模型的流感时间序列预测 Python 源码,面向计算机相关专业课程设计与期末大作业学生,以及项目实战学习者。内容覆盖预处理、平稳性检验、定阶、残差分析、多模型对比预测的完整时序建模流程,…

2026/10/16 21:35:51 阅读更多 →
影刀RPA新手教程:键盘模拟输入实战——输入文本与模拟按键的区别

影刀RPA新手教程:键盘模拟输入实战——输入文本与模拟按键的区别

影刀RPA新手教程:键盘模拟输入实战——输入文本与模拟按键的区别 做影刀RPA自动化,十个新手有八个栽在"往输入框里填东西"这件事上:要么填不进去,要么填了一半,要么直接把原来内容追加在后面。这背后的根因&…

2026/10/17 1:44:59 阅读更多 →
影刀RPA新手教程:阅文起点小说数据采集实战——书籍信息与章节内容

影刀RPA新手教程:阅文起点小说数据采集实战——书籍信息与章节内容

影刀RPA新手教程:阅文起点小说数据采集实战——书籍信息与章节内容 1. 认识影刀:什么场景该用RPA采小说数据 起点中文网的页面结构相对稳定——分类榜单、书籍详情、章节内容三块独立页面,跳转链路清晰。这种场景非常适合影刀自动化&#x…

2026/10/16 15:04:24 阅读更多 →

月新闻

我发现了一个新思路:用 Remotion + Claude Code 像写代码一样自动化生成短视频

我发现了一个新思路:用 Remotion + Claude Code 像写代码一样自动化生成短视频

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/16 21:54:38 阅读更多 →
Windows下 Codex 中 Chrome 和 Computer Use 插件不可用问题排查及解决参考方式:TaoToken 统一 Key 配置与验证

Windows下 Codex 中 Chrome 和 Computer Use 插件不可用问题排查及解决参考方式:TaoToken 统一 Key 配置与验证

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/16 3:49:43 阅读更多 →
黑夜航拍船只数据集训练YOLOV5模型全流程解析

黑夜航拍船只数据集训练YOLOV5模型全流程解析

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/16 14:23:36 阅读更多 →