Prerequisites
The standalone CLI installer does not expose an importable package, so embed from a source checkout:opensre onboard) — the harness reuses the same
config and credentials as the CLI. Run your script inside the checkout’s
environment with uv run python your_script.py.
One turn
AgentHarness.start() resolves the environment, opens a session, and attaches
an agent with the standard ports — the same tools and prompts the interactive
shell uses.
Always check result.answered before trusting the text: when a turn fails (for
example the LLM provider is unreachable), the error message itself lands in
result.primary_response_text.
A conversation
Eachdispatch_message call is one turn in the same session, so follow-ups see
earlier context:
Your own grounding context
The agent builds its prompts from the session by default. To ground it your own way — a different system prompt, your own retrieved context — pass a provider:core.agent_harness.DefaultPromptContextProvider). A custom provider must
satisfy core.agent_harness.ports.PromptContextProvider. The same prompts=
argument is accepted by build_default_headless_agent on the custom-ports path
below.
Custom output and ports
start() buffers all output. To capture tool progress yourself — stream to a
websocket, collect for a report — build the agent explicitly and pass your own
sink:
OutputSink protocol
(core.agent_harness.ports.OutputSink: print, render_response_header,
render_error, stream) works in place of BufferOutputSink.
build_default_headless_agent also accepts a custom logger, prompt surface,
and tool observers — see its docstring for the full port list.
Your own tools
Register a package before the first tool lookup:- Declare tools with
surfaces=("action",)(or include"action"). The@tooldefault is("investigation",)only — the chat/Python-API action loop will not see investigation-only tools. - Tools may live in the package’s
__init__.pyor in submodules; both are scanned after registration.