pub trait ReadonlyContext: Send + Sync {
Show 16 methods
// Required methods
fn invocation_id(&self) -> &str;
fn agent_name(&self) -> &str;
fn user_id(&self) -> &str;
fn app_name(&self) -> &str;
fn session_id(&self) -> &str;
fn branch(&self) -> &str;
fn user_content(&self) -> &Content;
// Provided methods
fn acting_context(&self) -> ActingContext { ... }
fn is_authenticated(&self) -> bool { ... }
fn state(&self) -> Option<&dyn State> { ... }
fn try_app_name(&self) -> Result<AppName, AdkError> { ... }
fn try_user_id(&self) -> Result<UserId, AdkError> { ... }
fn try_session_id(&self) -> Result<SessionId, AdkError> { ... }
fn try_invocation_id(&self) -> Result<InvocationId, AdkError> { ... }
fn try_identity(&self) -> Result<AdkIdentity, AdkError> { ... }
fn try_execution_identity(&self) -> Result<ExecutionIdentity, AdkError> { ... }
}Expand description
Core traits and types.
Always available regardless of feature flags. Includes:
Agent- The fundamental trait for all agentsTool/Toolset- For extending agents with capabilitiesSession/State- For managing conversation contextEvent- For streaming agent responsesAdkError/Result- Unified error handling Read-only access to invocation metadata.
Provides identity information (user, app, session, invocation) and the current user content. Implemented by all context types.
Required Methods§
Sourcefn invocation_id(&self) -> &str
fn invocation_id(&self) -> &str
Returns the current invocation identifier.
Sourcefn agent_name(&self) -> &str
fn agent_name(&self) -> &str
Returns the name of the currently executing agent.
Sourcefn session_id(&self) -> &str
fn session_id(&self) -> &str
Returns the session identifier.
Sourcefn user_content(&self) -> &Content
fn user_content(&self) -> &Content
Returns the user’s input content for this invocation.
Provided Methods§
Sourcefn acting_context(&self) -> ActingContext
fn acting_context(&self) -> ActingContext
Returns who the running agent is and on whose behalf it acts.
The runtime’s contexts answer from the run’s RunConfig::acting for the agent
that is executing, and wrapper contexts must forward this to the context they
wrap. The default is the identity ADK-Rust derives when none is configured:
ActingContext::derived from the app name, the
agent name, and the user as a human. The invocation the agent acts in is
invocation_id.
Sourcefn is_authenticated(&self) -> bool
fn is_authenticated(&self) -> bool
Returns whether user_id comes from an authenticated
RequestContext rather than from the caller’s request body.
The runner’s invocation context answers true when the run carries a
RequestContext, which adk-server sets only from a request its
RequestContextExtractor authenticated. A wrapper context should forward it to the
context it wraps. The default is false, so a context that cannot tell treats the
identity as unauthenticated. Implements spec 3.1 §10 F5.
§Example
use adk_core::ReadonlyContext;
/// Standing approvals apply only to a user the server authenticated.
fn standing_rules_apply(ctx: &dyn ReadonlyContext) -> bool {
ctx.is_authenticated()
}Sourcefn state(&self) -> Option<&dyn State>
fn state(&self) -> Option<&dyn State>
Returns the session state when the runtime exposes it to dynamic toolsets.
The default keeps lightweight contexts and third-party implementations
source-compatible. Consumers must gracefully handle contexts without
session state. Dynamic Toolset implementations use
this to determine their context-specific tool surface without requiring
mutable access to the session.
Sourcefn try_app_name(&self) -> Result<AppName, AdkError>
fn try_app_name(&self) -> Result<AppName, AdkError>
Returns the application name as a typed AppName.
Parses the value returned by app_name(). Returns an
error if the raw string fails validation (empty, null bytes, or exceeds
the maximum length).
§Errors
Returns an error when the underlying string is not a valid identifier.
Sourcefn try_user_id(&self) -> Result<UserId, AdkError>
fn try_user_id(&self) -> Result<UserId, AdkError>
Sourcefn try_session_id(&self) -> Result<SessionId, AdkError>
fn try_session_id(&self) -> Result<SessionId, AdkError>
Returns the session identifier as a typed SessionId.
Parses the value returned by session_id().
Returns an error if the raw string fails validation.
§Errors
Returns an error when the underlying string is not a valid identifier.
Sourcefn try_invocation_id(&self) -> Result<InvocationId, AdkError>
fn try_invocation_id(&self) -> Result<InvocationId, AdkError>
Returns the invocation identifier as a typed InvocationId.
Parses the value returned by invocation_id().
Returns an error if the raw string fails validation.
§Errors
Returns an error when the underlying string is not a valid identifier.
Sourcefn try_identity(&self) -> Result<AdkIdentity, AdkError>
fn try_identity(&self) -> Result<AdkIdentity, AdkError>
Returns the stable session-scoped AdkIdentity triple.
Combines try_app_name(),
try_user_id(), and
try_session_id() into a single composite
identity value.
§Errors
Returns an error if any of the three constituent identifiers fail validation.
Sourcefn try_execution_identity(&self) -> Result<ExecutionIdentity, AdkError>
fn try_execution_identity(&self) -> Result<ExecutionIdentity, AdkError>
Returns the full per-invocation ExecutionIdentity.
Combines try_identity() with the invocation,
branch, and agent name from this context.
§Errors
Returns an error if any of the four typed identifiers fail validation.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".