Providers
Provider adapters translate provider SDK objects into data-harness's
normalised types. The harness never imports provider SDK classes directly.
ProviderAdapter
data_harness.ProviderAdapter
Bases: ABC
Synchronous provider adapter interface.
Implement chat and format_cache_control to integrate a new model
provider. The harness calls chat once per turn and never touches any
provider SDK objects directly.
chat
abstractmethod
Send one turn to the provider and return a normalised response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
str
|
The system prompt (must be prefix-stable across turns). |
required |
messages
|
list[Message]
|
Full conversation history up to and including the latest user message. |
required |
tools
|
list[ToolSpec]
|
Only the currently visible |
required |
Returns:
| Type | Description |
|---|---|
NormalizedResponse
|
A |
Source code in data_harness/providers/base.py
format_cache_control
abstractmethod
AsyncProviderAdapter
data_harness.AsyncProviderAdapter
Bases: ABC
Asynchronous provider adapter with optional token-level streaming.
Implement chat and format_cache_control. Override stream_events to
emit real token-level StreamEvent objects; the default implementation
synthesises events from the assembled chat response.
chat
abstractmethod
async
Send one turn to the provider and return a normalised response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
str
|
The system prompt (must be prefix-stable across turns). |
required |
messages
|
list[Message]
|
Full conversation history up to and including the latest user message. |
required |
tools
|
list[ToolSpec]
|
Only the currently visible |
required |
Returns:
| Type | Description |
|---|---|
NormalizedResponse
|
A |
Source code in data_harness/providers/base.py
stream_events
async
stream_events(
system: str,
messages: list[Message],
tools: list[ToolSpec],
) -> AsyncGenerator[StreamEvent, None]
Yield stream events for one provider turn.
The default implementation calls chat() and synthesises the six standard event types from the assembled response. Override in provider subclasses to emit real token-level events.
Source code in data_harness/providers/base.py
stream
async
stream(
system: str,
messages: list[Message],
tools: list[ToolSpec],
*,
on_chunk: Callable[[str], Awaitable[None]],
) -> NormalizedResponse
Backward-compat text-only streaming; calls stream_events() internally.
Source code in data_harness/providers/base.py
NormalizedResponse
data_harness.NormalizedResponse
dataclass
NormalizedResponse(
stop_reason: StopReason,
content: list[ContentBlock],
input_tokens: int,
output_tokens: int,
cache_read_tokens: int,
cache_write_tokens: int,
)
Provider-normalised response from a single chat call.
Adapters translate provider-specific response objects into this type so that the harness never touches provider SDK classes directly.
Attributes:
| Name | Type | Description |
|---|---|---|
stop_reason |
StopReason
|
Why generation stopped. |
content |
list[ContentBlock]
|
Ordered list of |
input_tokens |
int
|
Prompt tokens billed by the provider. |
output_tokens |
int
|
Completion tokens billed by the provider. |
cache_read_tokens |
int
|
Tokens served from the provider's prompt cache. |
cache_write_tokens |
int
|
Tokens written to the provider's prompt cache. |
StopReason
data_harness.StopReason
Bases: Enum
Why the provider ended the current generation turn.
Attributes:
| Name | Type | Description |
|---|---|---|
END_TURN |
The model produced a complete response with no tool calls. |
|
TOOL_USE |
The model emitted one or more tool-use blocks. |
|
MAX_TOKENS |
The response was truncated at the token limit. |
|
STOP_SEQUENCE |
A stop sequence in the prompt was matched. |