Models and adapters
Root model contracts and the public provider translator entry point.
ModelAdapter
Access: @nylorun/harness → ModelAdapter, ModelCall, ModelAdapterContext,
ModelCandidate
An adapter converts one canonical Harness model call into a provider request and returns the provider result as a candidate, string, or deferred outcome.
| Parameter | Type | Required | Description |
|---|---|---|---|
call | ModelCall | Yes | Provider-facing projection with model directive, prompt, tools, and session id. |
context | ModelAdapterContext | Yes | Full request, invocation id, and cancellation signal. Forward signal to the provider client. |
| Returns | Promise<ModelCandidate or string or DeferredOutcome> | — | Candidate data, direct text output, or deferred work marker. |
ModelCall and adapter context
Access: @nylorun/harness → ModelCall, ModelAdapterContext, ModelRequest
| Name | Type | Required | Description |
|---|---|---|---|
ModelCall.model | ModelDirective | No | Requested model id, controls, and host-defined JSON config. |
ModelCall.prompt | readonly PromptItem[] | Yes | Provider-neutral instructions, messages, tool results, and context. |
ModelCall.tools | readonly ModelCallTool[] | Yes | Model-visible tool names, descriptions, and input schemas. |
ModelCall.sessionId | string | Yes | Owning session id. |
ModelAdapterContext.request | ModelRequest | Yes | Immutable configuration, runtime context, transcript, arrivals, tool results, and bound tools. |
ModelAdapterContext.invocationId | string | Yes | Unique model invocation id. |
ModelAdapterContext.signal | AbortSignal | Yes | Cancellation signal. |
Candidate, configuration, and prompt types
Access: @nylorun/harness → ModelCandidate, ModelOutputBlock, ModelDirective,
ModelControls, ModelUsage, ModelEvidence, ModelConfigurationSnapshot, ContextSnapshot
| Type | Fields | Description |
|---|---|---|
ModelCandidate | output, optional finishReason, usage, evidence | Canonical provider result. |
ModelOutputBlock | text, reasoning, or tool-call variant | A text/reasoning block or a tool call with id, name, JSON args, and optional raw arguments. |
ModelDirective | optional id, controls, config | Middleware-selected provider model and host-defined provider configuration. |
ModelControls | optional temperature, maxOutputTokens | Provider-neutral controls forwarded by the built-in translators. |
ModelUsage | optional token counts and costUsd | Provider usage normalized when available. |
ModelEvidence | optional request id, model, warnings, extras | Provider evidence retained with the candidate. |
ModelConfigurationSnapshot | model, instructions, tools, contracts, contributors, digests | Immutable, attributed model configuration for one step. |
ContextSnapshot | items, contributors, digest | Runtime context kept separate from configuration policy. |
PromptItem, PromptContentPart, ModelCallTool, ModelConfigurationContributor,
ModelConfigurationInstruction, ModelConfigurationTool, ContextContributor, and the mutation
option types are also exported from the package root for adapters and middleware that need the
complete canonical shape.
Chat Completions translators
Access: @nylorun/harness/model/adapters → toChatCompletions, fromChatCompletions,
chatCompletionsAdapter
| API | Parameters | Returns | Description |
|---|---|---|---|
toChatCompletions | call: ModelCall | ChatCompletionsRequest | Projects the canonical call into Chat Completions messages, function tools, and controls. |
fromChatCompletions | value: unknown | ModelCandidate | Validates and normalizes one Chat Completions response. |
chatCompletionsAdapter | send: AdapterSend<ChatCompletionsRequest> | ModelAdapter | Combines request translation, application-owned transport, and response normalization. |
| Request field | Type | Required | Description |
|---|---|---|---|
messages | readonly ChatCompletionsMessage[] | Yes | System, user, assistant, and tool messages. |
tools | Function-tool array | No | Model-visible function definitions. |
temperature | number | No | Forwarded model temperature. |
max_completion_tokens | number | No | Forwarded model output-token limit. |
OpenAI Responses translators
Access: @nylorun/harness/model/adapters → toResponses, fromResponses,
responsesAdapter
| API | Parameters | Returns | Description |
|---|---|---|---|
toResponses | call: ModelCall | ResponsesRequest | Projects instructions, messages, function calls, tool results, tools, and controls. |
fromResponses | value: unknown | ModelCandidate | Validates and normalizes a Responses API result. |
responsesAdapter | send: AdapterSend<ResponsesRequest> | ModelAdapter | Creates an adapter backed by an application-owned Responses transport. |
| Request field | Type | Required | Description |
|---|---|---|---|
instructions | string | No | Joined canonical instructions. |
input | readonly ResponsesInputItem[] | Yes | User/assistant messages and function call or output items. |
tools | Function-tool array | No | Model-visible function definitions. |
temperature | number | No | Forwarded model temperature. |
max_output_tokens | number | No | Forwarded model output-token limit. |
Anthropic Messages translators
Access: @nylorun/harness/model/adapters → toMessages, fromMessages, anthropicAdapter
| API | Parameters | Returns | Description |
|---|---|---|---|
toMessages | call: ModelCall, defaultMaxOutputTokens: number | MessagesRequest | Projects a canonical call into the Messages request format. |
fromMessages | value: unknown | ModelCandidate | Validates and normalizes a Messages API result. |
anthropicAdapter | options: AnthropicAdapterOptions | ModelAdapter | Creates an adapter backed by an application-owned Messages transport. |
| Option or request field | Type | Required | Description |
|---|---|---|---|
AnthropicAdapterOptions.defaultMaxOutputTokens | number | Yes | Positive fallback for max_tokens when the model directive has no output limit. |
AnthropicAdapterOptions.send | AdapterSend<MessagesRequest> | Yes | Application-owned provider call. |
MessagesRequest.system | string | No | Joined canonical instructions. |
MessagesRequest.messages | readonly MessagesMessage[] | Yes | User content, tool results, and assistant text/tool-use parts. |
MessagesRequest.tools | Tool-definition array | No | Model-visible Messages tools. |
MessagesRequest.temperature | number | No | Forwarded model temperature. |
MessagesRequest.max_tokens | number | Yes | Per-step output limit or adapter fallback. |
Shared adapter types
Access: @nylorun/harness/model/adapters → AdapterSend, ChatCompletionsMessage,
ChatCompletionsToolCall, ResponsesInputItem, MessagesMessage, MessagesAssistantPart,
MessagesToolResult
| Type | Description |
|---|---|
AdapterSend<Request> | Application transport callback receiving translated request, canonical call, and adapter context. |
| Chat Completions types | JSON messages and function tool-call structures emitted or parsed by its translator. |
| Responses types | JSON message, function-call, and function-call-output structures emitted or parsed by its translator. |
| Messages types | JSON user, assistant, tool-use, and tool-result structures emitted or parsed by its translator. |
The translators cover text and JSON-object tool loops. Provider-native streaming, image input, continuation state, cache controls, and other extensions remain part of a custom host integration.