Skip to main content

PhaseContext

Struct PhaseContext 

Source
pub struct PhaseContext {
Show 18 fields pub phase: Phase, pub snapshot: Snapshot, pub agent_spec: Arc<AgentSpec>, pub run_identity: RunIdentity, pub messages: Arc<[Arc<Message>]>, pub tool_name: Option<String>, pub tool_call_id: Option<String>, pub tool_args: Option<Value>, pub tool_result: Option<ToolResult>, pub run_mode: RunMode, pub adapter: AdapterKind, pub tool_kind: ToolKind, pub llm_response: Option<LLMResponse>, pub resume_input: Option<ToolCallResume>, pub suspension_id: Option<String>, pub suspension_reason: Option<String>, pub cancellation_token: Option<CancellationToken>, pub profile_access: Option<Arc<ProfileAccess>>,
}
Expand description

Execution context passed to phase hooks and action handlers.

Three input sources per ADR-0009:

  • agent_spec: immutable agent configuration (model, active_hook_filter, sections)
  • snapshot: shared runtime state (StateKeys)
  • run_identity: per-run identity (thread_id, run_id, etc.)

Fields§

§phase: Phase§snapshot: Snapshot§agent_spec: Arc<AgentSpec>

Active agent spec (resolved from registry at each phase boundary).

§run_identity: RunIdentity

Per-run identity (thread_id, run_id, etc.). Immutable for the run.

§messages: Arc<[Arc<Message>]>

Messages accumulated in the current run.

§tool_name: Option<String>§tool_call_id: Option<String>§tool_args: Option<Value>§tool_result: Option<ToolResult>§run_mode: RunMode§adapter: AdapterKind§tool_kind: ToolKind§llm_response: Option<LLMResponse>§resume_input: Option<ToolCallResume>§suspension_id: Option<String>§suspension_reason: Option<String>§cancellation_token: Option<CancellationToken>

Optional cancellation token for cooperative cancellation at phase boundaries.

§profile_access: Option<Arc<ProfileAccess>>

Optional profile access for cross-run persistence.

Implementations§

Source§

impl PhaseContext

Source

pub fn new(phase: Phase, snapshot: Snapshot) -> Self

Create a minimal context (for testing or phases without extra data).

Source

pub fn state<K: StateKey>(&self) -> Option<&K::Value>

Read a state key from the snapshot.

Source

pub fn config<K: PluginConfigKey>(&self) -> Result<K::Config, StateError>

Read a typed plugin config from the active agent spec. Returns Config::default() if the section is missing.

Source

pub fn with_snapshot(self, snapshot: Snapshot) -> Self

Source

pub fn with_agent_spec(self, spec: Arc<AgentSpec>) -> Self

Source

pub fn with_run_identity(self, identity: RunIdentity) -> Self

Source

pub fn with_messages(self, messages: Vec<Arc<Message>>) -> Self

Source

pub fn with_tool_info( self, name: impl Into<String>, call_id: impl Into<String>, args: Option<Value>, ) -> Self

Source

pub fn with_run_mode(self, mode: RunMode) -> Self

Source

pub fn with_adapter(self, adapter: AdapterKind) -> Self

Source

pub fn with_tool_kind(self, kind: ToolKind) -> Self

Source

pub fn tool_policy_context(&self) -> Option<ToolPolicyContext>

Build typed policy context for ToolGate/ToolPolicy hooks.

Source

pub fn with_tool_result(self, result: ToolResult) -> Self

Source

pub fn with_llm_response(self, response: LLMResponse) -> Self

Source

pub fn with_resume_input(self, resume: ToolCallResume) -> Self

Source

pub fn with_suspension( self, suspension_id: Option<String>, suspension_reason: Option<String>, ) -> Self

Source

pub fn with_cancellation_token(self, token: CancellationToken) -> Self

Source

pub fn profile(&self) -> Option<&ProfileAccess>

Get profile access, if configured.

Source

pub fn with_profile_access(self, access: Arc<ProfileAccess>) -> Self

Trait Implementations§

Source§

impl Clone for PhaseContext

Source§

fn clone(&self) -> PhaseContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneAny for T
where T: Clone + Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn as_mut_any(&mut self) -> &mut (dyn Any + 'static)

Source§

fn as_any_box(self: Box<T>) -> Box<dyn Any>

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more