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: StringUnique run identifier.
start_time: DateTime<Utc>Run start time.
model_name: StringModel being used.
model_settings: ModelSettingsModel 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: u32Current retry count.
metadata: Option<Value>Custom metadata.
Implementations§
Source§impl<Deps> RunContext<Deps>
impl<Deps> RunContext<Deps>
Sourcepub fn new(deps: Deps, model_name: impl Into<String>) -> RunContext<Deps>
pub fn new(deps: Deps, model_name: impl Into<String>) -> RunContext<Deps>
Create a new run context.
Create with shared dependencies.
Sourcepub fn elapsed_seconds(&self) -> i64
pub fn elapsed_seconds(&self) -> i64
Get elapsed time in seconds.
Sourcepub fn set_metadata(&mut self, key: &str, value: impl Serialize)
pub fn set_metadata(&mut self, key: &str, value: impl Serialize)
Set metadata value.
Sourcepub fn get_metadata<T>(&self, key: &str) -> Option<T>where
T: DeserializeOwned,
pub fn get_metadata<T>(&self, key: &str) -> Option<T>where
T: DeserializeOwned,
Get metadata value.
Sourcepub fn for_tool(
&self,
tool_name: impl Into<String>,
tool_call_id: Option<String>,
) -> RunContext<Deps>
pub fn for_tool( &self, tool_name: impl Into<String>, tool_call_id: Option<String>, ) -> RunContext<Deps>
Clone with a new tool context.
Sourcepub fn for_retry(&self) -> RunContext<Deps>
pub fn for_retry(&self) -> RunContext<Deps>
Clone for a retry.
Trait Implementations§
Source§impl<Deps> Clone for RunContext<Deps>
impl<Deps> Clone for RunContext<Deps>
Source§fn clone(&self) -> RunContext<Deps>
fn clone(&self) -> RunContext<Deps>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<Deps> Debug for RunContext<Deps>where
Deps: Debug,
impl<Deps> Debug for RunContext<Deps>where
Deps: Debug,
Source§impl<Deps> Default for RunContext<Deps>where
Deps: Default,
impl<Deps> Default for RunContext<Deps>where
Deps: Default,
Source§fn default() -> RunContext<Deps>
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>
impl<Deps> Sync for RunContext<Deps>
impl<Deps> Unpin for RunContext<Deps>
impl<Deps> UnwindSafe for RunContext<Deps>where
Deps: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more