AI Agent Frameworks: Four Patterns for Harness Design and Implementation

    Reliable AI agents need more than capable models: they need an execution harness that manages tools, state, policies, and failures. This article examines four framework patterns—reasoning–action loops, workflow orchestration, memory and state management, and multi-agent collaboration—and explains how to select, combine, and implement them with practical engineering controls.

    AI Agent Frameworks: Four Patterns for Harness Design and Implementation

    When teams discuss AI agents, their first instinct is often to choose a stronger model. In production systems, however, the model is only the reasoning core. Whether an agent completes tasks reliably often depends on the execution framework surrounding it.

    Think of a large language model as a powerful but stateless horse. The harness does not generate power; it constrains and channels that power into useful action. From a general engineering perspective, this article examines four common agent framework patterns and the design decisions needed to put them into practice. It does not focus on any particular product.

    1. The Core Architecture: Agent = Model + Harness

    At its core, a large language model processes tokens and produces tokens. It has no inherent persistent memory, cannot directly operate on files, databases, or business systems, and does not automatically enforce permission boundaries. Completing multi-step tasks requires a surrounding runtime layer, commonly called a harness or agent framework.

    A harness has at least six responsibilities:

    1. Prompt and context assembly: Organize system instructions, user input, conversation history, tool descriptions, and retrieved information into context the model can consume.
    2. Tool registration and execution: Describe available tools and their parameters, then translate model-generated actions into actual calls.
    3. State and session management: Store short-term conversation history, long-term memory, task progress, and intermediate results so execution can resume.
    4. Policies and safety guardrails: Enforce permissions, validate parameters, filter sensitive information, require human confirmation, and limit budgets and execution steps.
    5. Error handling and retries: Handle tool timeouts, unexpected responses, and malformed model output, then decide whether to retry, fall back, or terminate.
    6. Observability and evaluation: Record execution traces, tool results, latency, and costs to support replay, evaluation, and optimization.

    An agent is therefore not simply a model that is better at conversation. It combines a stateless reasoning engine with a stateful execution layer. Model capability sets the ceiling; harness quality determines baseline reliability and consistency.

    A smaller model with a carefully designed harness may perform reliably on well-bounded tasks. A frontier model in a framework without guardrails or state management can still enter loops, invoke tools incorrectly, or incur uncontrolled costs.

    2. Four Agent Framework Patterns

    2.1 Reasoning–Action Loops: Progress Through Observation

    This is the most direct agent pattern. The runtime asks the model to assess the current state and select an action. It executes a tool, adds the resulting observation to the context, and repeats until a termination condition is met.

    The basic loop is:

    1. Load task context
    2. → Model determines the next step
    3. → Parse the action and parameters
    4. → Validate against policies
    5. → Execute the tool
    6. → Record the observation
    7. → Check termination conditions

    This pattern suits open-ended tasks such as information retrieval, troubleshooting, and multi-step data preparation. Its strength is flexibility: the agent can adjust its next action based on tool results.

    Its weakness is that reliability depends on termination conditions, action parsing, and error recovery. Production implementations need maximum step counts, per-step timeouts, total budgets, and loop detection. Without these controls, agents may repeatedly invoke the same tool or continue reasoning without making progress.

    Key design considerations include:

    • Clear tool descriptions and structured parameters.
    • Robust action parsing.
    • Truncation and summarization of observations to prevent context growth.
    • Idempotent tool operations or compensating actions.
    • Human confirmation for high-risk actions.

    The goal is not unrestricted model autonomy. It is bounded exploration within a controlled state machine.

    2.2 Tool and Workflow Orchestration: Constrain Uncertainty with Deterministic Flows

    In this pattern, tasks are divided into explicit nodes, and an orchestrator controls execution. The model performs classification, extraction, generation, or decision-making within individual nodes. Rules in the workflow trigger tool calls rather than leaving tool selection entirely to the model.

    This approach suits relatively deterministic processes, including enterprise workflows, approvals, data pipelines, and report generation. A typical implementation uses a directed acyclic graph (DAG) or state machine with stages such as:

    • Prerequisite validation.
    • Information extraction.
    • Tool execution.
    • Result review.
    • Human intervention.
    • Final output.

    Each node has an input/output contract, a retry policy, and compensation logic.

    Compared with reasoning–action loops, workflow orchestration is easier to control, audit, and test, but less flexible. The guiding principle should be determinism first: if rules and state machines can handle a decision, do not delegate it to unconstrained model reasoning. Use the model primarily for semantic understanding and generation.

    Contracts between nodes should be versioned, tool responses should be standardized, and failures should be traceable to specific nodes. Long-running workflows should also support pausing, resuming, and human approval.

    2.3 Memory and State Management: Make Remembering an Engineering Capability

    This pattern focuses on context and execution state. An agent needs to distinguish among three kinds of information:

    • Short-term conversation history: The current interaction.
    • Task state: Steps, variables, and intermediate results.
    • Long-term memory: Reusable preferences, facts, or conclusions from earlier work.

    Memory does not mean putting the entire interaction history into every prompt. A practical memory design should:

    • Deduplicate information and assess its trustworthiness before writing it.
    • Isolate stored data by user, tenant, and task.
    • Consider recency, relevance, and permissions during retrieval.
    • Use summaries and references in context rather than concatenating all stored content.
    • Define expiration, deletion, and audit policies.

    State management also requires snapshots and recovery. If execution fails halfway through a task, the agent should resume from the latest checkpoint rather than start over. For multi-turn tasks, an explicit state machine is more reliable than conversation history alone.

    Memory improves continuity and reduces repeated interactions. However, the harness must prevent incorrect memories from propagating and ensure that private data does not enter context without authorization.

    2.4 Multi-Agent Collaboration: Divide Work to Reduce Complexity

    Multi-agent frameworks use multiple roles or subagents coordinated through messages, a shared blackboard, or a supervisor. Common roles include planners, executors, reviewers, and retrieval agents.

    This pattern is useful when tasks can run in parallel, require clearly different specializations, or benefit from cross-checking.

    It is not the default solution. Every additional agent introduces communication overhead, state synchronization, conflict resolution, and the risk of amplifying errors. Before adopting it, determine:

    • Whether the task can genuinely be decomposed.
    • Whether role boundaries are clear.
    • Whether communication follows a structured protocol.
    • Whether all agents share an overall budget and termination conditions.
    • Who arbitrates failures or disagreements.

    A practical composition is to place loops inside workflows, use memory within those loops, and reserve multiple agents for subtasks. For example, a supervisor node can decompose a task, subagents can execute within restricted tool sets, and a review node can consolidate their results.

    Do not allow agents to converse indefinitely. Define round limits, message formats, and a final decision-maker.

    3. Selection and Composition: Define the Task Contract First

    Evaluate framework choices along four dimensions: task determinism, number of tools, interaction duration, and compliance requirements.

    • For highly deterministic tasks with strong audit requirements, prioritize workflow orchestration.
    • For open-ended tasks requiring dynamic exploration, prioritize reasoning–action loops.
    • For long-running tasks, add memory and checkpoints.
    • For complex tasks, consider multiple agents, but keep their scope at the subtask level.

    A working agent runtime typically includes a model adapter, tool registry, policy engine, memory store, executor, and observer. The following pseudocode illustrates the core structure:

    1. class AgentRuntime:
    2. def run(self, session_id, user_input):
    3. context = self.memory.load(session_id)
    4. plan = self.model.reason(self.system_prompt, context, user_input)
    5. steps = 0
    6. while not plan.done and steps < self.max_steps:
    7. action = self.policy.validate(plan.next_action)
    8. if action.need_confirm:
    9. return self.human_confirm(action)
    10. result = self.tools.execute(action.name, action.args)
    11. self.memory.append(session_id, action, result)
    12. self.observer.record(session_id, action, result)
    13. plan = self.model.reason(
    14. self.system_prompt,
    15. self.memory.load(session_id),
    16. "Continue based on the observations"
    17. )
    18. steps += 1
    19. return plan.answer

    This sketch captures the division of responsibilities: the model handles reasoning, the policy layer enforces constraints, the tool layer executes actions, the memory layer maintains state, and the observation layer records execution.

    4. Implementation Checklist

    1. Tool contracts: Clearly define each tool’s name, description, parameter schema, response format, timeout, idempotency behavior, and permission scope.

    2. Safety guardrails: Implement tool allowlists, parameter validation, sandboxed execution, sensitive-data filtering, human confirmation, and budget and step limits.

    3. Observability: Record every model call, tool call, observation, execution duration, and cost. Support execution-trace replay.

    4. Evaluation metrics: Track task success rate, average step count, tool-call success rate, human intervention rate, error recovery rate, and cost per task.

    5. Cloud infrastructure: Use general-purpose object storage for traces, logging services for events, monitoring and alerts for anomalies, and containers to isolate execution environments. General-purpose infrastructure from providers such as Baidu AI Cloud can serve as a hosting environment for these capabilities.

    6. Iteration: Start with the smallest end-to-end implementation. Ensure that a single task can be completed, observed, and recovered before adding more tools or multiple agents.

    Conclusion

    These four agent framework patterns are not mutually exclusive. They are composable capability layers.

    The most valuable long-term engineering assets are not framework names, but the tool contracts, state models, safety policies, and evaluation systems within the harness. Define task boundaries, tool permissions, and termination conditions first. Then choose and combine loops, orchestration, memory, and multi-agent collaboration to move from generating text to completing work reliably.