Skip to content

Harness

The core ReAct loop implementation. Agent is a convenience layer over Harness. Use Harness directly when you need explicit control over tool wiring — see examples/advanced_wiring.py for a complete example.


Harness

data_harness.data.harness.Harness

Harness(
    adapter: ProviderAdapter,
    system: str,
    tools: list[ToolSpec],
    max_turns: int = 25,
    cache: SessionCache | None = None,
    on_code: Callable[[str], object] | None = None,
    code_only: bool = False,
    session: Session | None = None,
    hooks: HookRegistry | None = None,
    compactor: Compactor | None = None,
)

Bases: Harness

Synchronous harness over a SessionCache. See core.loop.Harness.

Parameters:

Name Type Description Default
adapter ProviderAdapter

Synchronous provider adapter.

required
system str

System prompt. Kept byte-identical across all turns.

required
tools list[ToolSpec]

Full tool list.

required
max_turns int

Hard cap on provider turns.

25
cache SessionCache | None

Shared SessionCache. A fresh one is created if None.

None
session Session | None

Durable record of the run. Pass one opened from storage to resume a conversation across processes.

None
hooks HookRegistry | None

Pre-built HookRegistry, so an application can define its policy once and reuse it across harnesses.

None
on_code Callable[[str], object] | None

Approval gate called with interpreter code before it runs.

None
code_only bool

When True, interpreter code is echoed, never executed.

False
Source code in data_harness/data/harness.py
def __init__(
    self,
    adapter: ProviderAdapter,
    system: str,
    tools: list[ToolSpec],
    max_turns: int = 25,
    cache: SessionCache | None = None,
    on_code: Callable[[str], object] | None = None,
    code_only: bool = False,
    session: Session | None = None,
    hooks: HookRegistry | None = None,
    compactor: Compactor | None = None,
) -> None:
    super().__init__(
        adapter=adapter,
        system=system,
        tools=tools,
        max_turns=max_turns,
        environment=_environment_for(cache),
        on_code=on_code,
        code_only=code_only,
        session=session,
        hooks=hooks,
        compactor=compactor,
    )

cache property

cache: SessionCache

The SessionCache backing tool results and handles.


AsyncHarness

data_harness.AsyncHarness

AsyncHarness(
    adapter: AsyncProviderAdapter,
    system: str,
    tools: list[ToolSpec],
    max_turns: int = 25,
    cache: SessionCache | None = None,
    on_code: Callable[[str], object] | None = None,
    code_only: bool = False,
    session: Session | None = None,
    hooks: HookRegistry | None = None,
    compactor: Compactor | None = None,
)

Bases: AsyncHarness

Async harness over a SessionCache. See core.loop.AsyncHarness.

Same arguments as Harness, but takes an AsyncProviderAdapter.

Source code in data_harness/data/harness.py
def __init__(
    self,
    adapter: AsyncProviderAdapter,
    system: str,
    tools: list[ToolSpec],
    max_turns: int = 25,
    cache: SessionCache | None = None,
    on_code: Callable[[str], object] | None = None,
    code_only: bool = False,
    session: Session | None = None,
    hooks: HookRegistry | None = None,
    compactor: Compactor | None = None,
) -> None:
    super().__init__(
        adapter=adapter,
        system=system,
        tools=tools,
        max_turns=max_turns,
        environment=_environment_for(cache),
        on_code=on_code,
        code_only=code_only,
        session=session,
        hooks=hooks,
        compactor=compactor,
    )

cache property

cache: SessionCache

The SessionCache backing tool results and handles.