createHarness<Construct a portable AI SDK v6 turn engine over an explicit ports object. Type ParametersState,TOOLS,OutputDefinition>(spec):Harness<TOOLS,OutputDefinition>
Parameters
Returns
Harness<TOOLS, OutputDefinition>
spec.ports
ports:Persistent host capabilities supplied through the versioned ports seam.AgentHarnessPorts<State>
spec.model
model: LanguageModel
AI SDK v6 language model.
Any AI SDK provider supplies the model. A failed call to it surfaces as HarnessProviderError, which keeps only allow-listed diagnostics.
spec.models
Host-owned models selectable only by a named runtime configuration key. The runtime configuration selects one for a turn by its name.optionalmodels?:Readonly<Record<string,LanguageModel>>
spec.tools
tools: TOOLS
The one explicit, flat tool set available to the model.
Tools are keyed by the name the model calls them by. createHarness() throws a TypeError unless every tool follows these rules.
- It has an
executefunction. - It is an ordinary function tool, not a dynamic or provider tool.
- It sets
needsApprovalonly totrue. - It uses no deferred results, no
toModelOutputand none of theonInputhooks.
needsApproval: true runs only inside a persistent run. A direct turn() whose tools include one throws TypeError("Harness approval-capable tools require durable runs"). Such a turn starts with accept() and executes through run().
spec.activeTools
Optional static subset of the injected tool set. When it is given, only the named tools are offered to the model. The runtime configuration can offer another subset for a turn.optionalactiveTools?: readonly (keyofTOOLS&string)[]
spec.authorization
Private, host-owned Service Account action mapping. Every supplied tool is mapped exactly once when approval-capable tools are present; model/tool metadata is never treated as an authorization authority. Both fields are required when any tool setsoptionalauthorization?:Readonly<{approvalTtlMs?:number;toolActions:Readonly<Record<string,string>>; }>
needsApproval. createHarness() throws a TypeError when a rule is broken.
toolActionsmaps each tool inspec.toolsto an action, and names no other tool.- An action is one or more runs of letters and digits joined by dots, such as
orders.refund, at most 512 bytes. approvalTtlMsis an approval’s lifetime from its request, in milliseconds, from 300000 (5 minutes) to 86400000 (24 hours).
approvals decides each held call.
spec.instructions
Optional static instructions supplied to every model step. The text is the model’s system prompt on every step. The harness assembles nothing into it, so its content is decided before the harness is built.optionalinstructions?:string
assemblePrompt()on a virtual workspace builds it from a base text and skills.- The runtime configuration replaces it for a turn.
spec.output
Optional host-owned structured output mode.optionaloutput?:OutputDefinition
output is an AI SDK output definition, such as Output.object({ schema }) from ai. The model’s final text is parsed through it, and the parsed value is returned as output in the HarnessTurnResult, beside text. A harness with output or outputs cannot take begin() turns.
spec.outputs
Host-owned output modes selectable only by a named runtime configuration key. The runtime configuration selects one for a turn by its name.optionaloutputs?:Readonly<Record<string,OutputDefinition>>
spec.limits
limits:Required bounded turn limits.Readonly<{steps:number; }>
steps is a positive integer that bounds the model steps of one turn. When the last allowed step still calls a tool, the turn throws HarnessStepLimitError. The runtime configuration can replace it for a turn.
spec.middleware
Ordered transport-neutral lifecycle middleware. Each list wraps one phase of a turn.optionalmiddleware?:Readonly<{modelStep?: readonlyHarnessMiddleware<HarnessModelStepMiddlewareContext<TOOLS>,unknown>[];tool?: readonlyHarnessMiddleware<HarnessToolMiddlewareContext<TOOLS>,unknown>[];turn?: readonlyHarnessMiddleware<HarnessTurnMiddlewareContext<TOOLS,OutputDefinition>,HarnessTurnResult<HarnessParsedOutput<OutputDefinition>>>[]; }>
turnwraps the whole turn.modelStepwraps each call to the model, and requires a model object rather than a model id.toolwraps each tool execution.
next ends the phase with its own result. A harness with turn or modelStep middleware cannot take begin() turns. HarnessMiddleware documents the contexts.
spec.durability
Deterministic persistence seams used by recovery tests. A host leavesoptionaldurability?:Readonly<{checkpoints?:HarnessCheckpoint;onToolCallStart?:GenerateTextOnToolCallStartCallback<TOOLS>;toolStepVersion?:string; }>
durability unset. Its seams exist for recovery tests.
Runtime Configuration
At the start of every turn, the harness reads one key of the instance’s state,__telnyx_agent_harness, and resolves the turn’s configuration from it.
modelandoutputname an entry ofspec.modelsandspec.outputs.instructionsreplaces the static text.toolsnames the tools offered, fromspec.tools, in place ofspec.activeTools.limits.stepsreplaces the step limit.
null takes its static value. A value that does not validate, such as one with an unknown name or key, is ignored whole, and the last valid configuration stands.