Skip to main content
Vizra ADK is in maintenance mode. It continues to work and receives compatibility fixes, but no new features are planned. For evaluating AI agents — now built on the official Laravel AI SDK — check out Vizra Evals, its successor for the evaluation use-case. Coming from ADK? See the migration guide.

What are Macros?

Macros allow you to add custom methods to classes at runtime. This is a powerful extensibility pattern borrowed from Laravel that lets you extend Vizra ADK’s functionality without modifying the core code.

Custom Tracking

Add analytics and tracking to your agents

Third-party Integrations

Integrate with external services seamlessly

Domain Logic

Add business-specific functionality

Reusable Patterns

Create patterns you can use across your app

Supported Classes

The following Vizra ADK classes support macros:

Basic Usage

Registering a Macro

Register macros in your AppServiceProvider::boot() method:
app/Providers/AppServiceProvider.php

Using Your Macro

Always return $this from your macros to maintain the fluent interface and enable method chaining.

Real-World Examples

Analytics Tracking

Track which models are using AI features:

Conditional Execution

Add conditional logic to your builder:

Metadata Tagging

Add metadata for logging or debugging:

Cost Tracking

Track estimated costs for budget monitoring:

Using Mixins

Mixins allow you to add multiple macros at once by grouping related functionality in a class:
app/Mixins/AnalyticsMixin.php
Register the mixin in your service provider:
app/Providers/AppServiceProvider.php
Now use all the mixed-in methods:
Mixins are ideal when you have a group of related macros that logically belong together, such as analytics, auditing, or domain-specific operations.

Advanced Patterns

Integration with Events

Combine macros with Laravel events for powerful side effects:

Dynamic Configuration

Load configuration dynamically from your models:

Workflow Macros

Add custom workflow types using the WorkflowManager:

Best Practices

Return $this

Always return $this to maintain the fluent interface

Register Early

Register macros in AppServiceProvider::boot()

Descriptive Names

Use clear, descriptive names for your macros

Document Well

Document macros for other developers on your team
Additional tips:
  • Consider scope - Macros are global, so namespace them if needed to avoid conflicts
  • Test your macros - Write tests to ensure macros work as expected
  • Group related macros - Use mixins to organize related functionality

Testing Macros

Test your macros using Pest or PHPUnit:
tests/Feature/MacroTest.php
The full test suite for macro support is available at tests/Feature/MacroSupportTest.php with 10 comprehensive tests covering all major use cases.

Learn More

Laravel Macros Docs

Official Laravel documentation on macros

Agent Builder API

Complete AgentBuilder reference