Skip to main content

RunContext

Struct RunContext 

Source
pub struct RunContext<Deps> {
    pub deps: Arc<Deps>,
    pub run_id: String,
    pub start_time: DateTime<Utc>,
    pub model_name: String,
    pub model_settings: ModelSettings,
    pub tool_name: Option<String>,
    pub tool_call_id: Option<String>,
    pub retry_count: u32,
    pub metadata: Option<Value>,
}
Expand description

Context for an agent run.

The context is passed to tools, instruction functions, and validators. It provides access to dependencies and run metadata.

Fields§

§deps: Arc<Deps>

Shared dependencies.

§run_id: String

Unique run identifier.

§start_time: DateTime<Utc>

Run start time.

§model_name: String

Model being used.

§model_settings: ModelSettings

Model settings for this run.

§tool_name: Option<String>

Current tool being executed (if any).

§tool_call_id: Option<String>

Current tool call ID (if any).

§retry_count: u32

Current retry count.

§metadata: Option<Value>

Custom metadata.

Implementations§

Source§

impl<Deps> RunContext<Deps>

Source

pub fn new(deps: Deps, model_name: impl Into<String>) -> RunContext<Deps>

Create a new run context.

Source

pub fn with_shared_deps( deps: Arc<Deps>, model_name: impl Into<String>, ) -> RunContext<Deps>

Create with shared dependencies.

Source

pub fn deps(&self) -> &Deps

Get a reference to the dependencies.

Source

pub fn elapsed(&self) -> TimeDelta

Get elapsed time since run started.

Source

pub fn elapsed_seconds(&self) -> i64

Get elapsed time in seconds.

Source

pub fn is_retry(&self) -> bool

Check if this is a retry.

Source

pub fn in_tool(&self) -> bool

Check if we’re currently in a tool execution.

Source

pub fn set_metadata(&mut self, key: &str, value: impl Serialize)

Set metadata value.

Source

pub fn get_metadata<T>(&self, key: &str) -> Option<T>

Get metadata value.

Source

pub fn for_tool( &self, tool_name: impl Into<String>, tool_call_id: Option<String>, ) -> RunContext<Deps>

Clone with a new tool context.

Source

pub fn for_retry(&self) -> RunContext<Deps>

Clone for a retry.

Trait Implementations§

Source§

impl<Deps> Clone for RunContext<Deps>

Source§

fn clone(&self) -> RunContext<Deps>

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
Source§

impl<Deps> Debug for RunContext<Deps>
where Deps: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<Deps> Default for RunContext<Deps>
where Deps: Default,

Source§

fn default() -> RunContext<Deps>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Deps> Freeze for RunContext<Deps>

§

impl<Deps> RefUnwindSafe for RunContext<Deps>
where Deps: RefUnwindSafe,

§

impl<Deps> Send for RunContext<Deps>
where Deps: Sync + Send,

§

impl<Deps> Sync for RunContext<Deps>
where Deps: Sync + Send,

§

impl<Deps> Unpin for RunContext<Deps>

§

impl<Deps> UnwindSafe for RunContext<Deps>
where Deps: RefUnwindSafe,

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> 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> 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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<T> GraphState for T
where T: Clone + Send + Sync + Debug + 'static,