cleandataengineering.aiAgent Harness, drawn simply
You are here: Tech stack › L4 · Control loop

Agent Harness Tutorial · Tech stack

L4 · Control loop

Plan, act, check, with step and no-progress limits. Family: Think · one turn, in order.

AZURE OPTIONSFoundry Agent Service✗ dropped: the platform would own the loopMicrosoft Agent Framework✗ dropped: for .NET / Azure-first teamsOUR CHOICEHand-written loopabout 400 lines, agent_harnessBudgets12 steps, 60 s, $0.50OPEN-SOURCE OPTIONSPydantic AI Agent✗ dropped: OK for simple A1–A3 agentsLangGraph✗ dropped: workflow-shaped agents onlyClaude Agent SDK✗ dropped: Claude-only, loop hiddenAnthropic tool runner· considered: small Claude-only agentsWHO DOES THE WORKAzure gives 0% · we code once 80% · each agent team still does 20%
Dark boxes are what we run. Solid boxes are used or planned; dashed boxes were considered or dropped (crossed). The bar: grey is what Azure gives, dark is what we code once, hatched is what each agent team writes.
Why our choiceAgents that touch money need every step testable and checks at exact positions. A hand-written loop has the lowest lock-in and works with any model.
OptionWhere fromVerdictWhy
Hand-written loopours✓ chosenabout 400 lines, agent_harness
Budgetsours✓ chosen12 steps, 60 s, $0.50
Foundry Agent ServiceAzure✗ droppedthe platform would own the loop
Microsoft Agent FrameworkAzure✗ droppedfor .NET / Azure-first teams
Pydantic AI Agentopen source✗ droppedOK for simple A1–A3 agents
LangGraphopen source✗ droppedworkflow-shaped agents only
Claude Agent SDKopen source✗ droppedClaude-only, loop hidden
Anthropic tool runneropen source· consideredsmall Claude-only agents

How it works inside the harness: Core loop.

Compared: Who owns the control loop?

Plain Python (…ourschosenPydantic AI Ag…open sourcemodel layer; A1–A3LangGraphopen sourceworkflow-shaped onlyClaude Agent S…vendorinternal agents onlyAnthropic tool…vendorsmall Claude agentsMicrosoft Agen…open source.NET teams onlyFoundry Agent …Azurerejected
Dark: what we chose. Crossed and dashed: rejected or not for us. From the Series.
OptionFromVerdictWho owns the loopAny modelCan tests reach every stepLock-inObservabilityBest for
Plain Python (hand-written)ourschosenusyesyesnoneour OTel spansassured, transactional agents
Pydantic AI Agentopen sourcemodel layer; A1–A3framework; we can step ityesyes if we step the looplow: open source, any cloudOTel built intyped, testable Python agents
LangGraphopen sourceworkflow-shaped onlyframework runs our graphyesyes, node by nodemedium: graph model, LangSmithfull only with LangSmithworkflow agents with approvals
Claude Agent SDKvendorinternal agents onlythe SDKClaude onlypartly: the loop is hiddenhigh: Claude-onlypartial tracescoding, ops, research agents
Anthropic tool runner (thin helper)vendorsmall Claude agentsus, with hooksClaude onlyyes: the steps are oursmedium: Claude-onlyour OTel spanssmall Claude-only agents
Microsoft Agent Frameworkopen source.NET teams onlyframeworkyestrajectory checks re-provedmedium: framework modelOTel, Azure-native.NET or Azure-first teams
Foundry Agent Service (prompt agent)AzurerejectedAzureFoundry modelsno: loop and retries hiddenhigh: Azure-only serviceFoundry tracinglow-code agents, not assured ones
DecisionWe write the loop ourselves and use Pydantic AI only as the model layer, so budgets and checks sit at exact, testable positions. We would use LangGraph for workflow-shaped agents, Agent Framework for a .NET team, and full Pydantic AI for simple A1–A3 agents.

How it is done: the real code

Cut from the live repositories each time the site is built, so it always matches what runs.

        for step in range(budgets.max_steps):
            ended = await this.step(step)
            if ended is not None:
                return ended
        return stopped(run_span, trace, TerminationReason.STEP_BUDGET_EXHAUSTED, PASS_ON)


@dataclass
class _Run:
    """One run's state, and the phases of a step as methods: each readable on its
    own, the state they share named once here rather than threaded through locals."""

    span: Span
    trace: Trace
    identity: Identity
    llm: LLMClient
    tools: ToolClient
    registry: ToolRegistry
    local_tools: dict[str, LocalTool]
    run_id: RunId
    system_prompt: str
    budgets: Budgets
    meter: Meter | None
    oscillation_threshold: int
    now: Callable[[], int]
    """The run's clock, injected like every other one here: a module that read
    the wall clock itself would be untestable about time, which is the whole
    subject of `fresh` (AHC L9, F-021)."""
    fresh: freshness.Freshness
    fan_out: int