API Reference

Middleware

Capability declarations, step middleware, state, and model-configuration mutation APIs.

CapabilityDeclaration

Access: @nylorun/harnessCapabilityDeclaration, CapabilityItems, CapabilityState

Declares one named contribution to an agent's model surface and step behavior.

NameTypeRequiredDescription
idstringYesStable capability and middleware id.
toolsCapabilityItems<ToolDefinition>NoTool list, or named slot plus tool list, visible to the model.
instructionsCapabilityItems<string>NoInstruction list, or named slot plus instruction list.
modelModelDirectiveNoModel selection contributed by the capability.
stateCapabilityState<State>NoCreates optional state once per session.
middlewareStepMiddleware<State>NoStep handler run around the model call.

CapabilityItems<Item> accepts either readonly Item[] or a value with slot and items. CapabilityState.create(session, signal) creates the state; its optional dispose(value) cleans it up when the session ends.

StepMiddleware

Access: @nylorun/harnessStepMiddleware, StepRequest, StepInput

ParameterTypeRequiredDescription
requestStepRequest<State>YesStep identity, session identity, arrivals, tool results, transcript, state, and mutation APIs.
next() => Promise<StepResponse>YesContinues the middleware chain and model step. Call at most once.
ReturnsPromise<StepResponse>Response that may be inspected or changed after next().

StepInput exposes sessionId, turnId, stepId, turn/step numbers, session identity, arrivals, tool results, and transcript. A stateful declaration adds state: Promise<State> to the request.

Request mutation APIs

Access: @nylorun/harnessContextMutationOptions, ModelConfigurationMutationOptions, ModelDirective

APIParametersReturnsDescription
request.context.setslot, items, optional context mutation optionsvoidReplaces runtime context for one named slot.
request.configuration.instructions.setslot, items, optional configuration mutation optionsvoidReplaces model instructions for one named slot.
request.configuration.tools.setslot, tools, optional configuration mutation optionsvoidReplaces model-visible tools for one named slot.
request.configuration.model.selectdirective, optional reasonvoidSelects a model when one has not already won selection.
request.configuration.model.replacedirective, optional reasonvoidReplaces the selected model.
request.configuration.model.clearoptional reasonvoidRemoves the selected model.

Context and configuration mutation options accept optional order and reason. Model selection uses an optional reason only. Harness records contributors and digests in ContextSnapshot and ModelConfigurationSnapshot.

StepResponse

Access: @nylorun/harnessStepResponse, Tripwire

MethodParametersReturnsDescription
candidate()NoneReadonly<ModelCandidate> or undefinedReturns the current candidate, if any.
toolCalls()Nonereadonly ModelToolCall[]Returns tool calls currently eligible for review.
replace(candidate)ModelCandidatevoidReplaces the candidate before tool planning.
deny(callId, reason)string, stringvoidConverts one tool call into a denied result.
requireInteraction(callId, interaction)string, InteractionvoidRequires approval or a response before a tool runs.
tripwire(error)TripwireStepResponseStops the step or session according to the tripwire scope.

Attempting to call next() twice or mutate a request after its middleware has returned raises a machine-readable HarnessError.

On this page