Skip to main content

OpenHarness

Struct OpenHarness 

Source
pub struct OpenHarness { /* private fields */ }
Expand description

A direct-model harness over an OpenAI-compatible HTTP endpoint.

Implementations§

Source§

impl OpenHarness

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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).

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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

Source§

fn info(&self) -> Info

Who this harness is — identity and presentation, for the picker.
Source§

fn features(&self) -> Features

What this harness supports, so a consumer adapts to it declaratively instead of branching on Info::id. Read more
Source§

fn readiness(&self) -> Readiness

Probe availability / version / auth. May shell out; callers should treat it as blocking and run it off the UI thread.
Source§

fn start( &self, request: RunRequest, on_event: RunCallback, ) -> Result<RunHandle, Error>

Start a run, streaming events through on_event. Returns a handle immediately; work continues on background threads.
Source§

fn credential(&self) -> CredentialSpec

The credential this harness needs.
Source§

fn list_models(&self) -> Result<Vec<ModelChoice>, Error>

Enumerate the models this harness can run, live. The default returns the static list declared in Info (capabilities().models), so existing adapters need no change. Read more
Source§

fn model_management(&self) -> Option<ModelManagement>

Whether this harness can install/list/delete its own models locally, and if so the endpoint metadata a host UI can surface (see 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>

Installed local models with their on-disk size + details, for a manager UI (distinct from 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>

Download (install) a model, streaming progress to 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>

Remove an installed local model. Removing one that’s already absent succeeds (the requested end state). Default: unsupported.
Source§

fn login(&self, _on_event: InstallCallback) -> Result<(), Error>

Trigger the harness’s own interactive sign-in (its CLI’s OAuth), streaming progress as 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>

Convenience over 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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoMaybeUndefined<T> for T

Source§

impl<T> IntoOption<T> for T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more