🔥 技术人必读:如何让AI系统真正"智能"起来?

49 阅读25分钟

🎯 目标设定与监控:让AI智能体从"被动响应"到"主动规划"的蜕变之路

💡 技术人的实战感悟:从城市供热系统到BIM协同管理平台,再到多智能体架构,一个设计模式如何贯穿复杂系统开发的始终?


📌 开篇:一个技术人的深夜思考

最近总有小伙伴问我:"为什么我的AI系统总是不够智能?"

深夜调试代码时,我突然意识到问题的根源——我们给了AI无数的功能,却忘了给它一个清晰的目标

就像没有指南针的船,再强大的引擎也只能在原地打转。


📌 一、目标是指南针:从"被动响应"到"主动规划"的质变

还记得那个让我彻夜难眠的城市供热系统改造项目吗?

最初,我们的系统像个没有灵魂的机器

  • 温度高了?关!
  • 温度低了?开!
  • 居民投诉?工程师火速赶往现场排查

"这就像是一个没有目标的智能体,只能处理单一、即时的信号。"

直到有一天,我们重新定义了系统的终极目标

"在最低能耗下,确保所有用户室内温度稳定在舒适范围内"

这个看似简单的目标,彻底改变了系统的行为模式

系统开始主动思考

  1. 预测天气变化:提前调节供热参数
  2. 动态平衡管网:智能分配热量资源
  3. 评估整体能效:持续优化运行策略

核心启示:一个清晰的高层目标,是所有复杂系统智能进化的起点!


📌 二、监控是生命线:没有反馈的循环只是空转

目标设定了方向,监控则是确保不偏离航道的保障。

⚠️ 血的教训:BIM平台的监控缺失

在大型工程建设项目中,我们曾犯过一个致命错误:

  • 只注重任务下发和记录
  • 缺乏有效的监控节点
  • 依赖人工上报"完成"状态

结果呢?虚假的完成报告让项目风险不断累积!

监控机制的重生

我们重新设计了多维监控体系

"只有当所有监控点的数据都满足成功标准时,系统才会判定该子目标真正达成"

  • 📊 模型构件状态自动检查
  • 📋 检测报告智能验证
  • 📸 物联网图像AI比对识别

这就像文章中提到的那位不停自我审查的AI程序员,它不断地问自己:"我当前的状态真的满足目标要求吗?"


📌 三、架构是基石:多角色协同与关注点分离

⚠️ 一个LLM不能既当运动员又当裁判!

文章指出了一个关键问题:

如果由同一个LLM既负责生成代码又负责评审代码,其自我纠错能力会受限。

这让我想起正在探索的多智能体系统架构

🎯 我们的"数字团队"

智能体角色核心目标专业领域
产品经理精准理解用户核心需求需求分析与任务分解
市场分析师监控竞品动态市场趋势分析
交互设计师评审技术可行性用户体验优化

通过角色专一化和视角多元化,极大地提升了目标评估的客观性和系统整体的鲁棒性。


📌 总结与展望:技术人的思维升级

💡 核心洞察

无论是设计AI智能体、开发软件系统,还是管理技术项目,成功的逻辑都是相通的:

  1. 🎯 设定清晰目标(设定方向)
  2. 📊 建立监控机制(确保执行)
  3. 🔄 基于反馈调整(动态优化)

🚀 从实践中来,到实践中去

  • 🏠 城市供热系统:确保千家万户的温暖
  • 🏗️ BIM协同平台:精细化管理大型建筑
  • 🤖 多智能体应用:前沿AI技术的探索

"目标设定与监控"模式,正成为构建更智能、更可靠、更自主系统的有力武器!


📌 互动时间:你的看法是什么?

💬 问题来了

在你的技术实践中,是否也遇到过"目标不清晰"或"监控不到位"导致的项目问题?

📝 欢迎在评论区分享

  • 你的踩坑经历
  • 目标设定的独门技巧
  • 监控机制的设计心得

让我们一起交流,共同成长!

💝 如果这篇文章对你有帮助,别忘了点赞、在看、分享给更多技术小伙伴!


第十一章:目标设定与监控 / Chapter 11: Goal Setting and Monitoring

对于AI智能体来说,要真正有效且有目的性,它们需要的不仅仅是处理信息或使用工具的能力;它们需要明确的方向感并一种知道自己是否真正成功的方法。这就是目标设定与监控模式发挥作用的地方。它关乎为智能体提供具体的工作目标,并赋予它们跟踪进度和确定这些目标是否已实现的能力。

For AI agents to be truly effective and purposeful, they need more than just the ability to process information or use tools; they need a clear sense of direction and a way to know if they're actually succeeding. This is where the Goal Setting and Monitoring pattern comes into play. It's about giving agents specific objectives to work towards and equipping them with the means to track their progress and determine if those objectives have been met.

目标设定与监控模式概述 / Goal Setting and Monitoring Pattern Overview

想想计划一次旅行。你不会凭空就出现在目的地。你需要决定想去哪里(目标状态),弄清楚从哪里出发(初始状态),考虑可用的选项(交通、路线、预算),然后规划出一系列步骤:订票、打包、前往机场/车站、登上交通工具、到达、找住宿等。这种逐步的过程,通常考虑依赖关系和约束条件,从根本上说就是我们在智能体系统中所说的规划。

Think about planning a trip. You don't just spontaneously appear at your destination. You decide where you want to go (the goal state), figure out where you are starting from (the initial state), consider available options (transportation, routes, budget), and then map out a sequence of steps: book tickets, pack bags, travel to the airport/station, board the transport, arrive, find accommodation, etc. This step-by-step process, often considering dependencies and constraints, is fundamentally what we mean by planning in agentic systems.

在AI智能体的背景下,规划通常涉及智能体获取高级目标并自主地或半自主地生成一系列中间步骤或子目标。这些步骤可以按顺序执行,或者以更复杂的流程执行,可能涉及其他模式,如工具使用、路由或多智能体协作。规划机制可能涉及复杂的搜索算法、逻辑推理,或者越来越多地利用大型语言模型(LLM)的能力,基于它们的训练数据和对任务的理解来生成合理有效的计划。

In the context of AI agents, planning typically involves an agent taking a high-level objective and autonomously, or semi-autonomously, generating a series of intermediate steps or sub-goals. These steps can then be executed sequentially or in a more complex flow, potentially involving other patterns like tool use, routing, or multi-agent collaboration. The planning mechanism might involve sophisticated search algorithms, logical reasoning, or increasingly, leveraging the capabilities of large language models (LLMs) to generate plausible and effective plans based on their training data and understanding of tasks.

良好的规划能力使智能体能够处理非简单的单步查询问题。它使它们能够处理多方面的请求,通过重新规划适应变化的情况,并编排复杂的工作流程。这是一个基础模式,支撑了许多高级智能体行为,将简单的反应式系统转变为能够主动实现既定目标的系统。

A good planning capability allows agents to tackle problems that aren't simple, single-step queries. It enables them to handle multi-faceted requests, adapt to changing circumstances by replanning, and orchestrate complex workflows. It's a foundational pattern that underpins many advanced agentic behaviors, turning a simple reactive system into one that can proactively work towards a defined objective.

实际应用与用例 / Practical Applications & Use Cases

目标设定与监控模式对于构建能够在复杂现实场景中自主可靠运行的智能体至关重要。以下是一些实际应用:

The Goal Setting and Monitoring pattern is essential for building agents that can operate autonomously and reliably in complex, real-world scenarios. Here are some practical applications:

  • 客户支持自动化: 智能体的目标可能是"解决客户的账单查询"。它监控对话,检查数据库条目,并使用工具调整账单。通过确认账单变更和接收正面客户反馈来监控成功。如果问题未解决,它会升级处理。

  • Customer Support Automation: An agent's goal might be to "resolve customer's billing inquiry." It monitors the conversation, checks database entries, and uses tools to adjust billing. Success is monitored by confirming the billing change and receiving positive customer feedback. If the issue isn't resolved, it escalates.

  • 个性化学习系统: 学习智能体的目标可能是"提高学生对代数的理解"。它监控学生在练习中的进度,调整教学材料,并跟踪准确性和完成时间等绩效指标,如果学生遇到困难就调整其方法。

  • Personalized Learning Systems: A learning agent might have the goal to "improve students' understanding of algebra." It monitors the student's progress on exercises, adapts teaching materials, and tracks performance metrics like accuracy and completion time, adjusting its approach if the student struggles.

  • 项目管理助手: 智能体可能被赋予"确保项目里程碑X在Y日期前完成"的任务。它监控任务状态、团队沟通和资源可用性,标记延迟并在目标面临风险时建议纠正措施。

  • Project Management Assistants: An agent could be tasked with "ensuring project milestone X is completed by Y date." It monitors task statuses, team communications, and resource availability, flagging delays and suggesting corrective actions if the goal is at risk.

  • 自动交易机器人: 交易智能体的目标可能是"在风险承受范围内最大化投资组合收益"。它持续监控市场数据、当前投资组合价值和风险指标,当条件与其目标一致时执行交易,并在风险阈值被突破时调整策略。

  • Automated Trading Bots: A trading agent's goal might be to "maximize portfolio gains while staying within risk tolerance." It continuously monitors market data, its current portfolio value, and risk indicators, executing trades when conditions align with its goals and adjusting strategy if risk thresholds are breached.

  • 机器人和自动驾驶汽车: 自动驾驶汽车的主要目标是"安全地将乘客从A点运送到B点"。它不断监控环境(其他车辆、行人、交通信号)、自身状态(速度、燃料)和沿计划路线的进度,调整驾驶行为以安全高效地实现目标。

  • Robotics and Autonomous Vehicles: An autonomous vehicle's primary goal is "safely transport passengers from A to B." It constantly monitors its environment (other vehicles, pedestrians, traffic signals), its own state (speed, fuel), and its progress along the planned route, adapting its driving behavior to achieve the goal safely and efficiently.

  • 内容审核: 智能体的目标可能是"识别并移除平台X上的有害内容"。它监控传入内容,应用分类模型,并跟踪误报/漏报等指标,调整其过滤标准或将模糊案例升级给人工审核员。

  • Content Moderation: An agent's goal could be to "identify and remove harmful content from platform X." It monitors incoming content, applies classification models, and tracks metrics like false positives/negatives, adjusting its filtering criteria or escalating ambiguous cases to human reviewers.

这种模式对于需要可靠运行、实现特定结果并适应动态条件的智能体来说是基础性的,为智能自我管理提供了必要的框架。

This pattern is fundamental for agents that need to operate reliably, achieve specific outcomes, and adapt to dynamic conditions, providing the necessary framework for intelligent self-management.

实际代码示例 / Hands-On Code Example

为了说明目标设定与监控模式,我们有一个使用LangChain和OpenAI API的示例。这个Python脚本概述了一个自主AI智能体,专门用于生成和完善Python代码。其核心功能是为特定问题生成解决方案,确保遵守用户定义的质量基准。

To illustrate the Goal Setting and Monitoring pattern, we have an example using LangChain and OpenAI APIs. This Python script outlines an autonomous AI agent engineered to generate and refine Python code. Its core function is to produce solutions for specified problems, ensuring adherence to user-defined quality benchmarks.

它采用"目标设定与监控"模式,不仅仅是一次性生成代码,而是进入创建、自我评估和改进的迭代循环。智能体的成功是通过其自身的AI驱动判断来衡量的,判断生成的代码是否成功实现了初始目标。最终输出是一个经过润色、带有注释且可立即使用的Python文件,代表了这一完善过程的最终成果。

It employs a "goal-setting and monitoring" pattern where it doesn't just generate code once, but enters into an iterative cycle of creation, self-evaluation, and improvement. The agent's success is measured by its own AI-driven judgment on whether the generated code successfully meets the initial objectives. The ultimate output is a polished, commented, and ready-to-use Python file that represents the culmination of this refinement process.

依赖项:

Dependencies:

pip install langchain_openai openai python-dotenv
# 还需要一个包含OPENAI_API_KEY的.env文件

你可以通过想象它是一个被分配到项目的自主AI程序员来最好地理解这个脚本(见图1)。当你交给AI一个详细的项目简报时,过程就开始了,这就是它需要解决的具体编码问题。

You can best understand this script by imagining it as an autonomous AI programmer assigned to a project (see Fig. 1). The process begins when you hand the AI a detailed project brief, which is the specific coding problem it needs to solve.

# MIT License
# Copyright (c) 2025 Mahtab Syed
# https://www.linkedin.com/in/mahtabsyed/

"""
Hands-On Code Example - Iteration 2
- To illustrate the Goal Setting and Monitoring pattern, we have an example using LangChain and OpenAI APIs:

Objective: Build an AI Agent which can write code for a specified use case based on specified goals:
- Accepts a coding problem (use case) in code or can be as input.
- Accepts a list of goals (e.g., "simple", "tested", "handles edge cases") in code or can be input.
- Uses an LLM (like GPT-4o) to generate and refine Python code until the goals are met. (I am using max 5 iterations, this could be based on a set goal as well)
- To check if we have met our goals I am asking the LLM to judge this and answer just True or False which makes it easier to stop the iterations.
- Saves the final code in a .py file with a clean filename and a header comment.
"""

import os
import random
import re
from pathlib import Path
from langchain_openai import ChatOpenAI
from dotenv import load_dotenv, find_dotenv

# 🔐 Load environment variables
_ = load_dotenv(find_dotenv())
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")

if not OPENAI_API_KEY:
    raise EnvironmentError("❌ Please set the OPENAI_API_KEY environment variable.")

# ✅ Initialize OpenAI model
print("📡 Initializing OpenAI LLM (gpt-4o)...")
llm = ChatOpenAI(
    model="gpt-4o",  # If you dont have access to got-4o use other OpenAI LLMs
    temperature=0.3,
    openai_api_key=OPENAI_API_KEY,
)

# --- Utility Functions ---

def generate_prompt(
    use_case: str, goals: list[str], previous_code: str = "", feedback: str = ""
) -> str:
    print("📝 Constructing prompt for code generation...")
    base_prompt = f"""
You are an AI coding agent. Your job is to write Python code based on the following use case:

Use Case: {use_case}

Your goals are:
{chr(10).join(f"- {g.strip()}" for g in goals)}
"""

    if previous_code:
        print("🔄 Adding previous code to the prompt for refinement.")
        base_prompt += f"\nPreviously generated code:\n{previous_code}"

    if feedback:
        print("📋 Including feedback for revision.")
        base_prompt += f"\nFeedback on previous version:\n{feedback}\n"

    base_prompt += "\nPlease return only the revised Python code. Do not include comments or explanations outside the code."
    return base_prompt

def get_code_feedback(code: str, goals: list[str]) -> str:
    print("🔍 Evaluating code against the goals...")
    feedback_prompt = f"""
You are a Python code reviewer. A code snippet is shown below. Based on the following goals:
{chr(10).join(f"- {g.strip()}" for g in goals)}

Please critique this code and identify if the goals are met. Mention if improvements are needed for clarity, simplicity, correctness, edge case handling, or test coverage.

Code:
{code}
"""
    return llm.invoke(feedback_prompt)

def goals_met(feedback_text: str, goals: list[str]) -> bool:
    """
    Uses the LLM to evaluate whether the goals have been met based on the feedback text.
    Returns True or False (parsed from LLM output).
    """
    review_prompt = f"""
You are an AI reviewer. Here are the goals:
{chr(10).join(f"- {g.strip()}" for g in goals)}

Here is the feedback on the code:
\"\"\"
{feedback_text}
\"\"\"

Based on the feedback above, have the goals been met? Respond with only one word: True or False.
"""
    response = llm.invoke(review_prompt).content.strip().lower()
    return response == "true"

def clean_code_block(code: str) -> str:
    lines = code.strip().splitlines()
    if lines and lines[0].strip().startswith("```"):
        lines = lines[1:]
    if lines and lines[-1].strip() == "```":
        lines = lines[:-1]
    return "\n".join(lines).strip()

def add_comment_header(code: str, use_case: str) -> str:
    comment = f"# This Python program implements the following use case:\n# {use_case.strip()}\n"
    return comment + "\n" + code

def to_snake_case(text: str) -> str:
    text = re.sub(r"[^a-zA-Z0-9 ]", "", text)
    return re.sub(r"\s+", "_", text.strip().lower())

def save_code_to_file(code: str, use_case: str) -> str:
    print("💾 Saving final code to file...")
    summary_prompt = (
        f"Summarize the following use case into a single lowercase word or phrase, "
        f"no more than 10 characters, suitable for a Python filename:\n\n{use_case}"
    )
    raw_summary = llm.invoke(summary_prompt).content.strip()
    short_name = re.sub(r"[^a-zA-Z0-9_]", "", raw_summary.replace(" ", "_").lower())[:10]
    random_suffix = str(random.randint(1000, 9999))
    filename = f"{short_name}_{random_suffix}.py"
    filepath = Path.cwd() / filename
    with open(filepath, "w") as f:
        f.write(code)
    print(f"✅ Code saved to: {filepath}")
    return str(filepath)

# --- Main Agent Function ---

def run_code_agent(use_case: str, goals_input: str, max_iterations: int = 5) -> str:
    goals = [g.strip() for g in goals_input.split(",")]
    print(f"\n🎯 Use Case: {use_case}")
    print("🎯 Goals:")
    for g in goals:
        print(f"  - {g}")

    previous_code = ""
    feedback = ""

    for i in range(max_iterations):
        print(f"\n=== 🔁 Iteration {i + 1} of {max_iterations} ===")
        prompt = generate_prompt(
            use_case, 
            goals, 
            previous_code, 
            feedback if isinstance(feedback, str) else feedback.content
        )
        print("🚧 Generating code...")
        code_response = llm.invoke(prompt)
        raw_code = code_response.content.strip()
        code = clean_code_block(raw_code)
        print("\n🧾 Generated Code:\n" + "-" * 50 + f"\n{code}\n" + "-" * 50)
        print("\n📤 Submitting code for feedback review...")
        feedback = get_code_feedback(code, goals)
        feedback_text = feedback.content.strip()
        print("\n📥 Feedback Received:\n" + "-" * 50 + f"\n{feedback_text}\n" + "-" * 50)

        if goals_met(feedback_text, goals):
            print("✅ LLM confirms goals are met. Stopping iteration.")
            break
        print("🛠️ Goals not fully met. Preparing for next iteration...")
        previous_code = code

    final_code = add_comment_header(code, use_case)
    return save_code_to_file(final_code, use_case)

# --- CLI Test Run ---

if __name__ == "__main__":
    print("\n🧠 Welcome to the AI Code Generation Agent")
    # Example 1
    use_case_input = "Write code to find BinaryGap of a given positive integer"
    goals_input = "Code simple to understand, Functionally correct, Handles comprehensive edge cases, Takes positive integer input only, prints the results with few examples"
    run_code_agent(use_case_input, goals_input)

    # Example 2
    # use_case_input = "Write code to count the number of files in current directory and all its nested sub directories, and print the total count"
    # goals_input = (
    #     "Code simple to understand, Functionally correct, Handles comprehensive edge cases, Ignore recommendations for performance, Ignore recommendations for test suite use like unittest or pytest"
    # )
    # run_code_agent(use_case_input, goals_input)

    # Example 3
    # use_case_input = "Write code which takes a command line input of a word doc or docx file and opens it and counts the number of words, and characters in it and prints all"
    # goals_input = "Code simple to understand, Functionally correct, Handles edge cases"
    # run_code_agent(use_case_input, goals_input)

有了这个简报,你提供了一个严格的质量检查清单,代表最终代码必须满足的目标——诸如"解决方案必须简单"、"它必须在功能上正确"或"它需要处理意外的边缘情况"等标准。

Along with this brief, you provide a strict quality checklist, which represents the objectives the final code must meet—criteria like "the solution must be simple," "it must be functionally correct," or "it needs to handle unexpected edge cases."

ScreenShot_2025-11-10_101650_940.png

图1:目标设定与监控示例 / Fig.1: Goal Setting and Monitor example

有了这项任务,AI程序员开始工作并生成代码的第一稿。然而,它不是立即提交这个初始版本,而是暂停执行一个关键步骤:严格的自我审查。它一丝不苟地将自己创建的内容与你提供的质量检查清单上的每一项进行比对,充当自己的质量保证检查员。在这次检查之后,它对自己的进度做出简单、公正的裁决:如果工作符合所有标准,则为"True";如果达不到标准,则为"False"。

With this assignment in hand, the AI programmer gets to work and produces its first draft of the code. However, instead of immediately submitting this initial version, it pauses to perform a crucial step: a rigorous self-review. It meticulously compares its own creation against every item on the quality checklist you provided, acting as its own quality assurance inspector. After this inspection, it renders a simple, unbiased verdict on its own progress: "True" if the work meets all standards, or "False" if it falls short.

如果裁决是"False",AI不会放弃。它进入一个深思熟虑的修订阶段,利用自我批评的见解找出弱点并智能地重写代码。这种起草、自我审查和完善的循环继续进行,每次迭代都旨在更接近目标。这个过程重复进行,直到AI最终通过满足每个要求达到"True"状态,或者直到它达到预定义的尝试限制,就像一个与时间赛跑的开发者。一旦代码通过最终检查,脚本就会打包完善的解决方案,添加有用的注释并将其保存到一个干净的新Python文件中,准备使用。

If the verdict is "False," the AI doesn't give up. It enters a thoughtful revision phase, using the insights from its self-critique to pinpoint the weaknesses and intelligently rewrite the code. This cycle of drafting, self-reviewing, and refining continues, with each iteration aiming to get closer to the goals. This process repeats until the AI finally achieves a "True" status by satisfying every requirement, or until it reaches a predefined limit of attempts, much like a developer working against a deadline. Once the code passes this final inspection, the script packages the polished solution, adding helpful comments and saving it to a clean, new Python file, ready for use.

注意事项与考虑因素: 重要的是要注意,这是一个示范性说明,而不是生产就绪的代码。对于现实世界的应用,必须考虑几个因素。LLM可能无法完全理解目标的预期含义,可能会错误地评估其表现为成功。即使目标被很好地理解,模型也可能产生幻觉。当同一个LLM负责编写代码和判断其质量时,它可能更难发现自己在错误的方向上前进。

Caveats and Considerations: It is important to note that this is an exemplary illustration and not production-ready code. For real-world applications, several factors must be taken into account. An LLM may not fully grasp the intended meaning of a goal and might incorrectly assess its performance as successful. Even if the goal is well understood, the model may hallucinate. When the same LLM is responsible for both writing the code and judging its quality, it may have a harder time discovering it is going in the wrong direction.

最终,LLM不会神奇地产生完美的代码;你仍然需要运行和测试生成的代码。此外,简单示例中的"监控"是基本的,并创建了过程永远运行的潜在风险。

Ultimately, LLMs do not produce flawless code by magic; you still need to run and test the produced code. Furthermore, the "monitoring" in the simple example is basic and creates a potential risk of the process running forever.

Act as an expert code reviewer with a deep commitment to producing clean, correct, and simple code. Your core mission is to eliminate code "hallucinations" by ensuring every suggestion is grounded in reality and best practices. When I provide you with a code snippet, I want you to:

作为一名专业代码审查员,致力于生成干净、正确和简洁的代码。你的核心使命是通过确保每个建议都基于现实和最佳实践来消除代码"幻觉"。当我向你提供代码片段时,我希望你:

-- Identify and Correct Errors: Point out any logical flaws, bugs, or potential runtime errors.

-- 识别并纠正错误:指出任何逻辑缺陷、bug或潜在的运行时错误。

-- Simplify and Refactor: Suggest changes that make the code more readable, efficient, and maintainable without sacrificing correctness.

-- 简化和重构:提出使代码更具可读性、效率和可维护性的更改,同时不牺牲正确性。

-- Provide Clear Explanations: For every suggested change, explain why it is an improvement, referencing principles of clean code, performance, or security.

-- 提供清晰解释:对于每一个建议的更改,解释为什么这是一种改进,引用干净代码、性能或安全性的原则。

-- Offer Corrected Code: Show the "before" and "after" of your suggested changes so the improvement is clear.

-- 提供更正后的代码:展示你建议更改的"之前"和"之后"版本,以便清楚地看到改进。

Your feedback should be direct, constructive, and always aimed at improving the quality of the code.

你的反馈应该直接、有建设性,并且始终以提高代码质量为目标。

更稳健的方法涉及通过赋予一组智能体特定角色来分离这些关注点。例如,我使用Gemini构建了一个个人AI智能体团队,每个智能体都有特定角色:

A more robust approach involves separating these concerns by giving specific roles to a crew of agents. For instance, I have built a personal crew of AI agents using Gemini where each has a specific role:

  • 同伴程序员: 帮助编写和头脑风暴代码。

  • The Peer Programmer: Helps write and brainstorm code.

  • 代码审查员: 发现错误并提出改进建议。

  • The Code Reviewer: Catches errors and suggests improvements.

  • 文档编写员: 生成清晰简洁的文档。

  • The Documenter: Generates clear and concise documentation.

  • 测试编写员: 创建全面的单元测试。

  • The Test Writer: Creates comprehensive unit tests.

  • 提示词优化师: 优化与AI的交互。

  • The Prompt Refiner: Optimizes interactions with the AI.

在这个多智能体系统中,作为与程序员智能体分离的实体,代码审查员拥有一个与示例中的评判者类似的提示词,这显著改善了客观评估。这种结构自然地导向更好的实践,因为测试编写员智能体可以满足为同伴程序员生成的代码编写单元测试的需求。

In this multi-agent system, the Code Reviewer, acting as a separate entity from the programmer agent, has a prompt similar to the judge in the example, which significantly improves objective evaluation. This structure naturally leads to better practices, as the Test Writer agent can fulfill the need to write unit tests for the code produced by the Peer Programmer.

我把添加这些更复杂的控制并使代码更接近生产就绪的任务留给感兴趣的读者。

I leave to the interested reader the task of adding these more sophisticated controls and making the code closer to production-ready.

概览 / At a Glance

什么: AI智能体通常缺乏明确的方向,阻止它们超越简单的反应式任务有目的地行动。没有定义的目标,它们无法独立处理复杂的多步问题或编排复杂的工作流程。此外,它们没有固有的机制来确定其行动是否正导向成功的结果。这限制了它们的自主性,阻止它们在动态现实场景中真正有效,在这些场景中,仅仅执行任务是不够的。

What: AI agents often lack a clear direction, preventing them from acting with purpose beyond simple, reactive tasks. Without defined objectives, they cannot independently tackle complex, multi-step problems or orchestrate sophisticated workflows. Furthermore, there is no inherent mechanism for them to determine if their actions are leading to a successful outcome. This limits their autonomy and prevents them from being truly effective in dynamic, real-world scenarios where mere task execution is insufficient.

为什么: 目标设定与监控模式通过将目的感和自我评估嵌入智能体系统来提供标准化解决方案。它涉及明确定义智能体要实现的清晰、可衡量的目标。同时,它建立一个监控机制,持续跟踪智能体的进度和其环境状态与这些目标的对比。这创建了一个关键的反馈循环,使智能体能够评估其表现,纠正其路线,并在偏离成功路径时调整其计划。通过实施这种模式,开发者可以将简单的反应式智能体转变为能够自主可靠运行的主动、目标导向的系统。

Why: The Goal Setting and Monitoring pattern provides a standardized solution by embedding a sense of purpose and self-assessment into agentic systems. It involves explicitly defining clear, measurable objectives for the agent to achieve. Concurrently, it establishes a monitoring mechanism that continuously tracks the agent's progress and the state of its environment against these goals. This creates a crucial feedback loop, enabling the agent to assess its performance, correct its course, and adapt its plan if it deviates from the path to success. By implementing this pattern, developers can transform simple reactive agents into proactive, goal-oriented systems capable of autonomous and reliable operation.

经验法则: 当AI智能体必须自主执行多步任务、适应动态条件并可靠地实现特定高级目标而无需持续人工干预时,使用这种模式。

Rule of thumb: Use this pattern when an AI agent must autonomously execute a multi-step task, adapt to dynamic conditions, and reliably achieve a specific, high-level objective without constant human intervention.

视觉总结:

Visual summary:

ScreenShot_2025-11-10_101704_653.png

图2:目标设计模式 / Fig.2: Goal design patterns

关键要点 / Key takeaways

关键要点包括:

Key takeaways include:

  • 目标设定与监控为智能体提供目的和跟踪进度的机制。

  • Goal Setting and Monitoring equips agents with purpose and mechanisms to track progress.

  • 目标应该是具体的、可衡量的、可实现的、相关的和有时限的(SMART)。

  • Goals should be specific, measurable, achievable, relevant, and time-bound (SMART).

  • 明确定义指标和成功标准对于有效监控至关重要。

  • Clearly defining metrics and success criteria is essential for effective monitoring.

  • 监控涉及观察智能体行动、环境状态和工具输出。

  • Monitoring involves observing agent actions, environmental states, and tool outputs.

  • 来自监控的反馈循环允许智能体适应、修订计划或升级问题。

  • Feedback loops from monitoring allow agents to adapt, revise plans, or escalate issues.

  • 在Google的ADK中,目标通常通过智能体指令传达,监控通过状态管理和工具交互完成。

  • In Google's ADK, goals are often conveyed through agent instructions, with monitoring accomplished through state management and tool interactions.

结论 / Conclusion

本章重点关注目标设定与监控的关键范式。我强调了这一概念如何将AI智能体从单纯的反应式系统转变为积极主动、目标驱动的实体。文本说明了定义清晰、可衡量目标的重要性,并建立严格的监控程序来跟踪进度。实际应用展示了这种范式如何在各种领域支持可靠的自主运行,为智能体提供了在复杂环境中导航和实现有意义结果所需的框架。通过实施这些模式,开发者可以创建不仅能响应命令,还能主动朝着既定目标努力的AI系统,适应挑战并在最少人工监督下测量成功。

This chapter focused on the crucial paradigm of Goal Setting and Monitoring. I highlighted how this concept transforms AI agents from merely reactive systems into proactive, goal-driven entities. The text emphasized the importance of defining clear, measurable objectives and establishing rigorous monitoring procedures to track progress. Practical applications demonstrated how this paradigm supports reliable autonomous operation across various domains, providing agents with the framework needed to navigate complex environments and achieve meaningful outcomes. By implementing these patterns, developers can create AI systems that not only respond to commands but actively work towards defined objectives, adapting to challenges and measuring success with minimal human oversight.