Quick Start
Default Behavior (Safe)
Each agent automatically gets its own context-isolated runtime and tool resolver:
How It Works
Context variables (contextvars.ContextVar) automatically isolate state per execution context. Each agent/task/request gets its own:
- Interactive runtime with separate LSP/ACP configurations
- Tool resolver anchored to its own working directory
- Memory and cache state that won’t leak between agents
Configuration Options
The context safety is automatic - no configuration required. However, there are some control points:| Component | Behavior | Control Function |
|---|---|---|
| Tool Resolver | Per-context CWD anchoring | reset_default_resolver() |
| Interactive Runtime | Per-context config isolation | cleanup_runtime() (context-local) |
| Memory State | Automatic isolation | Built-in with async-safe locks |
Common Patterns
Pattern 1: Daemon with Project Switching
Pattern 2: Concurrent Multi-Agent Workflow
Pattern 3: IDE Plugin Integration
Best Practices
Always use reset_default_resolver() after chdir
Always use reset_default_resolver() after chdir
When switching working directories in long-lived processes, explicitly reset the tool resolver to pick up the new directory’s tools.py.
Trust automatic context isolation
Trust automatic context isolation
Don’t manually manage context variables - the framework handles isolation automatically. Each async task or thread gets its own context.
Use context-local cleanup functions
Use context-local cleanup functions
When cleaning up resources, use the context-local versions that only affect the current agent’s context.
Leverage CWD-per-context for multi-project tools
Leverage CWD-per-context for multi-project tools
Each context anchors its tool resolver to the working directory when first called. Use this for clean project separation.
Related
Thread Safety
Thread-safe agent operations and state management
Tool Resolver
Context-aware tool resolution and loading

