Skip to main content

Harness

A harness lets an agent pursue long-running, complex goals while keeping its work durable, visible, and steerable. It preserves progress across retries and interruptions, while giving people and other systems a way to inspect progress, add context, approve actions, redirect the agent, or stop it.

Agent harnesses are useful wherever work continues over time. Common examples include coding agents that carry changes through CI and review, software factories (like Mastra Factory) that coordinate many tasks in parallel, SRE agents that adapt as incidents evolve, and go-to-market agents that respond as accounts, signals, and conversations change.

In Mastra, harness refers to a set of capabilities for managing an agent beyond a single uninterrupted run. You can adopt these capabilities individually or combine them as needed.

When to use a harness
Direct link to When to use a harness

Choose a starting point based on what the agent needs. You may use one capability or several.

If you want toStart hereWhy
Keep a run available through client disconnects or server restartsDurable AgentsPersist run state and let clients reconnect to its stream.
Run slow tools, workflows, or subagents without blockingBackground TasksFinish work asynchronously and return its result to the agent.
Keep an agent working until it reaches an objectiveGoalsEvaluate a thread-scoped objective until it's complete or reaches its run budget.
Start work automatically at recurring timesSchedulesStart isolated runs or send prompts into an existing thread on a cron schedule.
Add context, redirect active work, or wake an idle threadSignalsDeliver input now or hold it for the next turn.
React to changes in GitHub, Slack, continuous integration, or another external systemSignal ProvidersTrack subscriptions and forward matching events to agent threads.
Build an interactive product with sessions, modes, state, approvals, and events, or let users steer, queue follow-up work, and stop a runAgentControllerHost isolated sessions around a shared agent runtime, each with its own run controls.
Give an agent files, a shell, and the defaults a coding agent needscreateCodingAgent()Build a standard agent with a workspace, task tracking, and retries already configured.
On this page