HarnessX is a Python SDK for building agents that reason, call tools, and carry work across turns. You supply the model, tools, and policies. The harness runs the loop and exposes what happens along the way.

THE WORKING PARTS BENEATH THE LOOP Execution stateSQLite · Postgres · Temporal Recoveryresume · replay Flight recorderexport · verify · play back Tracing & evalsLangSmith DecisionsChoice · Score · Noul end_turn requestenters guardrailsrequest middleware permissions · approvalscall middleware hooks observe every event · result middleware · next iteration ↺ AROUND EVERY STEPMiddleware reshapes requests and resultsHooks watch every eventGuardrails cap iterations, cost and contextApprovals pause a tool until a person decidesExtensions bundle these with saved state Contexthistory · notes · factstrimming · spilling Modelprompt cache · retry Toolsfunctions · MCP · skillssubagents · sandbox ResultRunResult · events · usage
Contextconversation historynotes · long-term factstrimming · spilling
Toolsfunctions · MCP · skills · knowledgesubagents · sandboxschemas · timeouts · dedupe
ResultRunResult · outputerror · typed eventsusage · cache reads

Repeats until the model stops, a tool needs approval, or a guardrail is reached.

Start with one agent

A typed Python function can be a tool. Pass it when you construct the agent, then await a run.

import asyncio
from harnessx import Agent

def multiply(a: int, b: int) -> int:
    """Multiply two numbers."""
    return a * b

async def main():
    async with Agent(tools=[multiply]) as agent:
        result = await agent.run("What is 40 * 10? Use multiply.")
        if result.error:
            raise RuntimeError(result.error["message"])
        print(result.output)

asyncio.run(main())

What the harness provides

Layer What it does Learn more
Agent loop Sends context to a provider, validates and dispatches tools, returns results Agents
Capabilities Typed functions, external MCP tools, lazy skill instructions, and BM25F retrieval over OKF knowledge bundles Tools, MCP, Skills, Knowledge
Context Conversation history, notes, structured facts, and result spilling Sessions & snapshots
Decisions Standalone Choice routing, Score rubrics, and Noul evidence assessments Decisions with Jev
Control Permissions, explicit approval, budgets, and replay policies Permissions
Execution Direct runs or durable sessions with persisted execution boundaries Durable agent runs (advanced)
Inspection Typed streaming events, lifecycle hooks, traces, and incident archives Streaming, Flight recorder

Choose the execution model

Agent and AgentRuntime are two entry points into one execution engine, with the same tool and permission semantics. Use Agent for an in-process conversation or request. Use AgentRuntime when work must pause for an approval or survive a process failure. See Durable agent runs.