pub struct AgentContext {
pub iteration: usize,
pub state: AgentState,
pub cwd: PathBuf,
pub custom: HashMap<String, Value>,
pub tool_configs: HashMap<String, Value>,
pub writable_roots: Vec<PathBuf>,
pub observation_limit: usize,
pub tool_cache: HashMap<String, String>,
/* private fields */
}Expand description
Shared context passed to tools during execution.
Two ways to store custom state:
- Typed (preferred):
ctx.insert::<MyState>(state)/ctx.get_typed::<MyState>() - String-keyed (legacy):
ctx.set("key", json_value)/ctx.get("key")
Fields§
§iteration: usize§state: AgentState§cwd: PathBuf§custom: HashMap<String, Value>String-keyed extensible state (legacy — prefer typed store).
tool_configs: HashMap<String, Value>Per-tool configuration overrides.
writable_roots: Vec<PathBuf>Sandbox: writable directory roots (empty = no restriction).
observation_limit: usize§tool_cache: HashMap<String, String>Tool result cache — keyed by “tool_name:arg_hash”.
Implementations§
Source§impl AgentContext
impl AgentContext
pub fn new() -> AgentContext
Sourcepub fn insert<T>(&mut self, value: T)
pub fn insert<T>(&mut self, value: T)
Insert typed state. Each type T gets exactly one slot — no string-key collisions.
ⓘ
#[derive(Clone)]
struct MyToolState { count: usize }
ctx.insert(MyToolState { count: 0 });Sourcepub fn remove_typed<T>(&mut self) -> Option<T>
pub fn remove_typed<T>(&mut self) -> Option<T>
Remove typed state, returning it if present.
Sourcepub fn observation_summary(&self) -> Option<String>
pub fn observation_summary(&self) -> Option<String>
Get observation log as a single string for LLM context injection.
pub fn cache_tool_result( &mut self, key: impl Into<String>, result: impl Into<String>, )
pub fn cached_tool_result(&self, key: &str) -> Option<&str>
pub fn invalidate_cache(&mut self, key: &str)
pub fn with_cwd(self, cwd: impl Into<PathBuf>) -> AgentContext
pub fn with_writable_roots(self, roots: Vec<PathBuf>) -> AgentContext
pub fn is_writable(&self, path: &Path) -> bool
pub fn set(&mut self, key: impl Into<String>, value: Value)
pub fn get(&self, key: &str) -> Option<&Value>
pub fn max_tokens_override(&self) -> Option<u32>
pub fn set_tool_config(&mut self, tool_name: impl Into<String>, config: Value)
pub fn tool_config(&self, tool_name: &str) -> Option<&Value>
pub fn merged_tool_config(&self, tool_name: &str, base: &Value) -> Value
Trait Implementations§
Source§impl Clone for AgentContext
impl Clone for AgentContext
Source§fn clone(&self) -> AgentContext
fn clone(&self) -> AgentContext
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 Debug for AgentContext
impl Debug for AgentContext
Source§impl Default for AgentContext
impl Default for AgentContext
Source§fn default() -> AgentContext
fn default() -> AgentContext
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for AgentContext
impl !RefUnwindSafe for AgentContext
impl Send for AgentContext
impl Sync for AgentContext
impl Unpin for AgentContext
impl UnsafeUnpin for AgentContext
impl !UnwindSafe for AgentContext
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