pub struct OpenHarness { /* private fields */ }Expand description
A direct-model harness over an OpenAI-compatible HTTP endpoint.
Implementations§
Source§impl OpenHarness
impl OpenHarness
Sourcepub fn builtin_tool_names() -> Vec<String>
pub fn builtin_tool_names() -> Vec<String>
Every tool this harness can offer, for a host building the choice into
its own settings rather than hardcoding names that drift as tools are
added. Any of these may go in OpenHarnessConfig::disabled_tools.
Sourcepub fn ollama() -> Self
pub fn ollama() -> Self
Local Ollama on its default port, with live /api/tags discovery and
no auth. Chat hits Ollama’s native /api/chat (not /v1) so
num_ctx applies, so the model loads the intended context window
instead of Ollama’s truncating 4096 default.
Sourcepub fn ollama_at(base_url: impl Into<String>) -> Self
pub fn ollama_at(base_url: impl Into<String>) -> Self
Ollama served from somewhere other than the default port — a remote box,
a container, a second instance. Identical to Self::ollama in every
other respect, including the native /api/chat path.
Sourcepub fn custom(config: OpenHarnessConfig) -> Self
pub fn custom(config: OpenHarnessConfig) -> Self
Any other OpenAI-compatible endpoint (OpenRouter, vLLM, LM Studio, a
self-hosted gateway), configured by an OpenHarnessConfig so each
argument is named at the call site.
Sourcepub fn with_models_dev(self, provider: impl Into<String>) -> Self
pub fn with_models_dev(self, provider: impl Into<String>) -> Self
Discover models from the models.dev catalog for the
given provider id ("anthropic", "openai", …) instead of a static list
— for a cloud endpoint that proxies a known provider. Needs the
agent-harness/models-dev feature (which openai-compatible enables); with no
reachable catalog list_models falls back to empty (free-text entry).
Sourcepub fn with_openai_models(self) -> Self
pub fn with_openai_models(self) -> Self
List models by asking the endpoint, via the OpenAI-standard
/v1/models. The right mode for an endpoint configured at runtime — a
local LM Studio, a llama.cpp server, a gateway — where no adapter knows
the catalog up front.
Any models already declared become the fallback: a server that does not
serve /v1/models still offers what it was configured with, so the
picker degrades to today’s behaviour instead of to nothing.
Sourcepub fn with_session_dir(self, dir: impl Into<PathBuf>) -> Self
pub fn with_session_dir(self, dir: impl Into<PathBuf>) -> Self
Persist sessions under dir so runs are resumable: each run writes its
transcript here and RunRequest.resume continues a prior session by id.
Without this, the harness runs ephemerally (no disk writes).
Sourcepub fn with_context_tokens(self, tokens: u64) -> Self
pub fn with_context_tokens(self, tokens: u64) -> Self
Tell the runtime the model’s context-window size (in tokens), enabling compaction: as the transcript nears the limit, older turns are summarized and recent ones kept verbatim. Without it the full transcript is always replayed (fine for short sessions).
Sourcepub fn with_agent(self, name: impl Into<String>, def: AgentDef) -> Self
pub fn with_agent(self, name: impl Into<String>, def: AgentDef) -> Self
Register a named subagent the task tool can spawn via subagent_type
(e.g. a focused “reviewer” with its own prompt/model). Registration order
is preserved for the catalog shown to the model.
Sourcepub fn with_mcp_server(self, server: McpServer) -> Self
pub fn with_mcp_server(self, server: McpServer) -> Self
Register an MCP server to launch over stdio; its advertised tools are
offered to the model (namespaced name_tool) and dispatched alongside the
built-ins. Connection is best-effort — a server that fails to start or
handshake is skipped at run time (with a status line), never fatal.
Sourcepub fn with_model_cost(self, model: impl Into<String>, cost: ModelCost) -> Self
pub fn with_model_cost(self, model: impl Into<String>, cost: ModelCost) -> Self
Register per-token pricing for a model, so its runs emit an estimated cost
on crate::RunEvent::Usage. Rates are USD per million tokens.
Sourcepub fn with_permission_rule(self, rule: PermissionRule) -> Self
pub fn with_permission_rule(self, rule: PermissionRule) -> Self
Add a PermissionRule gating tool calls before execution (deny specific
dangerous calls, or allow-list specific ones then deny the rest). Rules
apply in the order added, to the main agent and its subagents.
Sourcepub fn with_permission_prompt(
self,
prompt: impl Fn(&PermissionRequest) -> bool + Send + Sync + 'static,
) -> Self
pub fn with_permission_prompt( self, prompt: impl Fn(&PermissionRequest) -> bool + Send + Sync + 'static, ) -> Self
Set the callback that decides Permission::Ask tool calls (true =
allow). It’s invoked synchronously on the run thread, so a host can block
on its own confirmation UI — the interactive permission channel. Without
it, Ask rules deny.
Sourcepub fn with_reasoning_tag(self, tag: impl Into<String>) -> Self
pub fn with_reasoning_tag(self, tag: impl Into<String>) -> Self
Set the inline reasoning tag lifted from streamed output into Thinking
— e.g. "think" for <think>…</think> (DeepSeek-R1, Qwen3), the default.
The convention is model-specific, so set it to match your model.
Sourcepub fn without_reasoning_extraction(self) -> Self
pub fn without_reasoning_extraction(self) -> Self
Disable inline reasoning extraction — stream content verbatim. Use for a non-reasoning model, or one whose reasoning arrives in a dedicated field (handled separately).
Sourcepub fn sessions(&self) -> Result<Vec<SessionRecord>, Error>
pub fn sessions(&self) -> Result<Vec<SessionRecord>, Error>
All persisted sessions for this harness (newest-updated first), or an empty list when no session dir is configured. Lets a host render a conversations view without driving a run.
Sourcepub fn mcp_prompts(&self) -> Vec<McpPrompt>
pub fn mcp_prompts(&self) -> Vec<McpPrompt>
List the prompt templates advertised by the configured MCP servers. Each
server is connected, queried, and disconnected, so this spawns the server
processes; a host surfaces the result for the user to pick from, then
resolves one with get_mcp_prompt to seed a run.
Sourcepub fn get_mcp_prompt(
&self,
server: &str,
name: &str,
arguments: &[(String, String)],
) -> Result<Vec<PromptMessage>, Error>
pub fn get_mcp_prompt( &self, server: &str, name: &str, arguments: &[(String, String)], ) -> Result<Vec<PromptMessage>, Error>
Resolve a prompt template (by server + name, with arguments) to its
messages, for a host to seed a run’s prompt.
Trait Implementations§
Source§impl Harness for OpenHarness
impl Harness for OpenHarness
Source§fn readiness(&self) -> Readiness
fn readiness(&self) -> Readiness
Source§fn start(
&self,
request: RunRequest,
on_event: RunCallback,
) -> Result<RunHandle, Error>
fn start( &self, request: RunRequest, on_event: RunCallback, ) -> Result<RunHandle, Error>
on_event. Returns a
handle immediately; work continues on background threads.Source§fn credential(&self) -> CredentialSpec
fn credential(&self) -> CredentialSpec
Source§fn list_models(&self) -> Result<Vec<ModelChoice>, Error>
fn list_models(&self) -> Result<Vec<ModelChoice>, Error>
Source§fn model_management(&self) -> Option<ModelManagement>
fn model_management(&self) -> Option<ModelManagement>
ModelManagement). None (the default) means model management isn’t
supported — a host hides the “Manage models” surface. Only the
openai-compatible Ollama adapter returns Some today.Source§fn list_installed_models(&self) -> Result<Vec<InstalledModel>, Error>
fn list_installed_models(&self) -> Result<Vec<InstalledModel>, Error>
list_models, the picker’s
name-only set). Default: unsupported — override alongside
model_management. Blocking (hits the local
server); run it off the UI thread.Source§fn pull_model(
&self,
model: &str,
cancel: &AtomicBool,
on_progress: PullProgressCallback<'_>,
) -> Result<(), Error>
fn pull_model( &self, model: &str, cancel: &AtomicBool, on_progress: PullProgressCallback<'_>, ) -> Result<(), Error>
on_progress. cancel
is polled during the download; flipping it aborts the pull. Blocking
until the download finishes (or fails / is cancelled); run it off the UI
thread. Default: unsupported.Source§fn delete_model(&self, model: &str) -> Result<(), Error>
fn delete_model(&self, model: &str) -> Result<(), Error>
Source§fn login(&self, _on_event: InstallCallback) -> Result<(), Error>
fn login(&self, _on_event: InstallCallback) -> Result<(), Error>
InstallEvents. The flow opens the user’s
browser; this blocks until the login process exits, then
Done { ok } reports success. This is the agent authenticating
itself — distinct from installing it, which the host’s user does.
Default: unsupported, for harnesses the host authenticates by key.Source§fn run(
&self,
request: RunRequest,
) -> Result<(RunHandle, Receiver<RunEvent>), Error>
fn run( &self, request: RunRequest, ) -> Result<(RunHandle, Receiver<RunEvent>), Error>
run for callers that want to
pull events off a channel instead of supplying a push callback.
Forwards each RunEvent into an mpsc channel and hands the
receiver back alongside the run handle, so the caller can simply
for event in rx { … } rather than re-write the
Arc::new(move |ev| tx.send(ev)) plumbing at every call site. Read more