页面简介
A reference architecture for AI agent orchestration with durable state, tool policy, human approval, retries, and execution evidence.
正文摘录
AI agent orchestration is the control system that turns an agent's changing plan into a reliable sequence of model calls, tool calls, policy checks, human decisions, and recorded outcomes. It owns execution state and transitions. The model may propose what happens next, but the orchestrator decides whether that transition is valid and how it survives failure. That distinction matters in production. A convincing plan is not a checkpoint. A tool result is not proof that the intended operation ran exactly once. An approval is not permission to use any credential the reviewer happens to possess. The most useful mental model is two connected loops: A reasoning loop interprets the goal, selects a step, and learns from the result. An execution control loop persists state, enforces policy, pauses for decisions, runs side effects, and records what actually happened. The reasoning loop can be probabilistic. The execution control loop should be boring, explicit, and testable. Orchestration is more than routing between agentsSome systems use "orchestration" to mean choosing which agent handles a task. Routing is part of the job, but production orchestration also answers harder questions: Which run owns this tool call? Has the same logical step already executed? Is the tool allowed for this workload and resource? Did a person approve these exact arguments or an older version? What happens if the worker stops while waiting? Which failures can be retried without repeating a side effect? Did the approved operation succeed, fail, or roll back? Anthropic's guide to building effective agents separates predefined workflows from agents that dynamically direct their own tool use. AWS Prescriptive Guidance for workflow orchestration agents includes state tracking, retries, conditional execution, and coordination with humans. Both point to the same practical boundary: model-driven planning still needs ordinary software to own control flow. The two-loop reference architecture Architecture Flow Copy diagram The model never writes directly to the protected system in this design. It produces a proposal. A deterministic boundary validates the proposal, computes policy, and decides whether to deny, execute, or request review. A bounded decision model can also sit inside this loop without owning it. The TypeSafe AI Jev review explains how typed choices, scores, and probabilities can support routing while application code retains policy and control. Google Cloud's agentic architecture component guide describes models, tools, memory, runtimes, frameworks, and design patterns as separate choices. The diagram above adds the production control path between those components. Memory helps the agent reason. Durable run state tells the system what has already happened. ComponentOwnsMust not ownPlanner or agentGoal interpretation, decomposition, proposed next stepFinal authority over protected side effectsRun-state storeCurrent state, attempt, version, stable IDs, prior resultsRaw secrets or unrestricted prompt historyPolicy boundaryIdentity, tool, resource, argument, and risk checksModel-generated exceptions to policyHuman decision boundaryBounded context, typed response, expiry, reviewer evidenceThe agent's downstream credentialTool runnerValidated side effect and its idempotency identityReplanning the goal after execution beginsEvidence pipelineCorrelated traces, decisions, tool outcomes, durationsUnfiltered sensitive arguments by defaultMake the run a state machineIf run state exists only inside a prompt or worker process, recovery is guesswork. Persist an explicit state machine and allow only named transitions. plaintextCopystateDiagram-v2 [*] --> queued queued --> planning planning --> tool_proposed tool_proposed --> denied tool_proposed --> waiting_for_approval tool_proposed --> executing waiting_for_approval --> executing: approved snapshot waiting_for_approval --> rejected waiting_for_approval --> expired executing --> completed executing --> failed failed --> executing: safe retry queued --> cancelled planning --> cancelled waiting_for_approval --> cancelledThe model can recommend a transition. Application code validates and commits it. A transition record should contain enough evidence to reject stale events and recover after a crash: jsonCopy{ "run_id": "run_release_842", "run_version": 4, "state": "waiting_for_approval", "step": { "id": "promote-checkout", "attempt": 1, "tool": "deployment.promote", "arguments_sha256": "sha256:<canonical-argument-hash>", "idempotency_key": "run_release_842:promote-checkout" }, "policy": { "decision": "require_human", "policy_version": "release-policy-v4" }, "approval": { "action_id": "act_<id>", "action_version": 1, "fingerprint": "sha256:<reviewed-action-fingerprint>" }, "updated_at": "2026-09-01T18:42:11Z" }This is a vendor-neutral run record, not an ActionBox API payload. Store the canonical operation in a system authorized to hold it. The hash lets the orchestrator compare snapshots without copying sensitive arguments through logs and approval messages. Five invariants that keep the control loop safe1. Give every logical step a stable identityNetwork failures create ambiguity. A worker can send a request, lose the response, and have no idea whether the server accepted it. Retrying with a fresh identifier creates duplicate work. Reusing a stable idempotency key lets the receiver return the original result or reject changed content. Derive the key from business identity, not process identity: plaintextCopyrun_id + step_id + operation_versionA random value generated on every attempt cannot connect those attempts to the same logical operation. 2. Bind decisions to immutable operation evidence"Approve the deployment" is too vague when the agent can change the version, environment, or arguments after review. Persist a canonical argument hash or version before requesting approval. Recheck it immediately before execution. If material input changes, create a new review. Do not carry approval forward because the title still looks similar. 3. Classify retry semantics before running the toolA timeout does not tell you whether a remote side effect happened. The AWS durable execution guidance on idempotency and retries distinguishes at-least-once work, which must tolerate repetition, from at-most-once work, which stops rather than risk replay after an ambiguous interruption. Neither label magically provides exactly-once execution. OperationTypical policyRecovery questionRead inventoryRetry with bounded backoffIs the error transient?Upsert by stable resource IDRetry idempotentlyDoes the same key return the same state?Charge a payment methodUse provider idempotency or stop on ambiguityDid the provider commit the charge?Send a one-time external messageDedupe at the receiver or use at-most-once behaviorCan delivery be reconciled before retrying?Deploy an immutable buildBind build and environment, then reconcile target stateIs that exact build already active?4. Treat waiting as durable stateA person may answer after the original worker has stopped. Waiting for approval must not require an open browser tab, a held HTTP connection, or one specific process. Store the approval identity, return the worker to the queue, and let any authorized worker reconcile the result later. Microsoft's durable agent patterns model human input as an external event in a durable orchestration. The same separation works without that framework: the orchestrator owns the checkpoint, while the decision system owns the request and response. 5. Record execution separately from authorizationAn approval says the operation may proceed. It does not say the tool call succeeded. Store a separate outcome with the real status, duration, error class, and rollback state. This distinction prevents dashboards from reporting approved failures as successful automation. A small ActionBox orchestration workerThe following Python worker demonstrates the control boundary with only the standard library. It creates one idempotent approval request, reconciles the durable Action until it becomes terminal, writes a harmless local release marker as the protected operation, and reports the execution outcome. The local marker uses exclusive creation, so restarting the example does not write the same logical release twice. Replace that function with a downstream API that accepts its own idempotency key or supports authoritative state reconciliation. In the inbox, the reviewer sees the proposed effect, risk, rollback plan, affected scope, and source evidence before choosing. The orchestration worker remains paused outside the inbox. An open production deployment Action in the ActionBox inbox with bounded risk, rollback, and release evidence pythonCopyfrom __future__ import annotations import json import os import time import urllib.request from datetime import datetime, timedelta, timezone from pathlib import Path API = "https://api.actionbox.cloud" SOURCE_KEY = os.environ["ACTIONBOX_SOURCE_KEY"] RUN_ID = os.environ.get("RUN_ID", "release-842") def request(method: str, path: str, body=None, idempotency_key=None) -> dict: data = None if body is None else json.dumps(body).encode() headers = { "Authorization": f"Bearer {SOURCE_KEY}", "User-Agent": "actionbox-release-example/1", } if body is not None: headers["Content-Type"] = "application/json" if idempotency_key: headers["Idempotency-Key"] = idempotency_key req = urllib.request.Request( f"{API}{path}", data=data, headers=headers, method=method ) with urllib.request.urlopen(req, timeout=35) as response: return json.load(response) def create_review() -> dict: expires_at = datetime.now(timezone.utc) + timedelta(minutes=30) payload = { "title": "Publish release 842?", "description": "The release worker is paused before publishing its marker.", "priority": "high", "options": [ {"id": "approve", "label": "Approve publish", "style": "primary"}, {"id": "reject", "label": "Reject", "style": "destructive"}, ], "expires_at": expires_at.