pub struct AgentContext {
pub session_id: SessionId,
pub working_dir: String,
pub variables: HashMap<String, ContextValue>,
pub permissions: AgentPermissions,
pub started_at: SystemTime,
pub last_activity: Instant,
pub audit: Vec<AuditEntry>,
pub transaction: Option<TransactionScope>,
pub budget: OperationBudget,
pub tool_registry: Vec<ToolDefinition>,
pub tool_calls: Vec<ToolCallRecord>,
}Expand description
Agent session context
Fields§
§session_id: SessionIdUnique session identifier
working_dir: StringCurrent working directory
variables: HashMap<String, ContextValue>Session variables
permissions: AgentPermissionsPermissions
started_at: SystemTimeSession start time
last_activity: InstantLast activity time
audit: Vec<AuditEntry>Audit trail
transaction: Option<TransactionScope>Transaction state
budget: OperationBudgetMaximum operation budget (token/cost limit)
tool_registry: Vec<ToolDefinition>Tool registry: available tools for this agent
tool_calls: Vec<ToolCallRecord>Tool call history for this session
Implementations§
Source§impl AgentContext
impl AgentContext
Sourcepub fn with_working_dir(session_id: SessionId, working_dir: String) -> Self
pub fn with_working_dir(session_id: SessionId, working_dir: String) -> Self
Create with custom working directory
Sourcepub fn with_full_permissions(session_id: SessionId) -> Self
pub fn with_full_permissions(session_id: SessionId) -> Self
Create with full permissions (for trusted agents)
Sourcepub fn register_tool(&mut self, tool: ToolDefinition)
pub fn register_tool(&mut self, tool: ToolDefinition)
Register a tool with this agent
Sourcepub fn record_tool_call(&mut self, call: ToolCallRecord)
pub fn record_tool_call(&mut self, call: ToolCallRecord)
Record a tool call
Sourcepub fn set_var(&mut self, name: &str, value: ContextValue)
pub fn set_var(&mut self, name: &str, value: ContextValue)
Set a variable
Sourcepub fn get_var(&mut self, name: &str) -> Option<ContextValue>
pub fn get_var(&mut self, name: &str) -> Option<ContextValue>
Get a variable (returns cloned value to avoid borrow issues)
Sourcepub fn peek_var(&self, name: &str) -> Option<&ContextValue>
pub fn peek_var(&self, name: &str) -> Option<&ContextValue>
Get a variable reference without auditing (for read-only access)
Sourcepub fn check_fs_permission(
&self,
path: &str,
op: AuditOperation,
) -> Result<(), ContextError>
pub fn check_fs_permission( &self, path: &str, op: AuditOperation, ) -> Result<(), ContextError>
Check filesystem permission
Sourcepub fn check_db_permission(
&self,
table: &str,
op: AuditOperation,
) -> Result<(), ContextError>
pub fn check_db_permission( &self, table: &str, op: AuditOperation, ) -> Result<(), ContextError>
Check database permission
Sourcepub fn consume_budget(
&mut self,
tokens: u64,
cost: u64,
) -> Result<(), ContextError>
pub fn consume_budget( &mut self, tokens: u64, cost: u64, ) -> Result<(), ContextError>
Consume operation budget
Sourcepub fn begin_transaction(&mut self, tx_id: u64) -> Result<(), ContextError>
pub fn begin_transaction(&mut self, tx_id: u64) -> Result<(), ContextError>
Begin transaction
Sourcepub fn commit_transaction(&mut self) -> Result<(), ContextError>
pub fn commit_transaction(&mut self) -> Result<(), ContextError>
Commit transaction
Sourcepub fn rollback_transaction(
&mut self,
) -> Result<Vec<PendingWrite>, ContextError>
pub fn rollback_transaction( &mut self, ) -> Result<Vec<PendingWrite>, ContextError>
Rollback transaction
Sourcepub fn record_pending_write(
&mut self,
resource_type: ResourceType,
resource_key: String,
original_value: Option<Vec<u8>>,
) -> Result<(), ContextError>
pub fn record_pending_write( &mut self, resource_type: ResourceType, resource_key: String, original_value: Option<Vec<u8>>, ) -> Result<(), ContextError>
Record pending write for rollback
Sourcepub fn resolve_path(&self, path: &str) -> String
pub fn resolve_path(&self, path: &str) -> String
Resolve path relative to working directory
Sourcepub fn substitute_vars(&self, input: &str) -> String
pub fn substitute_vars(&self, input: &str) -> String
Substitute variables in string ($var syntax)
Sourcepub fn is_expired(&self, idle_timeout: Duration) -> bool
pub fn is_expired(&self, idle_timeout: Duration) -> bool
Check if session is expired (default: 1 hour idle)
Trait Implementations§
Source§impl Clone for AgentContext
impl Clone for AgentContext
Source§fn clone(&self) -> AgentContext
fn clone(&self) -> AgentContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more