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

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

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

2026/7/22 18:11: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/7/22 18:11:28 阅读更多 →

最新新闻

Gazelle高性能用户态网络协议栈:解锁数据库网络性能20%+的加速秘诀

Gazelle高性能用户态网络协议栈:解锁数据库网络性能20%+的加速秘诀

Gazelle高性能用户态网络协议栈:解锁数据库网络性能20%的加速秘诀 【免费下载链接】gazelle A high performance user-mode stack, which powered by dpdk and lwip 项目地址: https://gitcode.com/openeuler/gazelle Gazelle作为openEuler社区的高性能用户态…

2026/7/22 19:03:46 阅读更多 →
老师傅30分钟拆一台设备,新人拆了3小时——差距不在手上,在经验传承

老师傅30分钟拆一台设备,新人拆了3小时——差距不在手上,在经验传承

设备故障,车间主任第一个电话打给老张。老张到场,听声音、看现象、摸管路,30分钟搞定。换新人上,对着图纸翻半天,螺丝型号没认全、拆装顺序拿不准、工具选错两回。3小时过去还没拆到位——这3小时里,整条产…

2026/7/22 19:03:46 阅读更多 →
TI C28x DSP McBSP多通道与SPI模式配置实战指南

TI C28x DSP McBSP多通道与SPI模式配置实战指南

1. 项目概述与核心价值在嵌入式系统和数字信号处理(DSP)的开发中,串行通信接口是连接处理器与外部世界(如传感器、存储器、其他处理器)的血管。我接触过不少项目,从简单的传感器数据采集到复杂的多通道音频…

2026/7/22 19:03:46 阅读更多 →
客户流失预警失效?AI动态生命周期分段算法(附TensorFlow实时推理代码片段)

客户流失预警失效?AI动态生命周期分段算法(附TensorFlow实时推理代码片段)

更多请点击: https://codechina.net 第一章:AI 客户生命周期管理 AI 客户生命周期管理(AI-CLM)是指利用机器学习、自然语言处理与实时数据分析技术,对客户从获客、激活、留存、增购到流失预警的全周期进行智能建模与…

2026/7/22 19:03:46 阅读更多 →
牛皮纸热封胶低温环境能用吗?

牛皮纸热封胶低温环境能用吗?

牛皮纸热封胶在低温环境下的应用越来越受到关注。它的设计专门考虑了耐温性,使其在寒冷的条件下仍能保持良好的粘合效果。在使用过程中,均匀涂布胶水是确保性能的重要一步。适当的加热也能为粘合力提供支持,帮助胶水在低温下发挥作用。另外、…

2026/7/22 19:03:46 阅读更多 →
dynamodb-onetable核心功能揭秘:从Schema定义到TypeScript类型自动生成

dynamodb-onetable核心功能揭秘:从Schema定义到TypeScript类型自动生成

dynamodb-onetable核心功能揭秘:从Schema定义到TypeScript类型自动生成 【免费下载链接】dynamodb-onetable DynamoDB access and management for one table designs with NodeJS 项目地址: https://gitcode.com/gh_mirrors/dy/dynamodb-onetable 在现代NoSQ…

2026/7/22 19:02:46 阅读更多 →

日新闻

TI DSP系统配置模块SYSCFG详解:中断机制与主设备优先级配置实战

TI DSP系统配置模块SYSCFG详解:中断机制与主设备优先级配置实战

1. 项目概述与SYSCFG模块的核心价值在嵌入式系统,尤其是像TI C6000系列这样的高性能DSP开发中,我们常常会与芯片手册里那些密密麻麻的寄存器打交道。很多开发者可能更关注算法实现、内存优化或者外设驱动,但对于一个稳定、高效的系统而言&…

2026/7/22 0:00:26 阅读更多 →
微信Server酱:高到达率的应急通知方案实践

微信Server酱:高到达率的应急通知方案实践

1. 为什么我们需要"最次"的通知方案? 在数字化协作环境中,消息通知系统的重要性不言而喻明。但现实情况是,企业级通知方案往往需要复杂的API对接(如企业微信、钉钉、飞书),个人开发者的小项目又经…

2026/7/22 0:00:26 阅读更多 →
甲方要的“简洁“PPT,到底是简洁还是省事?

甲方要的“简洁“PPT,到底是简洁还是省事?

甲方说"简洁一点",乙方听到的是"少做几页"。甲方说"不要太复杂",乙方理解成"别放图表了"。结果交过去,甲方说"我说的简洁不是这个意思"。"简洁"这个词在PPT语境里,是…

2026/7/22 0:00:26 阅读更多 →

周新闻

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

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

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

2026/7/22 8:58:19 阅读更多 →
Go语言实现高性能LDAP认证服务的架构与实践

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

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

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

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

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

2026/7/22 12:54:44 阅读更多 →

月新闻