vizra/vizra-adk
Vizra ADK brings autonomous AI agents to Laravel: multi-model support (OpenAI/Anthropic/Gemini), tools, persistent memory, sub-agents, workflows, streaming responses, evaluation, and tracing—plus a Livewire dashboard for testing and monitoring.
Installation:
composer require vizra/vizra-adk
php artisan vizra:install
First Agent:
php artisan vizra:make:agent CustomerSupportAgent
app/Agents/.Quick Test:
php artisan vizra:chat customer_support
app/Agents/ - Auto-discovered agent classes.app/Tools/ - Custom tool implementations.config/vizra.php - API keys, model defaults, and behavior settings./vizra - Livewire-powered UI for testing and monitoring.Create a simple support agent that can:
// 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];
public function handleOrderInquiry(string $orderId): string
{
return $this->run("Handle customer inquiry for order #{$orderId}")
->forUser(auth()->user())
->go();
}
}
Agent Execution Flow:
// Basic execution
$response = CustomerSupportAgent::run('User query')
->forUser($user)
->withMemory($memory)
->go();
// With streaming
$response = CustomerSupportAgent::run('User query')
->stream(fn($token) => Log::info($token))
->go();
Tool Integration Pattern:
// In your agent's tools array
protected array $tools = [
DatabaseQueryTool::class,
PaymentProcessorTool::class,
EmailSenderTool::class,
];
// Tool implementation
class DatabaseQueryTool implements ToolInterface
{
public function definition(): array
{
return [
'name' => 'db_query',
'description' => 'Execute SQL queries',
'parameters' => [
'type' => 'object',
'properties' => [
'query' => ['type' => 'string'],
'params' => ['type' => 'array']
]
]
];
}
public function execute(array $args, AgentContext $context): string
{
return DB::select($args['query'], $args['params']);
}
}
Memory Management:
// Persistent memory
$memory = AgentMemory::create()
->addFact('user_preferences', $user->preferences)
->persist();
// Session memory
$session = $this->memory->startSession()
->add('last_query', $query)
->end();
Laravel Events:
// Trigger agent on event
event(new OrderCreated($order))
->then(fn() => CustomerSupportAgent::run(
"Notify customer about order #{$order->id}"
)->forUser($order->user)->go());
Queue Jobs:
// Dispatch async agent execution
CustomerSupportAgent::run('Process refund')
->forUser($user)
->dispatch()
->onQueue('agents');
Livewire Integration:
// In Livewire component
public function handleUserMessage(string $message)
{
$response = CustomerSupportAgent::run($message)
->forUser($this->user)
->go();
$this->messages[] = [
'user' => $message,
'bot' => $response->content
];
}
API Endpoints:
Route::post('/agents/chat', function (Request $request) {
$agent = CustomerSupportAgent::run($request->input('message'))
->forUser(auth()->user())
->go();
return response()->json($agent->toArray());
});
Agent Composition:
// Delegate to specialized agents
class MasterAgent extends BaseLlmAgent
{
public function handleRequest(string $query): string
{
$specializedAgents = [
'orders' => OrderAgent::class,
'support' => SupportAgent::class,
'billing' => BillingAgent::class
];
$agentClass = collect($specializedAgents)
->first(fn($class, $key) =>
str_contains($query, $key)
);
return $agentClass::run($query)->go();
}
}
Tool Pipelines:
// Complex workflow tool
class OrderFulfillmentPipelineTool implements ToolInterface
{
public function execute(array $args, AgentContext $context): string
{
return ToolChain::create('fulfillment')
->pipe(ValidateOrderTool::class)
->pipe(InventoryCheckTool::class)
->pipe(ShippingScheduleTool::class)
->execute($args, $context);
}
}
Evaluation Framework:
// Test agent responses
$evaluation = AgentEvaluator::create()
->forAgent(CustomerSupportAgent::class)
->withTestCases([
'test_order_inquiry' => [
'input' => 'Where is my order?',
'expected' => 'contains tracking number'
]
])
->run();
$results = $evaluation->getResults();
Tool Parameter Validation:
execute():
if (!isset($args['order_id'])) {
throw new \InvalidArgumentException('Order ID required');
}
Memory Leaks:
$memory->pruneOlderThan(Carbon::now()->subDays(7));
API Rate Limits:
config/vizra.php:
'llm' => [
'retry_attempts' => 3,
'retry_delay' => 1000, // ms
],
Circular Dependencies:
if ($context->get('call_depth') > 5) {
throw new \RuntimeException('Maximum call depth exceeded');
}
Execution Tracing:
php artisan vizra:trace --agent=CustomerSupportAgent --query="test"
Memory Inspection:
$memory = AgentMemory::find($memoryId);
dd($memory->getFacts());
Tool Logging:
// Add to tool execute method
Log::debug('Tool executed', [
'tool' => $this->definition()['name'],
'args' => $args,
'context' => $context->toArray()
]);
Model Fallbacks:
config/vizra.php:
'models' => [
'default' => 'gpt-4o',
'fallback' => [
'gpt-4o' => 'gpt-4',
'gpt-4' => 'gpt-3.5-turbo'
]
],
Tool Discovery:
app/Tools/ or registered via service provider:
$this->app->bind(
ToolInterface::class,
InventoryCheckTool::class
);
Memory Storage:
'memory' => [
'driver' => 'database', // or 'redis', 'filesystem'
'table' => 'agent_memories',
],
Custom Prompt Templates:
// Override default prompt structure
AgentBuilder::macro('withCustomPrompt', function ($template) {
$this->promptTemplate = $template;
return $this;
});
Evaluation Metrics:
// Add custom evaluation metric
AgentEvaluator::
How can I help you explore Laravel packages today?