Problem
Tools currently access config through global state (e.g., OnceLock<AgentContext> in spawn_agent) because the app doesn't create tools directly - they're instantiated via Tool::execute().
This pattern is used by:
Current workarounds
- Global
OnceLock initialized at app startup
- Loading config inside the tool handler (inefficient)
Desired solution
Pass config/context through the effect handler system so tools don't need global state. Options:
- Add a
Context parameter to EffectHandler::call()
- Use a trait object for tool context in
ToolExecutor
- Dependency injection at tool registration time
Affected code
src/tools/impls/spawn_agent.rs - AGENT_CONTEXT
src/tools/handlers.rs - effect handlers
src/tools/exec.rs - ToolExecutor
Problem
Tools currently access config through global state (e.g.,
OnceLock<AgentContext>in spawn_agent) because the app doesn't create tools directly - they're instantiated viaTool::execute().This pattern is used by:
spawn_agent.rs:AGENT_CONTEXT: OnceLock<AgentContext>fetch_html(PR Add Chrome profile support to fetch_html tool #45): loads config per-call, should use same pattern for consistencyCurrent workarounds
OnceLockinitialized at app startupDesired solution
Pass config/context through the effect handler system so tools don't need global state. Options:
Contextparameter toEffectHandler::call()ToolExecutorAffected code
src/tools/impls/spawn_agent.rs-AGENT_CONTEXTsrc/tools/handlers.rs- effect handlerssrc/tools/exec.rs-ToolExecutor