Skip to main content

Crate strands_harness

Crate strands_harness 

Source
Expand description

A preconfigured Strands agent in one call.

A thin composition layer over the strands crate: create_harness wires a resolved model, the vended system prompt, built-in tools, context management, session persistence, skills and long-term memory into a plain strands::Agent, which callers can change or extend like any other agent.

use strands::{InterruptResponse, StopReason};
use strands_harness::{Effort, HarnessAgentOptions, create_harness};

let mut agent = create_harness(
    HarnessAgentOptions::builder()
        .model("anthropic/claude-opus-5")
        .effort(Effort::High)
        .interventions("ask")
        .mcp_servers("./mcp.json")
        .build(),
)
.await?;

let mut result = agent.invoke("Fix the failing test in src/lib.rs").await?;
while result.stop_reason() == StopReason::Interrupt {
    let answers: Vec<InterruptResponse> = result.interrupts().iter().map(ask_user).collect();
    result = agent.invoke(answers).await?;
}
agent.shutdown().await?;

§Models

model takes a model or router, or a string: bedrock/<id>, bedrock-mantle/<id>, anthropic/<id>, openai/<id>, or a bare Bedrock model id. The default is bedrock/global.anthropic.claude-opus-5. Effort maps to each provider’s reasoning fields, and prompt caching is on by default.

§Features

FeatureAdds
bedrock (default)bedrock/ model strings and the default model
anthropic (default)anthropic/ model strings
openai (default)openai/ model strings
mantle (default)bedrock-mantle/ model strings; turns on openai
mcp (default)mcp_servers
cedar (default).cedar interventions
monty-pool (default)programmatic_tool_caller in a monty worker subprocess (Isolation)
otelSpan export selected by OTEL_TRACES_EXPORTER

Re-exports§

pub use plugins::EnvironmentContext;
pub use plugins::EnvironmentContextConfig;
pub use tools::file_tools::edit_tool;
pub use tools::file_tools::read_tool;
pub use tools::file_tools::write_tool;
pub use tools::programmatic_tool_caller::DEFAULT_PROGRAMMATIC_TOOL_CALLER_DESCRIPTION;
pub use tools::programmatic_tool_caller::Isolation;
pub use tools::programmatic_tool_caller::MakeProgrammaticToolCallerOptions;
pub use tools::programmatic_tool_caller::ProgrammaticToolCaller;
pub use tools::programmatic_tool_caller::ProgrammaticToolCallerConfig;
pub use tools::programmatic_tool_caller::make_programmatic_tool_caller;
pub use tools::programmatic_tool_caller::programmatic_tool_caller;
pub use tools::web_fetch::WebFetchConfig;
pub use tools::web_fetch::WebFetchTransport;
pub use tools::web_fetch::web_fetch_tool;
pub use tools::web_search::WebSearchSetting;
pub use tools::web_search::web_search_tool;
pub use tools::web_search::MakeAgentCoreWebSearchOptions;

Modules§

plugins
Harness-authored plugins.
tools
Harness-authored tools.

Structs§

AgentSpec
The resolved configuration of one child agent, handed to the ChildAgentBuilder (AgentSpec). None fields inherit from the parent.
BuiltinToolsConfig
Edits to the default built-in tool set (BuiltinToolsConfig). false disables a tool, true enables it, and a per-tool config enables and configures it (web_search takes WebSearchSetting::Exa instead). all is the portable config’s "*" key (default true): it includes the harness defaults; set it to false to start from nothing and enable tools one by one.
ChildAgentBuilder
Turns a resolved spec into a child agent, built the way the parent was (AgentBuilder). The builder may be async: the child is awaited before it runs.
Choice
The model picks from a developer-supplied set (Choice); with multiple, more than one.
ChoiceOption
A selectable entry of a Choice (named to stay clear of the prelude’s Option).
Fixed
The developer pins the value; the axis adds no model-facing parameter (Fixed).
HarnessAgentConfig
The complete portable form of a harness definition (HarnessAgentConfig).
HarnessAgentOptions
Options for create_harness (HarnessAgentOptions). Every field is optional.
HarnessAgentOptionsBuilder
Builds HarnessAgentOptions; the setters are its fields.
HarnessConfigBuiltinTools
JSON form of BuiltinToolsConfig (HarnessConfigBuiltinTools), with web_fetch.model allowed to be a module reference.
HarnessConfigMemory
JSON form of MemoryConfig (HarnessConfigMemory); stores are declared separately as memoryStores module references.
HarnessConfigWebFetch
JSON form of WebFetchConfig (HarnessConfigWebFetch).
HarnessDependencies
Dependencies a project declares for the runtimes that load its modules (HarnessDependencies).
HarnessModuleReference
A reference to a value defined in code (HarnessModuleReference). Rust parses and keeps these so a config round-trips, but cannot load them yet.
Inherit
The child takes the parent’s value; the axis adds no model-facing parameter (Inherit).
MakeSubagentOptions
Options for make_subagent (MakeSubagentOptions).
MemoryConfig
The harness’s default long-term memory (MemoryConfig); the empty config selects the defaults. For a different policy pass the SDK’s memory_manager instead.
Open
The model writes the value freely; the axis adds a string parameter (Open).
Preset
A named role, selected with agent_type: a partial child configuration (Preset).
ReadConfig
Per-tool config for the read built-in (ReadConfig).
SessionConfig
Session persistence (SessionConfig); the empty config selects the defaults.
ShellConfig
Per-tool config for the shell built-in (ShellConfig).
SubagentConfig
Per-tool config for the subagent built-in (SubagentConfig).
SubagentTool
The subagent tool: builds a fresh child per call and streams it (SubagentTool).

Enums§

BuiltinPluginName
A built-in feature plugin (BuiltinPluginName).
BuiltinToolName
A built-in tool (BuiltinToolName).
BuiltinToolsOption
What builtin_tools accepts: a list pins exactly those tools (an empty list disables them all), a mapping edits the defaults.
Effort
Reasoning effort applied to the resolved model (Effort); see HarnessAgentOptions::effort.
HarnessConfigBuiltinToolsOption
The portable builtinTools: a list of names or a mapping.
HarnessConfigContextManager
The portable contextManager (HarnessConfigContextManager: "auto", "agentic" or false; JSON also accepts "off" for false).
HarnessConfigInterventions
The portable interventions: one value or a list (presets, .cedar paths, policies).
HarnessConfigMcpServers
The portable mcpServers: a path to a JSON file, or the server map itself.
HarnessConfigModel
The summarizer model in a portable web_fetch config: a "provider/name" string or a model module reference.
HarnessConfigSkills
The portable skills: on or off, one source, or a list of sources.
HarnessModuleKind
What a module reference provides (HarnessModuleKind).
HarnessModuleLanguage
The language a module reference is written in (HarnessModuleLanguage).
InterventionValue
One interventions value (InterventionValue): a preset, a .cedar path or a policy string, or a handler.
InterventionsOption
What interventions accepts (InterventionsOption): one value, or a list layering, for example, a Cedar policy with one human gate.
McpServersOption
Where mcp_servers come from. The type exists with or without the mcp feature; without it, create_harness fails when servers are set.
MemoryOption
What memory accepts.
SessionOption
What session accepts.
Setting
A setting that is a boolean or a config object, such as a built-in tool’s entry in BuiltinToolsConfig: on, off, or on with a config.
SkillsOption
What skills accepts.

Constants§

BUILTIN_PLUGIN_NAMES
Every built-in plugin (BUILTIN_PLUGIN_NAMES).
BUILTIN_TOOL_NAMES
Every built-in tool, in canonical order (BUILTIN_TOOL_NAMES).
HARNESS_CONTRACT
The model-neutral behavioral contract every harness system prompt starts with.

Statics§

DEFAULT_HARNESS_AGENT_CONFIG
The defaults every key of a portable config falls back to (DEFAULT_HARNESS_AGENT_CONFIG).

Functions§

build_system_prompt
Assembles the harness contract, an optional domain block and per-request context, separated by blank lines.
create_harness
Builds a preconfigured Strands agent with the harness defaults.
define_harness_agent_config
Validates a config built in code the way a parsed one is.
harness_agent_options_from_config
Maps a portable config onto HarnessAgentOptions.
make_subagent
Creates a subagent tool whose input schema follows the axis policies and presets.
supports_thinking
Whether reasoning can be configured for model: true for a model instance or router; for a string, whether its provider and model take any reasoning level. None is the harness default model.
supports_web_search
Whether web_search works for model without the Exa opt-in: where the provider has native search, and on every Bedrock API, where AgentCore web search serves it. false for a model instance or router, whose provider is unknown; None is the harness default model.

Type Aliases§

ContextManagerOption
What context_manager accepts (ContextManagerOption): exactly the SDK’s ContextManagerStrategy, whose Disabled stands for both false and null.