#[non_exhaustive]pub struct AgentContext {
pub working_directory: String,
pub tool_executor: Arc<dyn ToolExecutor>,
pub communication_hub: Arc<CommunicationHub>,
pub file_lock_manager: Arc<FileLockManager>,
pub working_set: Arc<RwLock<WorkingSet>>,
pub metadata: HashMap<String, String>,
pub pre_execute_hook: Option<Arc<dyn ToolPreHook>>,
pub lifecycle_hooks: Option<Arc<dyn AgentLifecycleHooks>>,
}Expand description
Environment context for a task agent.
Pass this to TaskAgent::new at
construction time. All fields are cheaply cloneable via Arc.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.working_directory: StringWorking directory used for resolving relative file paths.
tool_executor: Arc<dyn ToolExecutor>Executes tools on behalf of the agent.
communication_hub: Arc<CommunicationHub>Inter-agent message bus.
file_lock_manager: Arc<FileLockManager>Coordinates exclusive/shared file access across concurrent agents.
working_set: Arc<RwLock<WorkingSet>>Tracks files currently loaded into the agent’s context window.
metadata: HashMap<String, String>Application-specific metadata passed through to tools.
pre_execute_hook: Option<Arc<dyn ToolPreHook>>Optional pre-execution hook for semantic tool validation.
When set, the hook is called before every tool execution. Returning
PreHookDecision::Reject causes the tool call to be skipped and
the rejection message injected as a ToolResult::error.
lifecycle_hooks: Option<Arc<dyn AgentLifecycleHooks>>Optional lifecycle hooks for granular loop control.
When set, the agent loop calls these hooks at every phase: iteration boundaries, provider calls, tool execution, completion, and context management. All hook methods have default no-op implementations.
See AgentLifecycleHooks for the full hook surface.
Implementations§
Source§impl AgentContext
impl AgentContext
Sourcepub fn new(
working_directory: impl Into<String>,
tool_executor: Arc<dyn ToolExecutor>,
communication_hub: Arc<CommunicationHub>,
file_lock_manager: Arc<FileLockManager>,
) -> Self
pub fn new( working_directory: impl Into<String>, tool_executor: Arc<dyn ToolExecutor>, communication_hub: Arc<CommunicationHub>, file_lock_manager: Arc<FileLockManager>, ) -> Self
Create a new agent context with the given environment.
A fresh, empty WorkingSet is created automatically. Use
AgentContext::with_working_set to supply a pre-populated one.
Sourcepub fn with_working_set(
working_directory: impl Into<String>,
tool_executor: Arc<dyn ToolExecutor>,
communication_hub: Arc<CommunicationHub>,
file_lock_manager: Arc<FileLockManager>,
working_set: Arc<RwLock<WorkingSet>>,
) -> Self
pub fn with_working_set( working_directory: impl Into<String>, tool_executor: Arc<dyn ToolExecutor>, communication_hub: Arc<CommunicationHub>, file_lock_manager: Arc<FileLockManager>, working_set: Arc<RwLock<WorkingSet>>, ) -> Self
Create a context that shares an existing WorkingSet.
Sourcepub fn with_metadata(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_metadata( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Add application-specific metadata.
Sourcepub fn with_pre_execute_hook(self, hook: Arc<dyn ToolPreHook>) -> Self
pub fn with_pre_execute_hook(self, hook: Arc<dyn ToolPreHook>) -> Self
Set a pre-execution hook for semantic tool validation.
Sourcepub fn with_lifecycle_hooks(self, hooks: Arc<dyn AgentLifecycleHooks>) -> Self
pub fn with_lifecycle_hooks(self, hooks: Arc<dyn AgentLifecycleHooks>) -> Self
Set lifecycle hooks for granular loop control.