构建智能体的架构:目的、范围与可靠性
Nowaczyk | 哈尔姆斯塔德大学
1 引言:目的、范围与架构可靠性
本章探讨构建智能体AI系统的架构选择,并分析这些选择如何影响可靠性。我们的核心主张简单明了:可靠性首先是一种架构属性。它源于我们将系统分解为组件的方式、界面的规范与执行方式,以及在负责推理、记忆和行动的各部分周围嵌入控制与保障环的方式。单个模型固然重要,但如果没有恰当的架构支撑,即使是最先进的模型也会表现不一致、无法审计,并在 novelty 面前显得脆弱。
本语境下的智能体AI,指的是系统通过决定下一步做什么、选择和使用工具、查阅和更新记忆,以及在约束条件下与环境交互来追求长期目标。智能体不仅仅是一个预测器;它是一个闭环中的决策者。它观察、规划(至少是选择)、行动和学习,通常在不确定性和部分可观测性下进行。
生成式AI指的是合成内容(文本、代码、图像、计划或中间表示)的模型——通常作为智能体内部的推理底层,或提供其他组件执行或验证的产物(查询、程序、模拟、解释)。在现代系统中,生成模型提供策略(如何推理和提出行动建议),而智能体架构则提供机制(建议如何被验证、制定、约束和记录)。
理解智能体生成式AI与传统自主智能体的关系至关重要,可以避免重复造轮子:许多关键概念已被长期研究并相对成熟;然而,生成式AI的本质也带来了全新的挑战,需要重新审视曾经的定论。
传统的反应式、审慎式或BDI(信念-欲望-意图)架构为信念、目标、计划和意图等概念提供了理论基础和清晰定义,具有清晰的控制环和显式世界模型。现代智能体系统通常用神经网络基础模型取代手工设计的推理模块。这些在大规模多样数据上训练的模型极大地提高了灵活性和能力广度,但也引入了推理步骤和工具使用方面的不确定性。
本章保留经典观点的有用约束——显式状态、目标、计划、承诺策略和监控——同时承认管道的某些部分(如计划生成或假设形成)可能由生成模型实现。这种协调正是架构发挥价值之处。
我们所说的可靠性,是指在规定条件下持续达成预期成果,并保持在安全、安保、数据保护和资源使用的可接受范围内,且有证据表明故障模式已知、受控且可恢复。对于智能体AI而言,这远不止模型准确性,还包括正确的工具调用、有边界的行动序列、对操纵的抵抗、可预测的延迟和成本,以及 graceful degradation、审计能力和人工覆盖路径。
架构通过以下方式使这些属性变得可处理:(i)在其契约可推理的模块中隔离职责;(ii)在推理与行动之间插入验证器和核查器;(iii)通过授权工具接口约束权威性和副作用;以及(iv)为系统配备仪表,使内部状态、决策和结果可观测且可重放。
在实践中,三个相互加强的设计选择决定了智能体系统在压力下的行为。组件化:将感知、记忆、规划、工具路由、执行、验证和监督等功能分离,将故障限制在明确界定的边界内,并限制其影响范围。接口与契约:将自由形式的模型输出转换为可预测的、可审计的行动。控制与保障环:监控器将计划行为与观察行为进行比较,批评者和验证器核查事实性和安全不变性,监督者执行预算和终止标准。
2 经典理论基础
2.1 反应式、审慎式与混合架构
反应式架构通过手工编码的条件-动作规则或学习策略将感知直接映射到行动。其优势是低延迟和对轻微分布偏移的鲁棒性;其劣势是在需要 lookahead、长期信用分配或对隐藏状态推理的任务面前表现脆弱。典型故障包括:短视反应(缺乏显式规划)、部分可观测性和未建模延迟。
审慎式架构维护世界的显式模型,并使用搜索或规划来选择行动。它们在可解释性和目标一致性方面表现出色,但可能遭受延迟和模型不匹配的困扰。典型故障包括:过时计划在快速变化的环境中变得不合适、模型不完备和计算超时。
混合架构将两种方法相结合:反应式层处理紧密控制环,审慎式层提供目标、约束和重规划。混合架构仍然是最实用的智能体AI模板,因为它们分离了关注点:需要行动的地方有快速安全,需要推理的地方有慢速监督层。故障通常源于层之间的协调缺陷,而非某一层单独的问题。
2.2 信念-欲望-意图(BDI)模型
BDI将代理框架为对信念(信息状态)、欲望(允许的目标)和意图(已采纳的计划/承诺)的管理。两个观点使BDI经久不衰:承诺策略(智能体在条件成立时坚持意图,因为承诺创造可预测性并减少颠簸)和意图修订(当触发条件或上下文改变时,智能体重新考虑意图并可能放弃、暂停或替换意图)。
映射到现代生成式AI智能体:信念→世界状态和记忆;欲望→目标和约束;意图→活跃计划和工具调用。BDI还阐明了将保障层置于何处的依据:采纳过滤器决定候选目标何时成为意图;执行监控跟踪上下文是否仍然支持该意图;重规划策略规定智能体重新规划的频率和信号。
3 现代智能体架构分类
现代智能体系统不是单一的整体设计,而是不同构建块——规划环、工具路由器、记忆层、验证器和监督者——围绕生成式推理核心的组合。五类架构在实践中反复出现。
3.1 工具使用型智能体
工具使用型智能体让生成模型决定调用哪些外部能力、用什么参数、按什么顺序来完成目标。三个关键角色:规划器生成意图结构(子目标、假设、候选行动);工具路由器将抽象行动映射到具体工具;执行沙箱执行前提条件检查,对每次调用进行速率限制和授权,在可能的情况下进行模拟,并以事务性方式(或回滚)提交副作用。
关键工程选择:类型化模式和验证器(将每次工具调用视为契约,拒绝不匹配,结构化错误反馈);幂等工具和请求去重(副作用工具应接受幂等令牌,安全重试);基于能力的授权(最小权限绑定工具,per-call政策核查);事务语义和补偿(当ACID不可用时使用saga模式);预算和终止标准(执行步数上限、累计成本上限和墙上时钟超时);确定性可观测性(以结构化形式记录计划、工具参数、结果和决策理由)。
典型故障模式和缓解:幻觉工具或参数可通过允许列表、模式验证和路由器批准来应对;无限或不生产的循环通过步数上限和安全停止来约束;工具不稳定需要"设计用于重试"思维和断路器;提示或检索注入需要消毒工具输出,剥离控制令牌,将任何不受信任的文本视为数据而非指令。核心原则:模型提议,架构处置。
3.2 记忆增强型智能体
智能体系统在能够记忆时会显著变得更加能干。工作记忆是episode内短暂存在的上下文(草稿本、CoT痕迹);长期记忆分为情景存储(先前任务的Structured日志)和语义存储(文档、事实)。检索增强生成(RAG)提供了进入语义记忆的非参数路径。
为可靠性而设计记忆需要:溯源与归属(每个检索或持久化的条目应携带源标识符、内容哈希、时间戳和检索政策/版本);新鲜度和有效期限(引入按来源的TTL和访问时刷新政策);记忆卫生与污染防御(将所有不受信任的文本视为数据而非指令);压缩、摘要与保留策略(冷存储保留无损Structured日志,中期召回保留摘要热存以便快速访问)。
3.3 规划与自我改进型智能体
规划型智能体通过显式搜索、外部执行器和自我评估环来加强模型的原始推理。思维树(ToT)将推理组织为对中间思想的搜索,而非单一从左到右的传递,使智能体能够从早期局部错误中恢复。思维图(GoT)将其推广到任意依赖图,允许子图的重组、摘要或优化。程序辅助语言模型(PAL)将推理转向可执行程序,由外部运行时执行,产生精确、确定性的计算。反思(Reflexion)在推理时增加自我评估和测试时修复,将反馈转化为结构化指导。
3.4 多智能体系统
多智能体系统用一组专业智能体团队取代单一全能智能体。三种拓扑:监督器-工作者(协调者负责任务分解和分配,权威和升级路径清晰);对等协作(协议规则驱动收敛);角色专业智能体(拍卖和黑板系统)。核心原则:模型提议,架构处置——通过将开放式推理转换为可靠行动的契约、调控器和沙箱。
Chapter 3: Architectures for Building Agentic AI
Slawomir Nowaczyk
1 Introduction: Purpose, Scope, and Architecture Reliability
This chapter surveys architectural choices for building agentic AI systems and analyses how those choices shape reliability. Our central claim is straightforward: reliability is, first and foremost, an architectural property. It emerges from how we decompose a system into components, how we specify and enforce interfaces between them, and how we embed control and assurance loops around the parts that reason, remember, and act.
Individual models matter, but without the right architectural scaffolding, even state-of-the-art models will behave inconsistently, be impossible to audit, and prove fragile in the face of novelty.
Agentic AI in this book denotes systems that pursue goals over time by deciding what to do next, selecting and using tools, consulting and updating memory, and interacting with their environment under constraints. An agent is not merely a predictor; it is a decision-maker in a closed loop. It observes, plans (or at least chooses), acts, and learns, typically under uncertainty and partial observability.
Generative AI refers to models that synthesise content—text, code, images, plans, or intermediate representations—often serving as the reasoning substrate inside the agent, or providing artefacts (queries, programs, simulations, explanations) that other components execute or verify. In modern systems, generative models supply the policy (how to reason and propose actions), while the agentic architecture supplies the machinery (how proposals are validated, enacted, bounded, and recorded).
Understanding the relation of Agentic GenAI with classic autonomous agents is crucially important to avoid reinventing the wheel: many key concepts have been studied for a long time and are relatively well-understood today; however, the nature of GenAI also brings up challenges that are completely novel and require rethinking of what was believed to be known.
Traditional reactive, deliberative, or BDI (belief-desire-intention) architectures offer theoretically-founded and crisp notions of concepts such as beliefs, goals, plans, and intentions, with clear control loops and explicit world models. Modern agentic systems often replace hand-engineered reasoning with neural-network-based foundation models. These models, trained on huge amounts of diverse data, vastly increase the flexibility and breadth of competence, but also introduce uncertainty in reasoning steps and tool usage.
By reliability, we mean the consistent achievement of intended outcomes under stated conditions, within acceptable bounds of safety, security, data protection, and resource usage, and with evidence that failure modes are known, contained, and recoverable. For agentic AI, this encompasses much more than just model accuracy. It includes correct tool invocation, bounded action sequences, resistance to manipulation, predictable latency and cost, graceful degradation, auditability, and human-override paths.
Architectures make these properties tractable by: (i) isolating responsibilities in modules whose contracts we can reason about; (ii) interposing validators and verifiers between reasoning and action; (iii) constraining authority and side-effects through permissioned tool interfaces; and (iv) instrumenting the system so that internal state, decisions, and outcomes are observable and replayable.
Three mutually reinforcing design choices determine how agentic systems behave under stress:
Componentisation: Separating functionality such as perception, memory, planning, tool routing, execution, verification, and oversight confines faults to well-defined boundaries and limits their blast radius. Clear responsibilities make defects diagnosable and upgrades safe: a verifier can be strengthened without disturbing the planner; an execution gateway can be hardened without touching memory logic.
Interfaces and contracts: Primary means to tame open-ended model behaviour are typed and schema-validated messages; explicit capability scopes for tools; idempotent and (where feasible) transactional semantics; rate/authority limits. All of these convert free-form model outputs into predictable, auditable actions.
Control and assurance loops: Monitors compare planned with observed behaviour; critics and verifiers check factuality, policy compliance, and safety invariants; supervisors enforce budgets, escalation rules, and termination criteria; fallbacks provide safe modes of operation when assumptions fail.
2 Classical Foundations
2.1 Reactive, Deliberative, and Hybrid Architectures
Reactive architectures map perceptions directly to actions through hand-coded condition–action rules or learned policies. Their strength is low latency and robustness to minor distributional shifts; their weakness is brittleness when tasks require look-ahead, long-horizon credit assignment, or reasoning about hidden state. Typical failure modes include myopic responses (lack of explicit planning), partial observability, and unmodelled delays.
Deliberative architectures maintain explicit models of the world and use search or planning to choose actions. They excel at explainability and goal consistency but can suffer from latency and model mismatch. Typical failures include stale plans, model incompleteness, and computational overrun.
Hybrid architectures combine the two approaches: reactive layers handle tight control loops, while deliberative layers provide goals, constraints, and re-planning. Hybrids remain the most practical template for agentic AI because they separate concerns: fast safety where the action is; slow reasoning in supervisory layers.
2.2 Belief–Desire–Intention (BDI) Architecture
BDI frames agency as the management of Beliefs (informational state), Desires (admissible goals), and Intentions (adopted plans/commitments). Two ideas make BDI enduring: commitment strategies (agents stick to intentions while conditions hold, creating predictability) and intention revision (when context changes, agents reconsider and may drop or replace intentions).
Mapping to modern GenAI agents is straightforward: Beliefs → world state and memory; Desires → goals and constraints; Intentions → active plans and tool calls. BDI clarifies where to place assurance: adoption filters decide when a goal becomes an intention; execution monitors track whether context still supports the intention; reconsideration policies specify how often and under what signals the agent re-plans.
3 A Taxonomy of Modern Agentic Architectures
Modern agentic systems are not single, monolithic designs, but compositions of different building blocks—planning loops, tool routers, memory layers, verifiers, and supervisors—typically stitched together around a core of generative reasoning.
Five families recur in practice:
3.1 Tool-Using Agents
Tool-using agents place a generative model in charge of deciding which external capabilities to invoke, with what arguments, and in what order, to accomplish a goal. A robust implementation separates three concerns: Planners generate intentional structure; Tool routers map abstract actions to concrete tools; Execution sandboxes perform pre-condition checks, rate-limit and permission each call, simulate where possible, and commit side-effects transactionally.
Key engineering choices: Typed schemas and validators; idempotent tools and request deduplication; capability-based permissioning; transactional semantics and compensations; budgets and termination criteria; deterministic observability.
3.2 Memory-Augmented Agents
Agentic systems become markedly more capable when they can remember. Working memory is a short-lived context (scratchpads, CoT traces); long-term memory splits into episodic stores (structured logs of prior tasks) and semantic stores (documents, facts). Retrieval-Augmented Generation (RAG) provides a non-parametric pathway into semantic memory.
Designing memory for reliability requires: Provenance and attribution (every retrieved item should carry source identifiers, content hash, timestamp); Freshness and validity windows (time-to-live policies by source); Memory hygiene and poisoning defences (sanitise all untrusted text); Compaction, summarisation, and retention policies.
3.3 Planning and Self-Improvement Agents
Planning-centred agents strengthen reasoning with explicit search, external executors, and self-evaluation loops. Tree of Thoughts (ToT) organises inference as a search over intermediate thoughts; Graph of Thoughts (GoT) generalises to arbitrary dependency graphs; Program-Aided Language models (PAL) shift reasoning to executable programs; Reflexion adds self-evaluation and test-time repair without gradient updates.
3.4 Multi-Agent Systems
Multi-agent systems exchange a single "do-everything" agent for a team of specialised agents that co-operate under explicit protocols. Three topologies have emerged: Supervisor–worker (clear authority and escalation paths); Peer collaboration (protocol rules drive convergence); Role-specialised agents (auctions and blackboard systems).
The guiding principle across all patterns: models propose, architectures dispose—with contracts, governors, and sandboxes that convert open-ended reasoning into reliable action.