Skip to main content

bedrock_agentcore/
lib.rs

1//! Amazon Bedrock AgentCore SDK for Rust.
2//!
3//! The `runtime` module hosts an agent on
4//! [AgentCore Runtime](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/agents-tools-runtime.html).
5//! It serves `POST /invocations` and `GET /ping` as the Runtime HTTP contract requires.
6//!
7// The example needs the `runtime` feature. Without it the code block is not compiled.
8#![cfg_attr(feature = "runtime", doc = "```no_run")]
9#![cfg_attr(not(feature = "runtime"), doc = "```ignore")]
10//! use bedrock_agentcore::{RequestContext, runtime::BedrockAgentCoreApp};
11//! use serde_json::{Value, json};
12//!
13//! async fn handle(payload: Value, ctx: RequestContext) -> Result<Value, std::convert::Infallible> {
14//!     Ok(json!({ "echo": payload, "session_id": ctx.session_id() }))
15//! }
16//!
17//! #[tokio::main]
18//! async fn main() -> Result<(), bedrock_agentcore::Error> {
19//!     BedrockAgentCoreApp::builder().invocation(handle).build()?.run().await
20//! }
21//! ```
22//!
23//! The `identity` module gets the credentials that the agent needs for the services
24//! it calls, such as API keys, from
25//! [AgentCore Identity](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/identity.html).
26//!
27//! # Features
28//!
29//! - `runtime` (default): the HTTP server in the `runtime` module.
30//! - `identity` (default): the client of AgentCore Identity in the `identity` module.
31//!   It depends on the AWS SDK for Rust.
32//!
33//! With neither feature the crate has no networking dependencies. The [`context`]
34//! and [`tasks`] modules are always available.
35
36#![forbid(unsafe_code)]
37#![warn(missing_docs, missing_debug_implementations, unreachable_pub)]
38
39pub mod context;
40mod error;
41#[cfg(feature = "identity")]
42pub mod identity;
43#[cfg(feature = "runtime")]
44pub mod runtime;
45pub mod tasks;
46
47pub use context::RequestContext;
48pub use error::{Error, ErrorKind};
49/// The `http` crate, whose header types appear in [`RequestContext`]. With this
50/// re-export a caller can write `bedrock_agentcore::http::HeaderValue` without a
51/// dependency on `http` of its own.
52pub use http;