use bedrock_agentcore::{RequestContext, runtime::BedrockAgentCoreApp};
use serde::Deserialize;
use serde_json::{Value, json};
use strands::{Agent, ToolError, models::bedrock::BedrockModel, tool};
#[derive(Deserialize)]
struct Request {
prompt: String,
}
#[tool]
async fn get_weather(
city: String,
) -> Result<String, ToolError> {
Ok(format!("Sunny and 21°C in {city}"))
}
#[tokio::main]
async fn main() -> Result<(), bedrock_agentcore::Error> {
tracing_subscriber::fmt().with_ansi(false).init();
let model = BedrockModel::builder().model_id("global.anthropic.claude-sonnet-4-6").max_tokens(4096).build();
let handle = move |request: Request, ctx: RequestContext| {
let model = model.clone();
async move {
let mut agent = Agent::builder().model(model).tools([GetWeather]).printer(false).build()?;
let result = agent.invoke(request.prompt).await?;
agent.shutdown().await?;
Ok::<Value, strands::Error>(json!({
"result": result.to_string(),
"session_id": ctx.session_id(),
"request_id": ctx.request_id(),
}))
}
};
BedrockAgentCoreApp::builder().invocation(handle).build()?.run().await
}