Skip to content

Refactor tool config: replace global state with proper dependency injection #46

@tcdent

Description

@tcdent

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

  1. Global OnceLock initialized at app startup
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions