Skip to main content

Session

Trait Session 

Source
pub trait Session: Send + Sync {
Show 16 methods // Required methods fn id(&self) -> &str; fn app_name(&self) -> &str; fn user_id(&self) -> &str; fn state(&self) -> &dyn State; fn conversation_history(&self) -> Vec<Content>; // Provided methods fn conversation_history_for_agent(&self, _agent_name: &str) -> Vec<Content> { ... } fn conversation_history_scoped( &self, agent_name: Option<&str>, _branch: &str, ) -> Vec<Content> { ... } fn conversation_history_with_context( &self, _agent_name: &str, branch: &str, ) -> Vec<Content> { ... } fn records_invocation_events(&self) -> bool { ... } fn held_tool_calls( &self, _agent_name: &str, _branch: &str, ) -> Vec<HeldToolCall> { ... } fn workflow_resume_positions( &self, _workflow: &str, _branch: &str, ) -> Vec<WorkflowPosition> { ... } fn append_to_history(&self, _content: Content) { ... } 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_identity(&self) -> Result<AdkIdentity, AdkError> { ... }
}
Expand description

Core traits and types.

Always available regardless of feature flags. Includes:

  • Agent - The fundamental trait for all agents
  • Tool / Toolset - For extending agents with capabilities
  • Session / State - For managing conversation context
  • Event - For streaming agent responses
  • AdkError / Result - Unified error handling Represents an active conversation session with identity and state.

Required Methods§

Source

fn id(&self) -> &str

Returns the session identifier.

Source

fn app_name(&self) -> &str

Returns the application name this session belongs to.

Source

fn user_id(&self) -> &str

Returns the user identifier for this session.

Source

fn state(&self) -> &dyn State

Returns the mutable state associated with this session.

Source

fn conversation_history(&self) -> Vec<Content>

Returns the conversation history from this session as Content items

Provided Methods§

Source

fn conversation_history_for_agent(&self, _agent_name: &str) -> Vec<Content>

Returns conversation history filtered for a specific agent.

When provided, events authored by other agents (not “user”, not the named agent, and not function/tool responses) are excluded. This prevents a transferred sub-agent from seeing the parent’s tool calls mapped as “model” role, which would cause the LLM to think work is already done.

Default implementation delegates to conversation_history.

Source

fn conversation_history_scoped( &self, agent_name: Option<&str>, _branch: &str, ) -> Vec<Content>

Returns conversation history scoped to an agent and a conversation branch.

branch is the invocation branch of the agent asking for history. An event is visible when its branch equals that branch or is an ancestor of it, so a sub-agent sees the conversation that led to it but not what its siblings produced. ParallelAgent relies on this to keep concurrent branches from contaminating each other’s context, mirroring ADK Python’s _is_event_belongs_to_branch and ADK Go’s eventBelongsToBranch.

An empty branch on either side means “unscoped” and matches everything, so implementations that never set crate::Event::branch are unaffected.

Default implementation ignores branch and preserves the agent-name filtering behaviour, so existing Session implementations keep working.

Source

fn conversation_history_with_context( &self, _agent_name: &str, branch: &str, ) -> Vec<Content>

Returns the history agent_name sends its model on branch.

The agent’s own events and the user’s keep their turns. What another agent said, called and got back becomes user-role context (other_agent_context), so a workflow sub-agent never replays an earlier agent’s turns as its own, and a request that would end on another agent’s answer ends on a user turn. A system notice (system_notice_event) keeps its user-role turn. Branch scoping is that of conversation_history_scoped.

The default cannot tell authors apart and returns conversation_history_scoped(None, branch). Implementations backed by an event log override it.

Source

fn records_invocation_events(&self) -> bool

Whether this session’s history already holds every event of the current invocation once the agent that produced it has yielded it.

The runner’s session records each event before it asks the agent for the next one, so a workflow agent reads its sub-agents’ history from it instead of tracking their events itself. The default is false.

Source

fn held_tool_calls(&self, _agent_name: &str, _branch: &str) -> Vec<HeldToolCall>

Returns the tool calls agent_name holds for confirmation on branch.

An agent resumes these at the start of a run once a decision exists for them. Implementations backed by an event log return held_tool_calls over it. The default returns none, so a session without an event log never resumes a held call.

Source

fn workflow_resume_positions( &self, _workflow: &str, _branch: &str, ) -> Vec<WorkflowPosition>

Returns where the workflow agent workflow on branch resumes: the positions it recorded on the holds that stopped its last run, while those calls are still held.

Implementations backed by an event log return workflow_resume_positions over it. The default returns none, so a workflow over a session without an event log starts over.

Source

fn append_to_history(&self, _content: Content)

Append content to conversation history (for sequential agent support)

Source

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.

Source

fn try_user_id(&self) -> Result<UserId, AdkError>

Returns the user identifier as a typed UserId.

Parses the value returned by user_id(). Returns an error if the raw string fails validation.

§Errors

Returns an error when the underlying string is not a valid identifier.

Source

fn try_session_id(&self) -> Result<SessionId, AdkError>

Returns the session identifier as a typed SessionId.

Parses the value returned by id(). Returns an error if the raw string fails validation.

§Errors

Returns an error when the underlying string is not a valid identifier.

Source

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§