Skip to content

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.

Install Rust 1.96 or newer through rustup, then create a binary project and add the SDK with the Tokio async runtime:

Terminal window
cargo new strands-quickstart
cd strands-quickstart
cargo add strands
cargo add tokio --features macros,rt-multi-thread

Create src/main.rs with an agent that uses Amazon Bedrock, the default model provider:

use strands::Agent;
#[tokio::main]
async fn main() -> strands::Result<()> {
let mut 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
cargo run

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.

Replace src/main.rs with a typed tool and pass its generated tool struct to the agent:

use strands::{Agent, ToolError, tool};
#[tool(description = "Count occurrences of a specific letter in a word. \
Performs case-insensitive matching.")]
async fn letter_counter(
/// Word to search.
word: String,
/// Letter to count.
letter: char,
) -> Result<usize, ToolError> {
Ok(word
.chars()
.filter(|candidate| candidate.eq_ignore_ascii_case(&letter))
.count())
}
#[tokio::main]
async fn main() -> strands::Result<()> {
let mut agent = Agent::builder().tools([LetterCounter]).build()?;
agent
.invoke(r#"How many letter R's are in the word "strawberry"?"#)
.await?;
agent.shutdown().await
}

Run the project again:

Terminal window
cargo run

The #[tool] macro generates the input schema from the typed parameters and the LetterCounter tool struct from the letter_counter function name.

To run the agent on Anthropic, OpenAI, or the Amazon Bedrock Mantle endpoint, enable the provider’s Cargo feature:

Terminal window
cargo add strands --no-default-features --features anthropic

Without the default bedrock feature, pass an explicit model to Agent::builder(). See the Rust API reference for provider builders and feature flags.