Skip to main content

Automatic Context for Custom Methods

All custom methods automatically have full agent context! The framework automatically detects and wraps your custom methods during initialization, ensuring getCurrentAgent() works seamlessly everywhere.

How It Works

Zero configuration required! The framework automatically:
  1. Scans your agent class for custom methods
  2. Wraps them with agent context during initialization
  3. Ensures getCurrentAgent() works in all external functions called from your methods

Real-World Example

Built-in vs Custom Methods

  • Built-in methods (onRequest, onEmail, onStateChanged): Already have context
  • Custom methods (your methods): Automatically wrapped during initialization
  • External functions: Access context through getCurrentAgent()

The Context Flow

Common Use Cases

Working with AI SDK Tools

Calling External Libraries

API Reference

The agents package exports one main function for context management:

getCurrentAgent<T>()

Gets the current agent from any context where it’s available. Returns:
Usage: