学习来源
Learning Source
- 类型:行业洞察Type: Industry Insight
- 名称:Harness EngineeringName: Harness Engineering
- 来源平台:LightpandaSource: Lightpanda
- 链接:https://lightpanda.io/blog/harness-engineering
- 作者:Lightpanda TeamAuthor: Lightpanda Team
核心收获
Key Takeaways
- 三层递进框架:Prompt Engineering → Context Engineering → Harness Engineering,层层嵌套构成完整的AI执行系统
- Three-Layer Framework: Prompt Engineering → Context Engineering → Harness Engineering, progressively nested to form a complete AI execution system
- 六层架构体系:结构化上下文、工具系统、执行编排、状态记忆、独立评估、约束恢复
- Six-Layer Architecture: Structured Context, Tool System, Execution Orchestration, State Memory, Independent Evaluation, Constraint Recovery
- 五个核心行动:重构思维重心、实施工具整合、建立独立评估、设计恢复机制、定期状态重置
- Five Core Actions: Reframe Thinking Focus, Implement Tool Integration, Establish Independent Evaluation, Design Recovery Mechanisms, Regular State Reset
- 执行骨架理念:真正的生产力革命不在模型参数里,而在包裹模型的那套"执行骨架"中
- Execution Skeleton Concept: The real productivity revolution lies not in model parameters, but in the "execution skeleton" that wraps around the model
- 工程化思维:从"调优提示词"转向"设计执行框架",重视AI系统的"操作系统"
- Engineering Mindset: Shift from "tuning prompts" to "designing execution frameworks", focusing on the "operating system" of AI systems
一、概述:从"能说"到"能干"的跨越1. Overview: Bridging from "Talk" to "Action"
在人工智能领域,我们见证了一场静默的革命。大语言模型(LLM)的出现让AI从"冰冷的规则引擎"变成了"能说会道的对话者"。然而,当我们深入企业级应用场景时,一个残酷的现实摆在我们面前:能说会道并不等于能干成事。
一个客服AI可以流畅地回答用户问题,却无法帮助用户完成订单;一个写作AI可以生成优美的文案,却无法自动发布到指定平台;一个数据分析AI可以解读海量数据,却无法根据分析结果自动触发后续业务流程。这些场景揭示了一个深刻的洞察:语言能力只是基础,执行能力才是关键。
Harness Engineering正是为解决这一问题而诞生的新学科。它不仅仅是一套技术,更是一种思维方式——将AI从"被动回答者"转变为"主动执行者"的系统化方法论。在Harness Engineering的视角下,AI不再是一个孤立的语言模型,而是一个拥有完整执行能力的智能体(Agent)。
这个框架的核心观点是:真正的生产力革命不在模型参数里,而在包裹模型的那套"执行骨架"中。就像一辆汽车的价值不仅在于发动机,还在于传动系统、控制系统、安全系统等一整套执行机制;AI系统的价值也不仅在于模型本身的语言能力,更在于围绕模型构建的完整执行保障体系。
In the field of artificial intelligence, we have witnessed a quiet revolution. The emergence of Large Language Models (LLMs) transformed AI from "cold rule engines" into "eloquent conversationalists." However, when we delve into enterprise-level application scenarios, a harsh reality confronts us: being articulate does not equal being capable.
A customer service AI can answer user questions fluently, yet cannot help users complete orders; a writing AI can generate beautiful copy, yet cannot automatically publish to designated platforms; a data analysis AI can interpret massive data, yet cannot automatically trigger subsequent business processes based on analysis results. These scenarios reveal a profound insight: language capability is merely the foundation; execution capability is the key.
Harness Engineering is precisely a new discipline born to solve this problem. It's not just a set of techniques, but a way of thinking—a systematic methodology for transforming AI from a "passive responder" to an "active executor." From the Harness Engineering perspective, AI is no longer an isolated language model, but an intelligent agent (Agent) with complete execution capabilities.
The core thesis of this framework is: the real productivity revolution lies not in model parameters, but in the "execution skeleton" that wraps around the model. Just as an automobile's value lies not only in its engine but in the entire execution mechanism of transmission systems, control systems, and safety systems; an AI system's value lies not only in the model's language capability but in the complete execution assurance system built around it.
二、Prompt Engineering详解:让模型听懂指令2. Deep Dive into Prompt Engineering: Making Models Understand Instructions
2.1 什么是Prompt Engineering
Prompt Engineering,即提示词工程,是Harness Engineering三层框架中最基础的一层。它的核心目标是通过设计输入语言来引导模型产生符合预期的输出。简单来说,就是"如何向AI提问才能得到最好的回答"。
2.2 核心技巧
- 结构化提示词:使用清晰的指令格式,如"角色+任务+约束+示例"的结构,帮助模型理解任务要求
- few-shot学习:通过提供少量示例来引导模型理解任务模式,比纯文字指令更有效
- 思维链提示:要求模型先展示推理过程,再给出答案,提高复杂任务的准确性
- 角色扮演:让模型扮演特定角色,利用角色固有的知识体系和表达方式来完成任务
- 分步指令:将复杂任务拆解为多个简单步骤,逐步引导模型完成
2.3 常见问题
- 指令模糊:使用过于笼统的描述,导致输出偏离预期
- 约束冲突:多个约束条件相互矛盾,让模型难以同时满足
- 上下文遗忘:在长对话中,早期的关键信息被后续内容稀释
- 过度依赖:认为"更好的提示词"能解决所有问题,忽视其他层面的优化
2.4 Prompt Engineering的局限性
尽管Prompt Engineering在优化模型输出方面效果显著,但它存在一个根本性的局限:它只能优化"输入-输出"这一环节,而无法解决AI在真实环境中执行任务的整体可靠性问题。当我们需要AI完成一个涉及多个步骤、多工具调用、需要状态维护的真实任务时,仅靠优化提示词是不够的。
2.1 What is Prompt Engineering
Prompt Engineering, or prompt design, is the most fundamental layer in the three-tier Harness Engineering framework. Its core objective is to guide the model toward expected outputs by designing input language. Simply put, it's about "how to ask AI questions to get the best answers."
2.2 Core Techniques
- Structured Prompts: Use clear instruction formats, such as "role + task + constraints + examples," to help models understand task requirements
- Few-shot Learning: Guide models to understand task patterns by providing a few examples, more effective than pure text instructions
- Chain of Thought Prompting: Ask models to show reasoning processes first, then provide answers, improving accuracy on complex tasks
- Role Play: Have models play specific roles, leveraging inherent knowledge systems and expression styles of those roles
- Step-by-step Instructions: Break complex tasks into multiple simple steps, guiding models through completion progressively
2.3 Common Problems
- Vague Instructions: Using overly general descriptions, causing outputs to deviate from expectations
- Conflicting Constraints: Multiple constraint conditions contradict each other, making it difficult for models to satisfy simultaneously
- Context Forgetting: In long conversations, early critical information gets diluted by subsequent content
- Over-reliance: Believing "better prompts" can solve all problems, neglecting optimization at other levels
2.4 Limitations of Prompt Engineering
Although Prompt Engineering shows significant effectiveness in optimizing model outputs, it has a fundamental limitation: it can only optimize the "input-output" link but cannot solve the overall reliability issues of AI executing tasks in real environments. When we need AI to complete real tasks involving multiple steps, multiple tool calls, and requiring state maintenance, optimizing prompts alone is insufficient.
三、Context Engineering详解:在正确时机提供关键信息3. Deep Dive into Context Engineering: Providing Critical Information at the Right Moment
3.1 什么是Context Engineering
Context Engineering,即上下文工程,是三层框架的第二层。它的核心目标是在正确的时机向AI提供关键信息,确保AI的决策和行动基于完整、准确的上下文。如果说Prompt Engineering是"如何问问题",那么Context Engineering就是"如何提供背景知识"。
3.2 上下文管理策略
- 信息分层:将信息按重要性和时效性分层,优先提供关键信息,确保模型首先关注核心内容
- 结构化注入:使用预定义的数据结构来组织上下文信息,提高信息的可解析性
- 动态补充:根据任务进展动态补充相关信息,而非一次性加载所有信息
- 上下文压缩:对长上下文进行智能压缩,保留关键信息,删除冗余内容
3.3 约束保持机制
在复杂任务执行过程中,一个常见的问题是约束漂移——即随着任务执行,原有的约束条件逐渐被遗忘或淡化。例如,用户要求"不要使用第三方API",但在AI调用某个工具时,这个约束被默默忽略了。
Context Engineering通过以下机制来解决约束保持问题:
- 约束前置声明:在任务开始时明确声明所有关键约束,并在执行过程中定期强化
- 约束检查点:在每个关键决策点设置约束检查,确保决策符合约束条件
- 约束记忆机制:将约束条件持久化存储,在需要时重新注入到上下文中
3.4 防止"失忆"的策略
LLM的上下文窗口是有限的,当对话过长时,早期的关键信息会被"挤出"上下文窗口,导致模型"失忆"。Context Engineering提供了多种策略来解决这一问题:
- 摘要回填:定期将对话内容压缩成摘要,在新的上下文窗口中保留核心信息
- 外部记忆:使用向量数据库或知识图谱存储对话历史,必要时检索相关信息
- 状态外置:将关键状态信息存储在外部系统,只在需要时注入到模型上下文中
3.1 What is Context Engineering
Context Engineering is the second layer of the three-tier framework. Its core objective is to provide critical information to AI at the right moment, ensuring AI decisions and actions are based on complete, accurate context. If Prompt Engineering is "how to ask questions," then Context Engineering is "how to provide background knowledge."
3.2 Context Management Strategies
- Information Layering: Organize information by importance and timeliness, prioritize critical information, ensure models focus on core content first
- Structured Injection: Use predefined data structures to organize context information, improving parseability
- Dynamic Supplementation: Dynamically supplement relevant information based on task progress, rather than loading all information at once
- Context Compression: Intelligently compress long contexts, retaining critical information and removing redundant content
3.3 Constraint Preservation Mechanisms
During complex task execution, a common problem is constraint drift—where original constraint conditions gradually get forgotten or diluted as the task progresses. For example, a user requires "do not use third-party APIs," but this constraint is silently ignored when AI calls a certain tool.
Context Engineering solves constraint preservation through the following mechanisms:
- Constraint Pre-declaration: Explicitly state all critical constraints at task start, and periodically reinforce them during execution
- Constraint Checkpoints: Set constraint checks at each critical decision point, ensuring decisions comply with constraints
- Constraint Memory: Persistently store constraint conditions, re-inject them into context when needed
3.4 Strategies to Prevent "Forgetfulness"
LLM context windows are limited; when conversations become too long, early critical information gets "squeezed out" of the context window, causing models to "forget." Context Engineering provides multiple strategies to solve this:
- Summary Refill: Periodically compress conversation content into summaries, preserving core information in new context windows
- External Memory: Use vector databases or knowledge graphs to store conversation history, retrieve relevant information when needed
- State Externalization: Store critical state information in external systems, injecting into model context only when needed
四、Harness Engineering详解:构建AI执行控制系统4. Deep Dive into Harness Engineering: Building AI Execution Control Systems
4.1 什么是Harness Engineering
Harness Engineering,即驾驭工程,是三层框架中最外层、也是最关键的一层。它的核心目标是构建AI在真实环境中的执行控制系统,确保任务能够稳定、可靠地完成。如果说Prompt Engineering优化的是"问答质量",Context Engineering优化的是"信息供给",那么Harness Engineering优化的就是"执行可靠性"。
这个概念的核心洞察在于:真正的生产力革命不在模型参数里,而在包裹模型的那套"执行骨架"中。就像核弹的威力不仅在于核材料,更在于引爆控制系统;AI的价值也不仅在于模型的智能,更在于围绕模型构建的执行保障体系。
4.2 三层关系:层层嵌套
构建完整的执行控制系统
在正确时机提供关键信息
让模型听懂指令
三层框架呈现出层层嵌套的关系:Prompt是Context的一部分,Context又是Harness的一部分。这意味着我们在设计AI系统时,需要从最外层开始思考:首先确保系统能够可靠执行(第三层),然后确保系统有正确的信息(第二层),最后确保系统的指令表达清晰(第一层)。
4.3 六层架构体系
| 层级 | 名称 | Name | 核心功能 | Core Function |
|---|---|---|---|---|
| 1 | 结构化上下文 | Structured Context | 组织和管理输入信息 | Organizing and managing input information |
| 2 | 工具系统 | Tool System | 扩展AI的行动能力 | Extending AI's action capabilities |
| 3 | 执行编排 | Execution Orchestration | 协调多步骤任务流程 | Coordinating multi-step task flows |
| 4 | 状态记忆 | State Memory | 维护长期任务状态 | Maintaining long-term task state |
| 5 | 独立评估 | Independent Evaluation | 验证输出质量与合规 | Verifying output quality and compliance |
| 6 | 约束恢复 | Constraint Recovery | 处理异常与边界条件 | Handling exceptions and boundary conditions |
4.1 What is Harness Engineering
Harness Engineering is the outermost and most critical layer of the three-tier framework. Its core objective is to build AI execution control systems in real environments, ensuring tasks are completed stably and reliably. If Prompt Engineering optimizes "Q&A quality" and Context Engineering optimizes "information provision," then Harness Engineering optimizes "execution reliability."
The core insight of this concept is: the real productivity revolution lies not in model parameters, but in the "execution skeleton" that wraps around the model. Like how a nuclear bomb's power lies not only in nuclear materials but in the ignition control system; AI's value lies not only in the model's intelligence but in the execution assurance system built around it.
4.2 Three-Layer Relationship: Progressive Nesting
Building complete execution control systems
Providing critical information at the right moment
Making models understand instructions
The three-tier framework shows a progressively nested relationship: Prompt is part of Context, and Context is part of Harness. This means when designing AI systems, we need to think from the outermost layer first: ensure the system can execute reliably (layer 3), then ensure the system has correct information (layer 2), and finally ensure clear instruction expression (layer 1).
4.3 Six-Layer Architecture System
| Layer | Name | Core Function |
|---|---|---|
| 1 | Structured Context | Organizing and managing input information |
| 2 | Tool System | Extending AI's action capabilities |
| 3 | Execution Orchestration | Coordinating multi-step task flows |
| 4 | State Memory | Maintaining long-term task state |
| 5 | Independent Evaluation | Verifying output quality and compliance |
| 6 | Constraint Recovery | Handling exceptions and boundary conditions |
4.4 六层架构详解
第一层:结构化上下文
结构化上下文是整个系统的基础。它的核心任务是将各种输入信息(用户指令、系统状态、外部数据等)组织成模型能够有效理解的格式。关键实践包括:
- 使用XML标签或JSON格式组织信息
- 按照"背景-任务-约束-示例"的结构组织提示词
- 使用markdown表格展示对比信息
- 在关键信息前添加明确的标签标记
第二层:工具系统
工具系统是扩展AI行动能力的关键。一个没有工具调用的AI只能在文字世界里打转,而一个配备了完善工具系统的AI可以真正"做事"——搜索网络、读写文件、执行代码、调用API等。关键实践包括:
- 设计清晰的工具描述Schema,包括用途、参数、返回值
- 实现工具调用的错误处理和重试机制
- 建立工具组合使用的最佳实践
- 设计工具执行结果的格式化处理
第三层:执行编排
执行编排负责协调多步骤任务的流程。复杂任务往往需要多个步骤,每个步骤可能涉及不同的工具调用和决策点。关键实践包括:
- 使用状态机或流程图描述任务执行流程
- 实现条件分支和循环逻辑
- 设计步骤间的数据传递机制
- 实现任务的暂停、恢复和取消能力
第四层:状态记忆
状态记忆确保AI能够维护长期任务的上下文。由于模型本身的上下文窗口有限,需要外部系统来存储和维护任务状态。关键实践包括:
- 设计任务状态的序列化格式
- 实现状态的持久化和恢复机制
- 定期对长对话进行摘要压缩
- 使用向量数据库实现语义检索
第五层:独立评估
独立评估是确保输出质量的关键机制。传统方式下,AI自我评估输出质量,但这容易导致"自我感觉良好"的问题。独立评估通过分离"生产者"和"验收者"来解决这个问题。关键实践包括:
- 设计独立的评估模型或规则引擎
- 建立多维度的质量评估标准
- 实现自动化的质量检测流程
- 设计人工审核与自动评估的结合机制
第六层:约束恢复
约束恢复是保障系统鲁棒性的最后一道防线。即使前面的设计再好,实际执行中总会出现各种异常情况。关键实践包括:
- 设计异常分类和处理策略
- 实现预设边界条件的检测
- 建立失败恢复的标准流程
- 设计优雅降级机制
4.4 Detailed Six-Layer Architecture
Layer 1: Structured Context
Structured context is the foundation of the entire system. Its core task is organizing various input information (user instructions, system state, external data, etc.) into formats the model can effectively understand. Key practices include:
- Using XML tags or JSON formats to organize information
- Organizing prompts in "background-task-constraints-examples" structure
- Using markdown tables to present comparative information
- Adding clear label markers before critical information
Layer 2: Tool System
The tool system is key to extending AI's action capabilities. An AI without tool calling can only roam in the world of text, while an AI equipped with a comprehensive tool system can truly "do things"—search the web, read/write files, execute code, call APIs, etc. Key practices include:
- Designing clear tool description schemas, including usage, parameters, return values
- Implementing error handling and retry mechanisms for tool calls
- Establishing best practices for combined tool usage
- Designing formatted processing of tool execution results
Layer 3: Execution Orchestration
Execution orchestration coordinates multi-step task flows. Complex tasks often require multiple steps, with each step potentially involving different tool calls and decision points. Key practices include:
- Using state machines or flowcharts to describe task execution flows
- Implementing conditional branching and loop logic
- Designing data transfer mechanisms between steps
- Implementing task pause, resume, and cancel capabilities
Layer 4: State Memory
State memory ensures AI can maintain context for long-term tasks. Due to the limited context window of models themselves, external systems are needed to store and maintain task state. Key practices include:
- Designing serialization formats for task state
- Implementing state persistence and recovery mechanisms
- Regularly summarizing and compressing long conversations
- Using vector databases for semantic retrieval
Layer 5: Independent Evaluation
Independent evaluation is a key mechanism for ensuring output quality. In traditional approaches, AI self-evaluates output quality, but this easily leads to "feeling good about oneself" problems. Independent evaluation solves this by separating "producers" and "acceptors." Key practices include:
- Designing independent evaluation models or rule engines
- Establishing multi-dimensional quality evaluation standards
- Implementing automated quality detection processes
- Designing mechanisms combining human review with automated evaluation
Layer 6: Constraint Recovery
Constraint recovery is the final line of defense for system robustness. No matter how good the preceding designs are, various exceptions will occur during actual execution. Key practices include:
- Designing exception classification and handling strategies
- Implementing detection of preset boundary conditions
- Establishing standard failure recovery processes
- Designing graceful degradation mechanisms
五、五个核心行动:从理论到实践5. Five Core Actions: From Theory to Practice
行动一:重构思维重心
核心转变:从"调优提示词"转向"设计执行框架"
传统做法:花大量时间迭代提示词,期望通过更好的指令获得更好的结果。
推荐做法:首先思考任务执行的完整流程,设计执行框架,然后根据框架需要优化提示词。
实践建议:在接到新任务时,先画流程图,再写提示词。
行动二:实施工具整合
核心转变:从"堆砌工具"转向"设计调用流程"
传统做法:给AI配备尽可能多的工具,期望它能自己决定何时用哪个工具。
推荐做法:根据任务流程设计工具调用逻辑,明确每个工具的触发条件和数据处理方式。
实践建议:不仅编写工具描述,还要编写"工具使用指南"和"结果处理函数"。
行动三:建立独立评估
核心转变:从"自我评估"转向"分离验收"
传统做法:让AI自己判断输出是否正确,这容易导致"自我感觉良好"的问题。
推荐做法:使用独立的评估系统(可以是另一个AI模型,也可以是规则引擎)来验证输出。
实践建议:设计"质量关卡",只有通过评估的输出才能进入下一步。
行动四:设计恢复机制
核心转变:从"被动处理错误"转向"主动预设边界"
传统做法:等问题出现了再想办法处理,头痛医头,脚痛医脚。
推荐做法:在设计阶段就预设各种异常情况,并制定相应的恢复策略。
实践建议:建立"异常场景库",每次遇到新问题后更新这个库。
行动五:定期状态重置
核心转变:从"维持长上下文"转向"适时压缩重启"
传统做法:尽可能维持长上下文,希望AI记住所有历史信息。
推荐做法:在长任务中适时进行上下文压缩或重置,防止性能衰减。
实践建议:设计"检查点",每完成一个阶段就进行状态总结和压缩。
Action 1: Reframe Thinking Focus
Core Shift: From "tuning prompts" to "designing execution frameworks"
Traditional approach: Spending significant time iterating prompts, hoping for better results through better instructions.
Recommended approach: First think about the complete task execution flow, design an execution framework, then optimize prompts based on framework needs.
Practical advice: When receiving new tasks, draw flowcharts first, then write prompts.
Action 2: Implement Tool Integration
Core Shift: From "stacking tools" to "designing call processes"
Traditional approach: Equipping AI with as many tools as possible, hoping it can decide which tool to use when.
Recommended approach: Design tool call logic based on task flows, clarifying trigger conditions and data processing methods for each tool.
Practical advice: Not only write tool descriptions, but also "tool usage guides" and "result processing functions."
Action 3: Establish Independent Evaluation
Core Shift: From "self-evaluation" to "separated acceptance"
Traditional approach: Letting AI judge whether outputs are correct by itself, which easily leads to "feeling good about oneself" problems.
Recommended approach: Use an independent evaluation system (which can be another AI model or a rule engine) to verify outputs.
Practical advice: Design "quality checkpoints," where only outputs passing evaluation can proceed to the next step.
Action 4: Design Recovery Mechanisms
Core Shift: From "passively handling errors" to "proactively setting boundaries"
Traditional approach: Waiting for problems to occur before figuring out how to handle them, treating symptoms rather than causes.
Recommended approach: During the design phase, anticipate various exception scenarios and develop corresponding recovery strategies.
Practical advice: Build an "exception scenario library," updating it each time a new problem is encountered.
Action 5: Regular State Reset
Core Shift: From "maintaining long contexts" to "appropriate compression and restart"
Traditional approach: Trying to maintain long contexts as much as possible, hoping AI remembers all historical information.
Recommended approach: Perform context compression or reset at appropriate intervals during long tasks, preventing performance degradation.
Practical advice: Design "checkpoints," summarizing and compressing state after completing each phase.
六、案例分析:Harness Engineering的实际应用6. Case Studies: Practical Applications of Harness Engineering
案例一:Claude Code的命令执行系统
Claude Code是Anthropic推出的AI编程助手,它完美诠释了Harness Engineering的核心理念:
- 工具系统:配备了文件读写、终端命令执行、Git操作等核心工具
- 执行编排:通过"任务分解→子任务执行→结果整合"的流程完成复杂编程任务
- 独立评估:在代码修改后自动运行测试和linting,确保输出质量
- 约束恢复:当命令执行失败时,会分析错误原因并尝试修复或回退
Claude Code的核心启示:工具不是越多越好,而是要有清晰的调用逻辑和完善的错误处理。
案例二:LangGraph的状态管理机制
LangGraph是LangChain推出的图状Agent框架,它通过图结构来实现复杂的状态管理:
- 结构化上下文:通过StateGraph定义统一的状态结构
- 执行编排:通过条件边实现动态的流程控制
- 状态记忆:通过checkpoint机制实现状态的持久化和恢复
- 约束恢复:通过条件判断和异常处理实现优雅的错误恢复
LangGraph的核心启示:复杂任务的执行需要一个清晰的状态机来管理。
案例三:CrewAI的角色协作系统
CrewAI是一个多Agent协作框架,它通过角色定义和任务分配来实现复杂的协作流程:
- 结构化上下文:每个Agent有明确的角色定义和上下文边界
- 执行编排:通过Crew和Task的组合实现复杂的协作流程
- 独立评估:每个任务的输出需要经过审核才能进入下一阶段
- 状态记忆:通过Agent之间的消息传递维护共享上下文
CrewAI的核心启示:多Agent协作需要清晰的角色定义和流程控制。
Case 1: Claude Code's Command Execution System
Claude Code is Anthropic's AI programming assistant, perfectly illustrating the core concepts of Harness Engineering:
- Tool System: Equipped with core tools for file read/write, terminal command execution, Git operations, etc.
- Execution Orchestration: Completes complex programming tasks through "task decomposition → subtask execution → result integration" flows
- Independent Evaluation: Automatically runs tests and linting after code modifications to ensure output quality
- Constraint Recovery: Analyzes error causes when commands fail and attempts to fix or roll back
Claude Code's core insight: Tools are not about having more, but having clearer call logic and comprehensive error handling.
Case 2: LangGraph's State Management Mechanism
LangGraph is LangChain's graph-based Agent framework, implementing complex state management through graph structures:
- Structured Context: Defines unified state structures through StateGraph
- Execution Orchestration: Implements dynamic flow control through conditional edges
- State Memory: Achieves state persistence and recovery through checkpoint mechanisms
- Constraint Recovery: Achieves graceful error recovery through conditional judgment and exception handling
LangGraph's core insight: Complex task execution requires a clear state machine for management.
Case 3: CrewAI's Role Collaboration System
CrewAI is a multi-Agent collaboration framework, implementing complex collaboration flows through role definitions and task assignments:
- Structured Context: Each Agent has clear role definitions and context boundaries
- Execution Orchestration: Implements complex collaboration flows through Crew and Task combinations
- Independent Evaluation: Each task output requires review before entering the next phase
- State Memory: Maintains shared context through message passing between Agents
CrewAI's core insight: Multi-Agent collaboration requires clear role definitions and flow control.
七、实践建议:如何在看宝AI项目中应用7. Practical Advice: Applying Harness Engineering to KanBao AI Projects
短期实践(1-2周)
- 重构现有提示词:按照"背景-任务-约束-示例"的结构重新组织所有提示词
- 添加质量检查点:在每个关键步骤后添加简单的质量验证逻辑
- 记录异常场景:开始建立异常场景库,记录每次遇到的问题和解决方案
中期优化(1-2个月)
- 设计工具调用框架:为常用工具设计清晰的调用逻辑和错误处理
- 实现状态管理:选择合适的状态管理方案(如Redis、SQLite等)
- 建立评估系统:开发独立的输出质量评估模块
长期建设(3-6个月)
- 构建执行框架:参考LangGraph等框架,设计适合项目的执行编排系统
- 完善恢复机制:建立完整的异常处理和恢复策略库
- 探索多Agent协作:研究CrewAI等框架,考虑在复杂场景中引入多Agent协作
关键成功因素
- 工程化思维:将AI系统当作软件系统来建设,重视可维护性和可扩展性
- 渐进式改进:不要试图一步到位,从简单的改进开始,持续迭代
- 度量驱动:建立合适的指标体系,用数据指导优化方向
- 文档沉淀:将每次遇到的问题和解决方案记录下来,形成组织知识
Short-term Practices (1-2 weeks)
- Refactor existing prompts: Reorganize all prompts according to "background-task-constraints-examples" structure
- Add quality checkpoints: Add simple quality verification logic after each critical step
- Document exception scenarios: Start building an exception scenario library, recording problems and solutions encountered
Medium-term Optimization (1-2 months)
- Design tool call framework: Design clear call logic and error handling for commonly used tools
- Implement state management: Choose appropriate state management solutions (Redis, SQLite, etc.)
- Establish evaluation system: Develop an independent output quality evaluation module
Long-term Development (3-6 months)
- Build execution framework: Reference frameworks like LangGraph to design execution orchestration systems suitable for projects
- Improve recovery mechanisms: Establish comprehensive exception handling and recovery strategy libraries
- Explore multi-Agent collaboration: Research frameworks like CrewAI, consider introducing multi-Agent collaboration in complex scenarios
Key Success Factors
- Engineering mindset: Build AI systems like software systems, emphasizing maintainability and scalability
- Progressive improvement: Don't try to achieve everything at once, start with simple improvements and iterate continuously
- Metrics-driven: Establish appropriate metric systems, use data to guide optimization directions
- Documentation accumulation: Record each problem and solution encountered to build organizational knowledge
八、相关链接8. Related Links
九、思考与实践9. Reflections and Practice
对我看宝AI项目的启发
通过学习Harness Engineering,我对AI Agent开发有了更深刻的理解。结合看宝AI项目的实际情况,我总结了以下几点思考:
第一,重新认识AI的价值定位。过去我们可能过度关注模型的智能程度(参数规模、推理能力等),而忽视了执行控制系统的重要性。Harness Engineering提醒我们,真正能产生生产力的不是模型本身,而是包裹模型的执行骨架。这意味着我们在项目规划时,应该将更多的精力放在执行框架的设计上。
第二,建立系统化的工程思维。Harness Engineering不仅仅是一套技术,更是一种思维方式。它强调从"调优提示词"转向"设计执行框架",从"被动处理错误"转向"主动预设边界"。这种工程化思维应该贯穿我们整个AI Agent开发过程。
第三,重视独立评估机制。"自我感觉良好"是AI系统常见的问题。通过建立独立的评估机制,分离"生产者"和"验收者",我们可以更客观地判断AI输出的质量。这对于需要高质量输出的场景尤为重要。
第四,坚持渐进式改进。Harness Engineering的六层架构看起来很复杂,但实际应用中不需要一步到位。我们可以从最简单的改进开始——比如重构提示词结构、添加质量检查点——然后逐步完善其他层次。
第五,重视文档和知识沉淀。异常场景库、最佳实践文档等都是组织的宝贵资产。通过建立和维护这些知识库,我们可以避免重复踩坑,加速团队成长。
具体行动计划
- 本周:梳理现有AI功能的执行流程,识别瓶颈和改进点
- 本月:为高频使用的工具设计调用指南和错误处理方案
- 本季:建立异常场景库和质量评估机制
- 本年:设计并实现看宝AI专属的执行框架
Insights for My KanBao AI Project
Through learning Harness Engineering, I have gained a deeper understanding of AI Agent development. Combined with the actual situation of the KanBao AI project, I've summarized the following reflections:
First, reconceptualize AI's value positioning. In the past, we may have overly focused on model intelligence (parameter scale, reasoning capabilities, etc.) while neglecting the importance of execution control systems. Harness Engineering reminds us that what truly generates productivity is not the model itself, but the execution skeleton wrapped around it. This means when planning projects, we should invest more energy in execution framework design.
Second, establish systematic engineering thinking. Harness Engineering is not just a set of techniques, but a way of thinking. It emphasizes shifting from "tuning prompts" to "designing execution frameworks," from "passively handling errors" to "proactively setting boundaries." This engineering mindset should permeate our entire AI Agent development process.
Third, value independent evaluation mechanisms. "Feeling good about oneself" is a common problem in AI systems. By establishing independent evaluation mechanisms that separate "producers" from "acceptors," we can more objectively judge the quality of AI outputs. This is particularly important for scenarios requiring high-quality outputs.
Fourth, persist in progressive improvement. The six-layer architecture of Harness Engineering looks complex, but it doesn't need to be implemented all at once. We can start with the simplest improvements—refactoring prompt structures, adding quality checkpoints—then gradually improve other layers.
Fifth, value documentation and knowledge accumulation. Exception scenario libraries and best practice documentation are valuable organizational assets. By building and maintaining these knowledge bases, we can avoid repeating mistakes and accelerate team growth.
Specific Action Plans
- This week: Review existing AI function execution flows, identify bottlenecks and improvement points
- This month: Design call guides and error handling solutions for frequently used tools
- This quarter: Build exception scenario libraries and quality evaluation mechanisms
- This year: Design and implement KanBao AI's proprietary execution framework