prelude
Prelude module for common imports
Structs
Section titled “Structs”Core Agent implementation
The Agent struct is the main runtime entry point for registering skills,
wiring handlers, and dispatching runtime messages. Protocol surfaces such as
A2A and AG-UI compose around this type via adapter modules.
Methods
new_runtime
Section titled “new_runtime”fn new_runtime(name: &str) -> SdkResult<Self>Create a new runtime-first agent.
fn new(name: &str) -> SdkResult<Self>Create a new agent (alias of new_runtime)
new_with_config
Section titled “new_with_config”fn new_with_config(config: AgentConfig) -> SdkResult<Self>Create agent with custom configuration
with_service
Section titled “with_service”fn with_service<T>(self, service: T) -> Selfget_service
Section titled “get_service”fn get_service<T>(&self) -> Option<Arc<T>>has_service
Section titled “has_service”fn has_service<T>(&self) -> booladd_skill
Section titled “add_skill”fn add_skill(&mut self, skill_id: &str) -> SkillEntryBuilder<'_>Register a skill via the fluent builder (handler optional — omit for metadata-only).
fn skill<F, Fut>(&mut self, name: &str, handler: F) -> SkillEntryBuilder<'_>where F: Fn + Send + Sync + ?, Fut: Future + Send + ?Register a skill with a handler (add_skill(name).handler(handler)).
register_notification
Section titled “register_notification”fn register_notification<F, Fut>(&mut self, name: &str, handler: F) -> SdkResult<()>where F: Fn + Send + Sync + ?, Fut: Future + Send + ?Register a notification handler.
config
Section titled “config”fn config(&self) -> &AgentConfiglist_skills
Section titled “list_skills”fn list_skills(&self) -> Vec<String>list_notifications
Section titled “list_notifications”fn list_notifications(&self) -> Vec<String>skill_registry
Section titled “skill_registry”fn skill_registry(&self) -> &SkillRegistryGet read-only reference to the skill registry.
set_message_handler
Section titled “set_message_handler”fn set_message_handler<F, Fut>(&mut self, handler: F)where F: Fn + Send + Sync + ?, Fut: Future + Send + ?dispatch_message
Section titled “dispatch_message”async fn dispatch_message(&self, msg_ctx: MessageContext, task_ctx: Option<TaskContext>) -> SdkResult<RuntimeResponse>Unified entrypoint to route a built MessageContext through the active handler.
AgentConfig
Section titled “AgentConfig”Agent Configuration
Configuration for agent behavior, capabilities, and response patterns.
Response Modes
Section titled “Response Modes”The agent supports different response patterns:
- Stateful (default): Creates Task responses for conversation continuity
- Stateless: Prefers lightweight Message responses for API-style interactions
Examples
Section titled “Examples”use agent_sdk::agent::AgentConfig;
// Default stateful agentlet config = AgentConfig::default();
// Stateless agent for API-style interactionslet config = AgentConfig::new("api-agent", "API Agent") .stateless();Fields
| Field | Type | Description |
|---|---|---|
name | String | |
description | String | |
version | String | |
storage_prefix | Option<String> | Optional storage namespace prefix used by shared task-storage backends. |
max_message_size | u64 | |
streaming | bool | |
batch_processing | bool | |
concurrent_tasks | Option<u32> | |
stateless_methods | bool | Prefer stateless responses (Message) over stateful (Task) for methods |
base_url | Option<String> | Base URL for constructing absolute AgentInterface URLs in the agent card. |
history_policy | Option<HistoryPolicyConfig> | Optional history policy used for durable continuation preparation. |
Methods
fn new<impl Into<String>, impl Into<String>>(name: impl Into, description: impl Into) -> SelfCreate a new agent configuration
Arguments
Section titled “Arguments”name- Agent namedescription- Agent description
Examples
Section titled “Examples”use agent_sdk::agent::AgentConfig;
let config = AgentConfig::new("my-agent", "My Agent Description");stateless
Section titled “stateless”fn stateless(self) -> SelfConfigure agent for stateless method responses
When enabled, methods will prefer lightweight Message responses over Task responses for API-style interactions.
Examples
Section titled “Examples”use agent_sdk::agent::AgentConfig;
let config = AgentConfig::new("api-agent", "API Agent") .stateless();stateful
Section titled “stateful”fn stateful(self) -> SelfConfigure agent for stateful method responses (default)
Methods will create Task responses for conversation continuity.
Examples
Section titled “Examples”use agent_sdk::agent::AgentConfig;
let config = AgentConfig::default() .stateful(); // Explicit stateful (default behavior)with_base_url
Section titled “with_base_url”fn with_base_url<impl Into<String>>(self, url: impl Into) -> SelfSet the base URL for absolute AgentInterface URLs in the agent card.
The A2A v1.0 spec requires absolute URLs in AgentInterface.url.
When set, the SDK produces {base_url}/jsonrpc instead of /jsonrpc.
with_history_policy
Section titled “with_history_policy”fn with_history_policy(self, policy: HistoryPolicyConfig) -> SelfAttach a history policy for pre/post-turn continuation preparation.
ServiceContainer
Section titled “ServiceContainer”Minimal service container for dependency injection
Allows agents to accept optional services through clean dependency injection without hardcoding specific service fields in the Agent struct.
Examples
Section titled “Examples”use agent_sdk::services::ServiceContainer;use std::sync::Arc;
#[derive(Clone)]struct MyService { name: String,}
let mut container = ServiceContainer::new();container.register(MyService { name: "test".to_string() });
let service: Option<Arc<MyService>> = container.get();assert!(service.is_some());Methods
fn new() -> SelfCreate a new empty service container
register
Section titled “register”fn register<T>(&mut self, service: T)Register a service in the container
Services are stored by their type and can be retrieved later using the same type signature.
Arguments
Section titled “Arguments”service- The service instance to register
Examples
Section titled “Examples”# use agent_sdk::services::ServiceContainer;# #[derive(Clone)]# struct DatabaseService;let mut container = ServiceContainer::new();container.register(DatabaseService);fn get<T>(&self) -> Option<Arc<T>>Get a service from the container
Returns an Arc-wrapped service if found, or None if the service type is not registered.
Returns
Section titled “Returns”Some(Arc<T>)- The service if foundNone- If no service of type T is registered
Examples
Section titled “Examples”# use agent_sdk::services::ServiceContainer;# use std::sync::Arc;# #[derive(Clone)]# struct DatabaseService { pub name: String }# let mut container = ServiceContainer::new();# container.register(DatabaseService { name: "test".to_string() });let service: Option<Arc<DatabaseService>> = container.get();if let Some(db) = service { println!("Database: {}", db.name);}fn has<T>(&self) -> boolCheck if a service type is registered
Returns
Section titled “Returns”true- If a service of type T is registeredfalse- If no service of type T is found
Examples
Section titled “Examples”# use agent_sdk::services::ServiceContainer;# #[derive(Clone)]# struct CacheService;let container = ServiceContainer::new();assert!(!container.has::<CacheService>());fn len(&self) -> usizeGet the number of registered services
is_empty
Section titled “is_empty”fn is_empty(&self) -> boolCheck if the container is empty
fn clear(&mut self)Remove all services from the container
SkillCall
Section titled “SkillCall”Skill Call Information
Extracted from DataPart when a structured skill call is detected.
Fields
| Field | Type | Description |
|---|---|---|
skill_id | String | |
parameters | serde_json::Value |
SkillDefinition
Section titled “SkillDefinition”Protocol-independent skill definition.
This is the single source of truth for skill metadata inside the SDK.
Protocol adapters (A2A AgentSkill, MCP, etc.) convert from this type.
Fields
| Field | Type | Description |
|---|---|---|
id | String | |
name | String | |
description | String | |
input_modes | Vec<String> | |
output_modes | Vec<String> | |
schema | Option<serde_json::Value> | |
examples | Option<Vec<String>> | |
tags | Option<Vec<String>> | |
instructions | Option<String> | Behavioral guidance injected into LLM context when this skill is activated. |
expose | bool | Whether the skill is visible on the discovery card (default: true). |
llm_callable | bool | Whether the LLM can invoke this skill’s handler via read_skill tool (default: false). |
SkillEntryBuilder
Section titled “SkillEntryBuilder”Fluent builder for skill registration.
Created via [SkillRegistry::add_skill] / [crate::Agent::add_skill], or [SkillRegistry::skill] /
[crate::Agent::skill] when providing a handler. Finalize with .register().
Methods
handler
Section titled “handler”fn handler<F, Fut>(self, handler: F) -> Selfwhere F: Fn + Send + Sync + ?, Fut: Future + Send + ?Attach an async handler. Omit for metadata-only skills (discovery card + LLM awareness).
display_name
Section titled “display_name”fn display_name<S>(self, name: S) -> Selfdescription
Section titled “description”fn description<S>(self, desc: S) -> Selfschema
Section titled “schema”fn schema(self, schema: Value) -> Selfexamples
Section titled “examples”fn examples(self, examples: Vec<String>) -> Selfexample
Section titled “example”fn example<S>(self, example: S) -> Selffn tags(self, tags: &[&str]) -> Selffn tag<S>(self, tag: S) -> Selfinput_modes
Section titled “input_modes”fn input_modes(self, modes: &[&str]) -> Selfoutput_modes
Section titled “output_modes”fn output_modes(self, modes: &[&str]) -> Selfjson_only
Section titled “json_only”fn json_only(self) -> Selftext_only
Section titled “text_only”fn text_only(self) -> Selfinstructions
Section titled “instructions”fn instructions<S>(self, text: S) -> SelfSet behavioral instructions (injected into LLM context when skill is activated).
expose
Section titled “expose”fn expose(self, visible: bool) -> SelfControl whether the skill is visible on the discovery card (default: true).
llm_callable
Section titled “llm_callable”fn llm_callable(self, callable: bool) -> SelfControl whether the LLM can invoke this skill via read_skill tool (default: false).
register
Section titled “register”fn register(self) -> SdkResult<()>Finalize registration.
MessageType
Section titled “MessageType”Message Type Classification
Classifies incoming messages based on their Part composition to determine the appropriate handling strategy (tool-like vs conversational vs hybrid).
Variants
| Variant | Description |
|---|---|
Data | Pure DataPart - structured tool calls |
Text | Pure TextPart - conversational interactions |
Mixed | Multiple part types - hybrid interactions |
SdkError
Section titled “SdkError”SDK-specific error types
Wraps underlying A2A protocol errors and adds SDK-specific error cases for better error handling and user experience.
Variants
| Variant | Description |
|---|---|
A2AProtocol(error::A2AError) | A2A protocol error |
Configuration { ... } | Configuration error |
AgentInitialization { ... } | Agent initialization error |
SkillRegistration { ... } | Skill registration error |
MethodExecution { ... } | Method execution error |
Serialization(serde_json::Error) | Serialization error |
Io(Error) | IO error |
Generic(anyhow::Error) | Generic error |
FeatureNotEnabled { ... } | Feature not enabled |
InvalidInput { ... } | Invalid input |
Methods
configuration
Section titled “configuration”fn configuration<impl Into<String>>(details: impl Into) -> SelfCreate a configuration error
agent_initialization
Section titled “agent_initialization”fn agent_initialization<impl Into<String>>(reason: impl Into) -> SelfCreate an agent initialization error
skill_registration
Section titled “skill_registration”fn skill_registration<impl Into<String>, impl Into<String>>(skill: impl Into, reason: impl Into) -> SelfCreate a skill registration error
method_execution
Section titled “method_execution”fn method_execution<impl Into<String>, impl Into<String>>(method: impl Into, details: impl Into) -> SelfCreate a method execution error
feature_not_enabled
Section titled “feature_not_enabled”fn feature_not_enabled<impl Into<String>>(feature: impl Into) -> SelfCreate a feature not enabled error
invalid_input
Section titled “invalid_input”fn invalid_input<impl Into<String>>(details: impl Into) -> SelfCreate an invalid input error
is_recoverable
Section titled “is_recoverable”fn is_recoverable(&self) -> boolCheck if error is recoverable
category
Section titled “category”fn category(&self) -> &''static strGet error category for monitoring/logging