【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/8/17 2:39:35 阅读更多 →
深入解析L4总线互联:防火墙机制与错误处理实战指南

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

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

2026/8/15 12:42:28 阅读更多 →
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/8/18 16:24:49 阅读更多 →

最新新闻

Go对比Python asyncio,GPT-Live语音p95降至p50

Go对比Python asyncio,GPT-Live语音p95降至p50

将媒体前端用Go进行重写, GPT - Live语音的p95延迟直接降低到原系统的p50水平。历经六个月开发出第三代语音系统, 这第三代语音系统把turn从音频链路里完全剔除出去。下面这套架构成功地将推理延迟压制到了亚秒这个级别, 你到下半年通过使得 Agent 去运行长任务或者充当开展实时…

2026/8/19 11:07:53 阅读更多 →
基于ESP8266的百元级智能风扇DIY:从硬件选型到固件开发全解析

基于ESP8266的百元级智能风扇DIY:从硬件选型到固件开发全解析

1. 项目缘起:为什么我要自己动手做一台智能风扇?去年夏天,我卧室里那台服役多年的老风扇彻底罢工了。去商场转了一圈,发现带智能功能(比如手机控制、温湿度联动)的风扇,价格直接翻了好几倍&…

2026/8/19 11:07:53 阅读更多 →
Python 企业级自动化运维:服务器、数据库、监控、告警全自动化

Python 企业级自动化运维:服务器、数据库、监控、告警全自动化

解放运维涵盖, 服务器管理, 此管理涉及 SSH/方面, 还有数据库备份恢复工作, 以及日志分析、监控告警、配置变更、自动化巡检、故障自愈、报表生成、任务调度/这些内容。其技术包含, Redis Shell。解放运维:多维度的运维工作与关键技术支撑于当下数字化时期, 高…

2026/8/19 11:07:53 阅读更多 →
汽车行业变革下研发部门出售的驱动逻辑与员工应对策略

汽车行业变革下研发部门出售的驱动逻辑与员工应对策略

1. 从一则内部抗议说起:当“出售”成为悬在企业头顶的剑 最近,汽车圈里一则来自欧洲的消息引起了我的注意。不是关于某款新车的发布,也不是关于某项前沿技术的突破,而是一则关于企业内部动荡的新闻:欧宝(Op…

2026/8/19 11:07:53 阅读更多 →
拆解Deepseek Harness(一):一切皆可插件

拆解Deepseek Harness(一):一切皆可插件

DeepSeek Harness开源之后热度极速上升,主要源于其一切皆可插件的概念,市面上的主流Agent,如Claude Code ,Cursor等都是将Agent Loop,上下文管理,工具,Memory 等跟框架深度绑定,只支…

2026/8/19 11:07:53 阅读更多 →
Arduino蓝牙控制LED点阵屏:从硬件连接到滚动显示全解析

Arduino蓝牙控制LED点阵屏:从硬件连接到滚动显示全解析

1. 项目概述:一个能“说话”的蓝牙像素矩阵 最近在工作室捣鼓一个互动装置,核心想法很简单:做一个能通过手机蓝牙控制的LED点阵屏,让它不仅能显示静态图案,还能滚动播放我发送过去的任何文字。听起来像是智能家居里那种…

2026/8/19 11:06:53 阅读更多 →

日新闻

【单片机课程设计/毕业设计】基于 STM32 与 WiFi 模块的室内通风智能管控系统设计 基于 STM32 的人体存在感知自适应风扇控制系统设计(018503)

【单片机课程设计/毕业设计】基于 STM32 与 WiFi 模块的室内通风智能管控系统设计 基于 STM32 的人体存在感知自适应风扇控制系统设计(018503)

博主介绍:✌️码农一枚 ,专注于大学生项目实战开发、讲解和毕业🚢文撰写修改等。全栈领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于嵌入式单片机,Java、小程序技术领域和毕业项目实战 ✌️…

2026/8/19 0:00:30 阅读更多 →
AI如何驱动数学猜想生成:从大语言模型到自动化数学发现

AI如何驱动数学猜想生成:从大语言模型到自动化数学发现

1. 项目概述:当AI开始“猜”数学定理 最近在AI研究圈里,一个名为“Moonshine”的项目引起了不小的讨论。这名字本身就挺有意思,直译是“月光”,但在数学史上,它特指一个神秘而美丽的联系——魔群月光猜想,连…

2026/8/19 0:00:30 阅读更多 →
WarcraftHelper 魔兽争霸3优化实战指南

WarcraftHelper 魔兽争霸3优化实战指南

WarcraftHelper 魔兽争霸3优化实战指南 【免费下载链接】WarcraftHelper Warcraft III Helper , support 1.20e, 1.24e, 1.26a, 1.27a, 1.27b 项目地址: https://gitcode.com/gh_mirrors/wa/WarcraftHelper 一台刚配的新电脑,跑《魔兽争霸3》却卡成 PPT——这…

2026/8/19 0:02:31 阅读更多 →

周新闻

基于阿里云与通义千问(Qwen)构建AI应用:从模型调用到生产部署的完整实践指南

基于阿里云与通义千问(Qwen)构建AI应用:从模型调用到生产部署的完整实践指南

如果你是一名开发者,最近可能已经感受到了AI大模型正在从“玩具”变成“生产力工具”的强烈信号。从代码补全到智能Agent,从本地部署到云端API,我们正处在一个技术栈快速重构的节点。然而,面对层出不穷的模型、框架和工具&#xf…

2026/8/18 9:15:35 阅读更多 →
工业通信系统底层逻辑:04 反射——高频能量撞墙之后会发生什么?

工业通信系统底层逻辑:04 反射——高频能量撞墙之后会发生什么?

第四篇:反射——高频能量撞墙之后会发生什么? —— 你以为信号已经过去了,其实它正在回来打你 老Q的现场笔记 第五季,我们正式进入工业神经系统层。这里不再是单个设备的战斗,而是整个工厂“经脉”层面的秩序之战。从这一篇开始,你将第一次看清:看似简单的信号传播,背…

2026/8/19 9:46:27 阅读更多 →
【文章复现】非线性值迭代自适应动态规划(ADP):离散时间非线性系统的策略迭代自适应动态规划算法研究附Matlab代码

【文章复现】非线性值迭代自适应动态规划(ADP):离散时间非线性系统的策略迭代自适应动态规划算法研究附Matlab代码

✅作者简介:热爱科研的Matlab仿真开发者,擅长毕业设计辅导、数学建模、数据处理、建模仿真、程序设计、完整代码获取、论文复现及科研仿真。🍎 往期回顾关注个人主页:Matlab科研工作室👇 关注我领取海量matlab电子书和…

2026/8/18 9:04:56 阅读更多 →

月新闻

免费解锁百度网盘SVIP加速:macOS用户必备的下载提速终极指南

免费解锁百度网盘SVIP加速:macOS用户必备的下载提速终极指南

免费解锁百度网盘SVIP加速:macOS用户必备的下载提速终极指南 【免费下载链接】BaiduNetdiskPlugin-macOS For macOS.百度网盘 破解SVIP、下载速度限制~ 项目地址: https://gitcode.com/gh_mirrors/ba/BaiduNetdiskPlugin-macOS 还在为百度网盘macOS版的龟速下…

2026/8/19 5:04:55 阅读更多 →
终极ncmdump指南:3分钟实现网易云NCM音乐解密与格式转换

终极ncmdump指南:3分钟实现网易云NCM音乐解密与格式转换

终极ncmdump指南:3分钟实现网易云NCM音乐解密与格式转换 【免费下载链接】ncmdump 项目地址: https://gitcode.com/gh_mirrors/ncmd/ncmdump 还在为网易云音乐下载的NCM格式文件无法在其他播放器播放而烦恼吗?ncmdump解密工具帮你轻松解决这个困…

2026/8/19 7:42:22 阅读更多 →
HarmonyOS 应用开发《掌上英语》第81篇: 智能体卡片:为英语学习 App 打造桌面级学习助手

HarmonyOS 应用开发《掌上英语》第81篇: 智能体卡片:为英语学习 App 打造桌面级学习助手

AgentCard 智能体卡片:为英语学习 App 打造桌面级学习助手适用平台:HarmonyOS 7.0 (API 26 Beta)一、引言 HarmonyOS 7.0(API 26 Beta)新增了 AgentCard 智能体卡片能力,这是继 HMAF(鸿蒙智能体框架&#x…

2026/8/17 18:55:55 阅读更多 →