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

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

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

2026/7/24 7:26:39 阅读更多 →
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/7/24 6:02:38 阅读更多 →

最新新闻

PCL2启动器终极指南:5大核心功能彻底解决你的Minecraft管理难题

PCL2启动器终极指南:5大核心功能彻底解决你的Minecraft管理难题

PCL2启动器终极指南:5大核心功能彻底解决你的Minecraft管理难题 【免费下载链接】PCL Minecraft 启动器 Plain Craft Launcher(PCL)。 项目地址: https://gitcode.com/gh_mirrors/pc/PCL 你是否曾经为了管理不同版本的Minecraft而手忙…

2026/7/25 1:01:59 阅读更多 →
战略咨询行业新标尺:聚焦企业实际经营成效的专业服务

战略咨询行业新标尺:聚焦企业实际经营成效的专业服务

在日益竞争的市场中,企业需要面对多变的挑战。专业服务正在发生变化:不再只停留在理论框架,而是通过具体案例推动解决方案,并关注长期目标。借助创新的方法与工具,咨询公司能够提供定制化的服务,并通过清晰…

2026/7/25 1:01:59 阅读更多 →
系统运维脚本:定时采集、定时备份、远程重启、磁盘空间监控

系统运维脚本:定时采集、定时备份、远程重启、磁盘空间监控

系统运维脚本:定时采集、定时备份、远程重启、磁盘空间监控工控设备部署在野外,你不可能天天往现场跑——运维自动化不是选择题,是必答题。一、工控运维为什么必须自动化 工业控制设备的典型运行环境:工厂车间、户外机柜、偏远站点…

2026/7/25 1:01:59 阅读更多 →
看门狗驱动与应用:硬件看门狗喂狗、死机自动重启机制实现

看门狗驱动与应用:硬件看门狗喂狗、死机自动重启机制实现

看门狗驱动与应用:硬件看门狗喂狗、死机自动重启机制实现你的工控板死机了,你人还在被窝里——这就是没有看门狗的代价。一、看门狗到底是什么 看门狗(Watchdog Timer,WDT)本质上是一个硬件倒计时器。启动后它开始从预…

2026/7/25 1:01:59 阅读更多 →
工控界面方案选型:QT5/QT6 轻量化窗口、无屏纯后台两种开发模式

工控界面方案选型:QT5/QT6 轻量化窗口、无屏纯后台两种开发模式

工控界面方案选型:QT5/QT6 轻量化窗口、无屏纯后台两种开发模式有些工控设备需要人机界面(HMI),有些就是闷头干活不带屏幕。选哪种方案?今天把两条路都铺开,让你少走弯路。一、工控设备两大模式 工控设备的…

2026/7/25 1:01:59 阅读更多 →
098、ESP-DL的安全加密案例

098、ESP-DL的安全加密案例

098、ESP-DL的安全加密案例:当模型部署遇上TLS握手失败 深夜两点,实验室的示波器还在跳着绿光。我盯着ESP32-S3的串口输出,一行刺眼的红色日志反复刷屏: E (2846) esp-tls: mbedtls_ssl_handshake returned -0x7780 E (2846) esp-tls: Failed to verify peer certificate…

2026/7/25 1:00:58 阅读更多 →

日新闻

突破文档下载限制:kill-doc让你看到的都能保存

突破文档下载限制:kill-doc让你看到的都能保存

突破文档下载限制:kill-doc让你看到的都能保存 【免费下载链接】kill-doc 看到经常有小伙伴们需要下载一些免费文档,但是相关网站浏览体验不好各种广告,各种登录验证,需要很多步骤才能下载文档,该脚本就是为了解决您的…

2026/7/25 0:00:35 阅读更多 →
C++ string类模拟实现:从深拷贝到内存管理的完整指南

C++ string类模拟实现:从深拷贝到内存管理的完整指南

1. 项目概述:为什么我们要“手撕”string类?在C的学习道路上,尤其是从C语言过渡到C的“初阶”阶段,string类绝对是一个绕不开的核心。标准库里的std::string用起来太方便了,、find、substr,几个操作符和函数…

2026/7/25 0:00:35 阅读更多 →
三角洲寻宝鼠工具:高效文件搜索与资源管理实战指南

三角洲寻宝鼠工具:高效文件搜索与资源管理实战指南

1. 先搞清楚“三角洲寻宝鼠”到底是什么工具从名称来看,“三角洲寻宝鼠”更像是一个资源查找或文件检索类工具,而不是游戏或娱乐软件。这类工具的核心价值在于帮助用户快速定位特定资源,比如文档、图片、压缩包或特定格式的文件。如果你经常需…

2026/7/25 0:00:35 阅读更多 →

周新闻

Go语言静态资源打包方案对比与实践指南

Go语言静态资源打包方案对比与实践指南

1. 项目背景与核心需求在Go语言开发中,我们经常需要处理静态资源文件的打包问题。无论是Web应用的模板文件、前端资源,还是配置文件、证书等,都需要随程序一起分发。传统做法是将这些文件与编译后的二进制文件放在同一目录下,但这…

2026/7/24 3:59:20 阅读更多 →
Go语言实现高性能LDAP认证服务的架构与实践

Go语言实现高性能LDAP认证服务的架构与实践

1. 项目背景与核心价值LDAP(轻量级目录访问协议)作为企业级身份认证的黄金标准,已经服务了超过80%的财富500强公司。我在金融科技领域实施统一认证体系时,发现传统Java方案存在启动慢、内存占用高等痛点。而Go语言凭借其协程并发模…

2026/7/24 1:23:39 阅读更多 →
【AI面试官实战指南】:用ChatGPT模拟10类高频技术岗面试,3天提升应答精准度92%

【AI面试官实战指南】:用ChatGPT模拟10类高频技术岗面试,3天提升应答精准度92%

更多请点击: https://intelliparadigm.com 第一章:AI面试官实战指南的核心价值与适用场景 AI面试官并非替代人类HR的“黑箱工具”,而是以可解释、可审计、可迭代的方式,赋能招聘全链路的关键基础设施。其核心价值在于将主观经验沉…

2026/7/24 18:52:18 阅读更多 →

月新闻