Expand description
harness-rs — facade re-exporting the public surface of the harness-rs
agent framework.
Most users depend only on this crate. It re-exports harness-core (traits +
types), the procedural macros from harness-macros, and exposes
harness-skills under the skills module. The lower-level crates remain
available individually for anyone who wants a minimal dependency footprint.
§What is a harness?
An agent in this framework is a Model + a harness — the surrounding
scaffold that decides what the model can see (Guide), what tools it can
call (Tool), what feedback signals come back to it (Sensor), what
policies wrap each step (Hook), and how its context is kept small
(Compactor). The AgentLoop in harness-rs-loop ties these together
in a ReAct loop with self-correction.
See DESIGN.md at the workspace root for the architectural intent.
§Quick start
Define a tool with #[tool], point the model adapter at any
OpenAI-compatible endpoint, and run the loop:
use harness::{tool, ToolError};
use harness_loop::AgentLoop;
use harness_models::OpenAiCompat;
use harness_context::default_world;
use harness_core::{Policy, Task};
use std::sync::Arc;
/// Add two integers.
#[tool(name = "add", risk = "Safe")]
async fn add(a: i64, b: i64) -> Result<i64, ToolError> {
Ok(a + b)
}
let model = OpenAiCompat::with_key(
"https://api.deepseek.com",
"deepseek-chat",
std::env::var("DEEPSEEK_API_KEY")?,
);
let loop_ = AgentLoop::new(model).with_tool(Arc::new(add()));
let mut world = default_world(std::env::current_dir()?);
let outcome = loop_
.run(
Task { description: "What is 2 + 3?".into(),
source: None, deadline: None },
&mut world,
)
.await?;
println!("{outcome:?}");§Examples
Worked examples live at https://github.com/liliang-cn/harness-rs/tree/main/examples:
deepseek-hello— smallest possible Hello-world.crate-keeper—MockModelsmoke test (no network).personal-assistant— scheduling agent withUserProfile, REPL, brief mode.investor-bot— autonomous web research with multi-engine search + retry.
§Crate map
harness_core—Model/Tool/Guide/Sensor/Hook/Compactor/Skilltraits,World,Context,Event, error types.harness_macros—#[skill]/#[tool]/#[guide]/#[sensor]/#[hook]proc-macros.harness_loop—AgentLoopReAct executor with auto-fix sensors.harness_hooks—HookBusover 27 lifecycle events.harness_blueprint— hybrid deterministic + agent state machine.harness_compactor— five-stage progressive context compaction.harness_sandbox—WorktreeSandbox(default) + container/VM stubs.harness_models—OpenAiCompat/AnthropicNative/MockModel.harness_mcp— MCP stdio JSON-RPC server.skills— agentskills.io-compliant skill loader + validator.harness_tools_fs/harness_tools_shell— built-in toolsets.harness_sensors_rust/harness_sensors_common— built-in sensors.
Modules§
- compactor
- context
- embed
- Optional embeddings trait. Strictly opt-in — nothing in
Model,AgentLoop,Hook,Guide,Sensor, orMemoryreferences this. Code that wants semantic search / vector recall holds anArc<dyn Embedder>explicitly; everything else compiles without ever touching this module. - error
- event
- guide
- hook
- memory
- Long-term, cross-session memory.
- model
- prelude
- profile
- User profile — ambient context every agent inherits.
- recall
- Cross-session conversation recall.
- recall_
testkit - Reusable conformance suite for
crate::RecallStorebackends. Each backend crate callsrecall_contract(store)from a#[tokio::test]so all impls are held to identical behaviour — including the privacy-critical owner isolation. - sensor
- signal
- skill
Skilltrait — strictly aligned with the agentskills.io specification.- skills
- agentskills.io-compliant skill loading.
- tool
- world
Structs§
- Action
- One action the agent has asked to take, paired with the originating tool call.
- Budget
- Code
Span - Context
- The model-visible state of an in-progress agent run.
- DynModel
- A concrete newtype wrapping a boxed model, so an
Arc<dyn Model>can be used where a concreteM: Modelis required (e.g.Subagent::new/AgentLoop<M>). - Guide
Entry - Harness
Ext - Optional
metadata.harness.*sub-tree. Spec-compliant: keys other agents don’t recognise are simply ignored. - Hook
Entry inventoryslot for compile-time hook registration via#[hook].- Memory
Entry - One persisted memory record.
- Model
Info - Information about a configured model — uniform across providers.
- Model
Output - Policy
- Process
Output - Recall
Message - One transcript message in a recall session.
- Repo
View - Runtime view of the filesystem / repo the agent operates on.
- Resource
- A non-
SKILL.mdresource bundled with the skill (scripts/*,references/*,assets/*). - Sensor
Entry - Session
Hit - A search hit: the matched session plus enough surrounding messages for the agent to orient (Hermes-style bookends + a window around the anchor).
- Session
Meta - Metadata about one session.
- Signal
- A feedback signal from a sensor — optimised for LLM consumption.
- Signal
Set - A bundle of signals, with helpers for the agent loop.
- Skill
Entry inventoryslot for compile-time skill registration via#[skill].- Skill
Manifest - The frontmatter of a
SKILL.md, exactly as specified. - Task
- Tool
Call - Tool
Entry inventoryslot for compile-time tool registration via#[tool].- Tool
Result - Tool
Schema - Turn
- A single conversation turn (assistant or user).
- Usage
- User
Profile - Ambient information about who the agent is working for.
- World
- Things the agent and its sensors can do that aren’t covered by a Tool.
Enums§
- Block
- A single block of content within the assembled prompt.
- Compact
Error - Compaction
Stage - The 5 progressive compaction stages (DESIGN.md §9 — borrowed from Claude Code).
- Embed
Error - Failures from an
Embedder::embedcall. Kept separate fromModelErrorbecause the surfaces differ (no thinking, no tools, no streaming) and we don’t want adapters reaching across modules. - Event
- All 27 lifecycle events the framework emits (DESIGN.md §10).
- Execution
- How a control-plane component executes:
- FixPatch
- A direct patch a sensor can apply without going through the model.
- Guide
Error - Guide
Scope - What kind of work this guide applies to. Determines when
applyruns. - Harness
Error - Hook
Outcome - What a hook tells the runtime to do after firing.
- Memory
Error - Model
Delta - Streaming delta — incremental output from the model.
- Model
Error - Notification
Kind - Recall
Error - Resource
Kind - Response
Format - Constrain the model’s terminal (non-tool-call) reply shape. Default = Free.
- Sensor
Error - Session
Source - Severity
- Skill
Error - Stage
- When in the change lifecycle a sensor runs (DESIGN.md §3, lifecycle distribution).
- Stop
Reason - Subagent
Status - Subagent self-report (Superpowers convention).
- Tool
Error - Tool
Risk - Risk class for a tool — drives sandbox / permission decisions.
- Turn
Role
Constants§
- VERSION
- Crate version for diagnostic logging.
Traits§
- Clock
- Compactor
- Embedder
- Producer of fixed-dimension float vectors for input text. Batched.
- Embedder
Ext - Convenience: one-shot single-string embed. Default impl wraps
embed. - Guide
- Hook
- KvStore
- Memory
- The open-memory primitive.
- Model
- Process
Runner - Recall
Store - Cross-session transcript store. All methods are owner-scoped: a given
ownercan never see another owner’s sessions. - Sensor
- Skill
- Tool
Functions§
- dot
- Plain dot product. With both vectors L2-normalised this equals cosine similarity. Bounded by ±1 in that case; outside that for raw vectors.
- iter_
macro_ guides - iter_
macro_ hooks - Enumerate every
#[hook]-registered hook. - iter_
macro_ sensors - iter_
macro_ skills - Enumerate every
#[skill]-registered skill (filesystem-loaded skills are separate — seeharness-skillsforscan_skills_root). - iter_
macro_ tools - l2_
normalize - Mutate
vin place to unit length (L2). No-op on zero vector. Callers that want cosine similarity should normalise both query and corpus once, then use dot product. - recall_
contract - Run the full contract against a fresh, empty
store.
Type Aliases§
- GuideId
- Result
- Sensor
Id - Skill
Handler - Optional in-process handler attached to a skill (only
#[skill]-generated skills carry one).