This quickstart takes you to a running Rust agent with one custom tool. You install
the SDK, invoke the default Amazon Bedrock model, and use #[tool] to expose an
async function to the agent loop.
Using a coding agent? Copy this prompt into Codex, Claude Code, Kiro, or any coding assistant and it will walk you through this page, ask a few setup questions, and offer to set up the Strands MCP server.
Help me build my first agent with the Strands Harness SDK in Rust. The Rust SDK is in
developer preview, so verify every API against the current repository documentation.
Work through these steps in order, checking with me before installing software or
writing files.
Step 1: Environment
Confirm Rust 1.96 or newer is available. Create a new project and add the Tokio async
runtime. Wait until I choose a provider before adding the Strands dependency:
cargo new strands-quickstart
cd strands-quickstart
cargo add tokio --features macros,rt-multi-thread
Step 2: Pick a model provider and run a first agent
Ask me which model provider I want to use:
- Amazon Bedrock (default): AWS credentials or AWS_BEARER_TOKEN_BEDROCK
- Anthropic: ANTHROPIC_API_KEY
- OpenAI: OPENAI_API_KEY
- Amazon Bedrock Mantle: AWS credentials, AWS_REGION, and optionally MANTLE_MODEL_ID
Add the matching dependency:
- Amazon Bedrock: cargo add strands
- Anthropic: cargo add strands --no-default-features --features anthropic
- OpenAI: cargo add strands --no-default-features --features openai
- Amazon Bedrock Mantle: cargo add strands --no-default-features --features mantle
Then create src/main.rs with the exact snippet for my provider.
Amazon Bedrock:
use strands::Agent;
#[tokio::main]
async fn main() -> strands::Result<()> {
let mut agent = Agent::builder()
.system_prompt("You are a concise assistant.")
.build()?;
agent
.invoke("What is an agent harness, in one sentence?")
.await?;
agent.shutdown().await
}
Anthropic:
use strands::models::anthropic::AnthropicModel;
use strands::Agent;
#[tokio::main]
async fn main() -> strands::Result<()> {
let model = AnthropicModel::builder()
.model_id("claude-sonnet-4-6")
.max_tokens(1024)
.build()?;
let mut agent = Agent::builder()
.model(model)
.system_prompt("You are a concise assistant.")
.build()?;
agent
.invoke("What is an agent harness, in one sentence?")
.await?;
agent.shutdown().await
}
OpenAI:
use strands::models::openai::OpenAIModel;
use strands::Agent;
#[tokio::main]
async fn main() -> strands::Result<()> {
let model = OpenAIModel::builder()
.model_id("gpt-5.4-mini")
.build()?;
let mut agent = Agent::builder()
.model(model)
.system_prompt("You are a concise assistant.")
.build()?;
agent
.invoke("What is an agent harness, in one sentence?")
.await?;
agent.shutdown().await
}
Amazon Bedrock Mantle:
use strands::models::openai::{
BedrockMantleConfig,
OpenAIModel,
OpenAIModelOptions,
};
use strands::Agent;
#[tokio::main]
async fn main() -> strands::Result<()> {
let region =
std::env::var("AWS_REGION").unwrap_or_else(|_| "us-east-1".to_owned());
let model_id = std::env::var("MANTLE_MODEL_ID")
.unwrap_or_else(|_| "openai.gpt-oss-120b".to_owned());
let model = OpenAIModel::bedrock_mantle(
OpenAIModelOptions::builder()
.model_id(model_id)
.build_options(),
BedrockMantleConfig::builder().region(region).build(),
)?;
let mut agent = Agent::builder()
.model(model)
.system_prompt("You are a concise assistant.")
.build()?;
agent
.invoke("What is an agent harness, in one sentence?")
.await?;
agent.shutdown().await
}
Run it with cargo run.
Step 3: Add a custom tool
Keep the provider imports and model construction from Step 2. Replace
use strands::Agent with:
use strands::{Agent, ToolError, tool};
#[tool(description = "Count occurrences of a letter in a word.")]
async fn letter_counter(word: String, letter: char) -> Result<usize, ToolError> {
Ok(word
.chars()
.filter(|candidate| candidate.eq_ignore_ascii_case(&letter))
.count())
}
In the existing Agent::builder() chain, add .tools([LetterCounter]) before .build().
Keep .model(model) when the selected provider created an explicit model. Then replace
the invocation prompt with:
agent
.invoke(r#"How many letter R's are in the word "strawberry"?"#)
.await?;
Run cargo run again. Explain that #[tool] uses the signature for the input schema,
the function name for the LetterCounter struct, and the description attribute for
the model-facing description.
Step 4: Offer the Strands MCP server (ask first, do not install without confirmation)
Strands ships an MCP server that gives you live access to the Strands documentation while
you work, so the code you generate follows current APIs. Ask me whether I want it set up
in this coding tool. If I say yes, it requires uv (https://github.com/astral-sh/uv).
The server runs as: command "uvx", args ["strands-agents-mcp-server"]. Config locations:
- Kiro: ~/.kiro/settings/mcp.json under "mcpServers"
- Cursor: ~/.cursor/mcp.json under "mcpServers"
- Claude Code: run `claude mcp add strands uvx strands-agents-mcp-server`
- Codex: ~/.codex/config.toml as [mcp_servers.strands-agents]
- VS Code: mcp.json under "servers"
If I say no, skip this step entirely.
Throughout: prefer the Strands docs at https://strandsagents.com/docs/ over memory. Use
tools from the Strands Harness SDK (vended tools) or custom tools instead of a separate community package.
Create src/main.rs with an agent that uses Amazon Bedrock, the default model
provider:
usestrands::Agent;
#[tokio::main]
asyncfnmain() ->strands::Result<()> {
letmut agent =Agent::builder().build()?;
agent.invoke("What is an agent harness, in one sentence?").await?;
agent.shutdown().await
}
The default model is Claude Sonnet 4.6 on Amazon Bedrock. Give the SDK AWS
credentials with permission to invoke the model, using one of:
Bedrock API key: set AWS_BEARER_TOKEN_BEDROCK to a
Bedrock API
key.
AWS credentials: run aws configure, use an AWS profile, or set the AWS
credential environment variables.
IAM role: run the agent on an AWS service with an attached role.
Set AWS_REGION to a region where the model is available. The SDK uses
us-west-2 when no region is configured.
Run the agent:
Terminal window
cargorun
The default printer streams the model response to the terminal. Each invocation
also returns an
AgentResult
with the final response, stop reason, and metrics. Call shutdown() before the
process exits so the agent can finish cleanup.