vizra/vizra-adk
Vizra ADK is a Laravel AI Agent Development Kit for building autonomous agents with tools, sub-agents, workflows, and persistent memory. Supports multiple LLM providers, streaming responses, tracing, evaluation, and a Livewire dashboard.
Installation:
composer require vizra/vizra-adk
php artisan vizra:install
First Agent Creation:
php artisan vizra:make:agent CustomerSupportAgent
app/Agents/Basic Usage:
$response = CustomerSupportAgent::run('User query here')
->forUser(auth()->user())
->go();
app/Agents/ namespaceapp/Agents/ directory (auto-discovered)app/Tools/ directory (auto-discovered)config/vizra.php (published by installer)/vizra (Livewire-powered UI for testing)Create a simple support agent that delegates to tools:
// app/Agents/CustomerSupportAgent.php
class CustomerSupportAgent extends BaseLlmAgent
{
protected string $name = 'customer_support';
protected string $instructions = 'You are a helpful customer support assistant.';
protected array $tools = [
OrderLookupTool::class,
RefundProcessorTool::class,
];
}
// Run in Tinker or controller:
$response = CustomerSupportAgent::run('I need to cancel my order #12345')
->forUser($user)
->go();
Agent Development Cycle:
flowchart TD
A[Define Agent] --> B[Add Tools]
B --> C[Configure Memory]
C --> D[Test Locally]
D --> E[Deploy]
Tool Integration Pattern:
// 1. Define tool schema
public function definition(): array {
return [
'name' => 'tool_name',
'description' => 'Tool purpose',
'parameters' => [
'type' => 'object',
'properties' => [
'param1' => ['type' => 'string'],
],
],
];
}
// 2. Implement execution
public function execute(array $args, AgentContext $context): string {
return json_encode($this->service->process($args));
}
Memory Integration:
// In agent class
protected function configureMemory(): void {
$this->memory()
->use('vector_store') // Default memory type
->withEmbeddingModel('text-embedding-3-small')
->withRetentionPolicy(30); // Days
}
Laravel Service Integration:
// Bind custom service to tool
$this->app->singleton(RefundProcessorTool::class, function ($app) {
return new RefundProcessorTool(
$app->make(PaymentGateway::class),
$app->make(NotificationService::class)
);
});
Event-Driven Agents:
// In EventServiceProvider
public function boot(): void {
OrderShipped::listen(function ($event) {
Agent::run('order_fulfillment')
->forUser($event->user)
->withInput($event->order->toArray())
->queue();
});
}
Dashboard Customization:
// Add custom metrics to dashboard
VizraDashboard::macro('addMetric', function ($name, $callback) {
$this->metrics[$name] = $callback;
});
// Usage:
VizraDashboard::addMetric('avg_response_time', fn() => AgentTrace::avg('response_time'));
Tool Pipeline Composition:
// app/Tools/Composite/ProcessOrderPipeline.php
ToolChain::create('order_processing')
->pipe(ValidateOrderTool::class)
->transform(fn($data) => ['valid' => true, 'order' => $data])
->when(fn($data) => $data['valid'])
->pipe(ChargePaymentTool::class)
->pipe(NotifyCustomerTool::class);
Agent Delegation:
// In parent agent
protected function handleComplexRequest(string $input): string {
return $this->delegateTo('specialist_agent')
->withInput($input)
->withMemory($this->memory)
->execute();
}
Evaluation Framework:
// Test agent quality
$results = AgentEvaluator::run('customer_support')
->withTestCases([
'test_cancel_order' => 'I want to cancel my order',
'test_refund_request' => 'How do I get a refund?',
])
->withEvaluator('gpt-4')
->execute();
Tool Schema Mismatches:
$this->validateToolSchema(OrderLookupTool::class);
Memory Bloat:
$this->memory()->withRetentionPolicy(7); // 7 days
Token Budget Exceeds:
$response = CustomerSupportAgent::run('...')
->stream()
->chunk(1000)
->go();
Circular Dependencies:
$this->toolChain->withMaxDepth(5);
Trace Visualization:
php artisan vizra:trace:view latest
Tool Logging:
// Enable verbose tool logging
config(['vizra.debug.tools' => true]);
Memory Inspection:
// Dump agent memory
dd($agent->memory()->getFacts());
Model Provider Switching:
// config/vizra.php
'providers' => env('LLM_PROVIDER') === 'google'
? 'google'
: 'openai',
Dashboard Permissions:
Route::middleware(['auth:sanctum', 'can:access,vizra'])->group(...);
Queue Workers:
$agent->queueOn('high_priority');
Custom Evaluators:
// app/Providers/VizraServiceProvider.php
VizraADK::extend('custom_evaluator', function () {
return new CustomEvaluator(
app(LLMClient::class),
app(EvaluationMetrics::class)
);
});
Memory Adapters:
// Register custom memory store
VizraADK::extendMemory('redis', function () {
return new RedisMemoryStore(
app(Redis::class),
config('vizra.memory.ttl')
);
});
Agent Middleware:
// Add pre/post execution hooks
VizraADK::macro('beforeRun', function ($callback) {
$this->beforeRunCallbacks[] = $callback;
});
// Usage:
Agent::beforeRun(function ($agent, $input) {
$agent->memory()->addFact("Initial input: {$input}");
});
Caching Strategies:
// Cache frequent tool responses
$tool->withCache(function ($args) {
return Cache::remember(
"tool:{$this->name}:{$args['order_id']}",
now()->addHours(1),
fn() => $this->execute($args, $context)
);
});
Batch Processing:
// Process multiple orders in one API call
$results = OrderBatchProcessor::process([
$order1->id,
$order2->id,
]);
Memory Compression:
// Use smaller embedding models for memory
$this->memory()->withEmbeddingModel('text-embedding-ada-002');
//
How can I help you explore Laravel packages today?