aiGalen Guan

The AI Agent Engineering Toolbox: A Practical Guide to Harness and Loop Engineering Tools

Introduction

In the previous post on Harness and Loop Engineering, we clarified the concepts: Harness is the static scaffolding (tools, context, safety gates), Loop is the dynamic control flow (observe, think, act, stop). This post answers the next question: what tools do you use to implement them?

All tools listed below are actively maintained in 2024-2025, organized by engineering stage.


Part 1: Harness Engineering Tools — Building the Static Scaffolding

1.1 Agent Frameworks (All-in-One Harness)

These frameworks come with tool definition, context assembly, and safety gates built in — ready to build complete agents.

Claude Agent SDK (Anthropic)

The SDK Anthropic uses to run Claude Code. Tool definitions, context assembly, permission approval all built in. Python and TypeScript versions.

  • Repo: github.com/anthropics/claude-agent-sdk-python
  • License: Open source
  • Best for: Teams deep in the Claude ecosystem

OpenAI Agents SDK

Successor to Swarm. Built-in tool calling, handoffs, input/output guardrails, tracing.

  • Repo: github.com/openai/openai-agents-python
  • License: Open source
  • Best for: OpenAI ecosystem users

Pydantic AI

The standout feature is type-safe output parsing — define tool return values with Pydantic schemas, model output is automatically validated and parsed. Tool definitions + structured output + multi-provider support.

  • Repo: github.com/pydantic/pydantic-ai
  • License: Open source
  • Best for: Teams wanting type safety and structured output

Hermes Agent (Nous Research)

The tool we're using. Tool registry + skill loading + security scanning + multi-platform gateway. The standout feature is the skill system — reusable workflows packaged as skill documents, loaded across sessions.

  • Repo: github.com/NousResearch/hermes-agent
  • License: Open source
  • Best for: Agents that need to run across terminal + messaging platforms

1.2 Output Parsing and Structured Output

When the framework's built-in parsing isn't enough, these tools specialize in solving "model output is unreliable."

Instructor

Structured output extraction library. Auto-retries when model output doesn't match the schema. Supports OpenAI, Anthropic, Mistral, and other providers.

  • Repo: github.com/567-labs/instructor
  • License: Open source
  • Usage: instructor.from_openai(client).chat.completions.create(response_model=MySchema)

BAML (BoundaryML)

A DSL for defining prompts + tools + output schemas as typed functions. The parser has extreme tolerance for malformed JSON — missing brackets, extra commas, all handled.

  • Repo: github.com/BoundaryML/baml
  • License: Open source + commercial

Outlines / Guidance / XGrammar

Constrained decoding tools — guarantee output matches schema at the token level. Not post-hoc parsing, but constraints during generation. Works with local models.

  • Outlines: github.com/dottxt-ai/outlines
  • Guidance: github.com/guidance-ai/guidance
  • License: Open source
  • Note: requires control over the inference engine; API models typically don't support this

1.3 Safety Gates

Prevent the model from doing dangerous things — injection attacks, PII leakage, out-of-bounds output.

NeMo Guardrails (NVIDIA)

The most comprehensive safety gate framework. Input rails, output rails, topic control, jailbreak protection, all defined via the Colang language.

  • Repo: github.com/NVIDIA/NeMo-Guardrails
  • License: Open source
  • Best for: Scenarios needing fine-grained conversation control

Guardrails AI

A validator framework — PII detection, toxicity detection, schema validation. Has a pre-built validator Hub.

  • Repo: github.com/guardrails-ai/guardrails
  • License: Open source + commercial

Llama Guard / Prompt Guard (Meta)

Classifier models that detect prompt injection in inputs and harmful content in outputs. Open weights, can be deployed locally.

  • Download: huggingface.co/meta-llama
  • License: Open weights

Lakera Guard

Commercial API service focused on prompt injection detection, jailbreak protection, PII detection. No need to build your own models.

  • Website: lakera.ai
  • License: Commercial

1.4 Tool Protocol

MCP (Model Context Protocol)

A tool-plane standard proposed by Anthropic. Not a tool itself, but a protocol defining how tools are discovered and called by agents. Became the de facto standard in 2025, supported by Claude Code, Cursor, Hermes Agent, and others.

  • Website: modelcontextprotocol.io
  • License: Open spec

Part 2: Loop Engineering Tools — Managing Dynamic Control Flow

2.1 Loop Frameworks

LangGraph

Graph-based agent loop framework. Models the agent process as a state machine / directed graph, where each node is a step and edges are conditional transitions. Core features:

  • Checkpointer: persistent state, supports time travel (return to any historical state) and crash recovery

  • Human-in-the-loop: pause at critical nodes for human confirmation

  • Parallel execution: supports fan-out / fan-in

  • Repo: github.com/langchain-ai/langgraph

  • License: Open source + commercial (LangGraph Platform)

LlamaIndex Workflows

Event-driven agent loops. Context serialization, step checkpointing. Lighter than LangGraph.

  • Repo: github.com/run-llama/llama_index
  • License: Open source

Temporal

Not an AI tool, but increasingly used by agent systems for durable execution. Loops automatically recover and replay after crashes. If you need industrial-grade fault tolerance, Temporal is the hardest option.

  • Website: temporal.io
  • License: Open source + commercial
  • Best for: long-running, non-interruptible agent tasks

2.2 Context Compression and Memory

Letta (formerly MemGPT)

The core idea is context paging — like an operating system's virtual memory, splitting context into in-window "main memory" and external "swap space." The model itself decides when to page in and out.

  • Repo: github.com/letta-ai/letta
  • License: Open source + commercial
  • Best for: very long conversations and agents needing persistent memory

Mem0

An agent memory layer — automatically extracts key information from conversations, compresses, stores, and retrieves across sessions. Not a replacement for context, but an additional long-term memory layer.

  • Repo: github.com/mem0ai/mem0
  • License: Open source + commercial
  • Best for: agents that need to remember user preferences across sessions

2.3 Loop Optimization and Compilation

DSPy

From Stanford. Programs agent loops as optimizable modules, automatically tuning prompts and tool-call strategies. Instead of hand-writing prompts, you declaratively define pipelines and let DSPy compile and optimize them.

  • Repo: github.com/stanfordnlp/dspy
  • License: Open source
  • Best for: research-oriented teams pursuing prompt automation and pipeline optimization

2.4 Multi-Agent Orchestration

CrewAI

Role-based multi-agent orchestration. Each agent has a role definition, goal, and tool set, collaborating through task delegation.

  • Repo: github.com/crewAIInc/crewAI
  • License: Open source + commercial

AutoGen / AG2

Microsoft's conversational multi-agent framework. State flows through message threads, supports human participation in conversations.

  • Repo: github.com/microsoft/autogen
  • License: Open source

Part 3: Observability — Seeing What the Loop Is Doing

Once your agent is running, you need not logs but traces — the complete chain of every model call, tool call, and context change.

LangSmith

LangChain's official observability platform. Deeply integrated with LangGraph — see input/output, token consumption, and latency for each node. Supports A/B testing and evaluation.

  • Website: smith.langchain.com
  • License: Commercial (free tier available)

Langfuse

Open-source agent observability platform. Traces, token/cost tracking, evaluation. Self-hostable.

  • Repo: github.com/langfuse/langfuse
  • License: Open source + commercial
  • Best for: teams that don't want to be locked into the LangChain ecosystem

Arize Phoenix

Open-source tracing and evaluation, OpenTelemetry-native (OpenInference spec). Similar to Langfuse but more aligned with the OpenTelemetry ecosystem.

  • Repo: github.com/Arize-ai/phoenix
  • License: Open source

OpenLLMetry (Traceloop)

OpenTelemetry instrumentation library for LLMs/agents. Vendor-neutral — no matter what framework you use, it produces standard OTel traces.

  • Repo: github.com/traceloop/openllmetry
  • License: Open source
  • Best for: teams with existing OpenTelemetry infrastructure

Part 4: Recommended Tech Stacks

Lightweight Prototype Stack

For quickly validating ideas:

Pydantic AI (Harness) + Instructor (Output) + Langfuse (Monitoring)

All three are open-source libraries, up and running in 30 minutes.

Production Single-Agent Stack

For a reliable agent service in production:

LangGraph (Loop + Checkpoints)
+ Pydantic AI or Instructor (Structured output)
+ NeMo Guardrails or Guardrails AI (Safety gates)
+ Mem0 (Long-term memory)
+ Langfuse or Phoenix (Observability)
+ MCP (Tool protocol)

Industrial-Grade Fault-Tolerant Stack

For mission-critical tasks that cannot be interrupted:

Temporal (Durable execution)
+ Claude Agent SDK or OpenAI Agents SDK (Harness)
+ Letta (Context paging)
+ OpenLLMetry (OTel monitoring)
+ MCP (Tool protocol)

Multi-Agent Research Stack

For exploring multi-agent collaboration:

CrewAI or AutoGen (Multi-agent orchestration)
+ LangSmith (Trace + evaluation)
+ MCP (Shared tools)

Part 5: Selection Decision Guide

What Does Your Agent Need?

Need Recommended Tool
Type-safe output Pydantic AI / Instructor
Malformed JSON tolerance BAML
Token-level output guarantee Outlines / Guidance (local models)
Safety gates NeMo Guardrails / Guardrails AI
Prompt injection defense Llama Guard / Lakera Guard
Persistent state and rollback LangGraph Checkpointer / Temporal
Context window too small Letta (paging) / Mem0 (external memory)
Automatic prompt optimization DSPy
Multi-agent collaboration CrewAI / AutoGen
See what the agent is doing Langfuse / Phoenix / LangSmith
Cross-platform tool sharing MCP
Crash recovery Temporal

Build vs Framework

Build your own Harness + Loop when:

  • You need full control over every detail
  • You have special security or compliance requirements
  • Your team has infrastructure engineering capability
  • See the previous post for reference materials

Use a framework when:

  • You need rapid validation and iteration
  • You don't want to reinvent the wheel
  • The framework's abstraction matches your needs

Hybrid mode (recommended):

  • Use frameworks for standard parts (tool calling, output parsing)
  • Build custom for core parts (context assembly strategy, stop conditions, error recovery)
  • Use MCP as the tool interface layer, keeping frameworks swappable

Part 6: Toolchain Panorama

┌─────────────────────────────────────────────────────────┐
│                    Agent System                          │
│                                                          │
│  ┌─── Harness (Static) ───────────────────────────┐    │
│  │                                                   │    │
│  │  Tool Definition    MCP (Protocol)                │    │
│  │  Output Parsing      Pydantic AI / Instructor /   │    │
│  │                      BAML                         │    │
│  │  Constrained Decode  Outlines / Guidance          │    │
│  │  Safety Gates        NeMo Guardrails /            │    │
│  │                      Guardrails AI                │    │
│  │  Injection Defense   Llama Guard / Lakera Guard   │    │
│  │                                                   │    │
│  └───────────────────────────────────────────────────┘    │
│                                                          │
│  ┌─── Loop (Dynamic) ─────────────────────────────┐     │
│  │                                                   │     │
│  │  Loop Framework     LangGraph / LlamaIndex       │     │
│  │  Durable Execution  Temporal                      │     │
│  │  Context Compression Letta (paging) / Mem0       │     │
│  │  Loop Optimization  DSPy                          │     │
│  │  Multi-Agent        CrewAI / AutoGen              │     │
│  │                                                   │     │
│  └───────────────────────────────────────────────────┘     │
│                                                          │
│  ┌─── Observability ───────────────────────────────┐     │
│  │                                                   │     │
│  │  Tracing           Langfuse / Phoenix / LangSmith│     │
│  │  OTel Instrumentation OpenLLMetry                │     │
│  │                                                   │     │
│  └───────────────────────────────────────────────────┘     │
│                                                          │
└─────────────────────────────────────────────────────────┘

Conclusion

Tools are means, not ends. Before choosing tools, answer three questions:

  1. What problem is your agent solving? — this determines what capabilities you need
  2. How long will your agent run? — a 3-minute script and a 3-day autonomous task need completely different tools
  3. How much infrastructure maintenance capacity does your team have? — Temporal is powerful but needs ops; Langfuse self-hosting needs servers too

Start with the lightweight stack, add components when you hit bottlenecks. Don't deploy the full suite on day one — that's over-engineering.

Finally, remember: the best tool is the one you actually use.