PHP code example of hakam / ai-log-inspector-agent
1. Go to this page and download the library: Download hakam/ai-log-inspector-agent library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hakam / ai-log-inspector-agent example snippets
// Just ask naturally!
$agent->ask("Why did payments fail?");
$agent->ask("What caused the 3 PM outage?");
$agent->ask("Show me timeout patterns");
$agent->ask("How many users affected?");
$agent = new LogInspectorAgent($platform, $model, $store);
// 🚨 Checkout Issues
$result = $agent->ask('Why did the last checkout request fail?');
// → "Payment gateway timeout after 30 seconds. The last 3 checkout attempts
// all failed with 'gateway_timeout' errors between 14:23-14:25."
// 🔍 Database Problems
$result = $agent->ask('Show me all database errors from the last hour');
// → "Found 12 database connection failures. Pattern shows connection pool
// exhaustion starting at 15:30, affecting user authentication service."
// 🌊 Performance Issues
$result = $agent->ask('What caused the sudden spike in API response times?');
// → "Memory leak in Redis connection causing 2.5s delays. Started after
// deployment at 13:45, affecting 847 requests per minute."
// 🔐 Security Monitoring
$result = $agent->ask('Are there any suspicious login attempts?');
// → "Detected brute force attack from IP 192.168.1.100. 156 failed login
// attempts in 5 minutes targeting admin accounts."
// 📊 Impact Assessment
$result = $agent->ask('How many users were affected by the outage?');
// → "Based on error logs, approximately 2,341 unique users experienced
// service disruption between 14:15-14:32 during the database incident."
akam\AiLogInspector\Agent\LogInspectorAgent;
use Hakam\AiLogInspector\Enum\PlatformEnum;
use Hakam\AiLogInspector\Platform\LogDocumentPlatformFactory;
use Hakam\AiLogInspector\Retriever\LogRetriever;
use Hakam\AiLogInspector\Store\VectorLogDocumentStore;
use Hakam\AiLogInspector\Tool\LogSearchTool;
use Hakam\AiLogInspector\Tool\RequestContextTool;
use Symfony\AI\Store\Bridge\Local\InMemoryStore;
// Brain platform (LLM) + Embedding platform
$brainPlatform = LogDocumentPlatformFactory::createBrainPlatform(
PlatformEnum::OPENAI,
[
'api_key' => $_ENV['OPENAI_API_KEY'],
'model' => 'gpt-4o-mini',
'model_capabilities' => ['text', 'tool_calling'],
]
);
$embeddingPlatform = LogDocumentPlatformFactory::createEmbeddingPlatform(
PlatformEnum::OPENAI,
[
'api_key' => $_ENV['OPENAI_API_KEY'],
'model' => 'text-embedding-3-small',
]
);
// Vector store + retriever
$store = new VectorLogDocumentStore(new InMemoryStore());
$retriever = new LogRetriever(
embeddingPlatform: $embeddingPlatform->getPlatform(),
model: 'text-embedding-3-small',
logStore: $store
);
// Tools + agent
$logSearchTool = new LogSearchTool($store, $retriever, $brainPlatform);
$requestContextTool = new RequestContextTool($store, $retriever, $brainPlatform);
$agent = new LogInspectorAgent($brainPlatform, [$logSearchTool, $requestContextTool]);
// Index a few logs (in-memory)
use Hakam\AiLogInspector\Document\LogDocumentFactory;
use Hakam\AiLogInspector\Indexer\LogDocumentIndexer;
$indexer = new LogDocumentIndexer(
embeddingPlatform: $embeddingPlatform->getPlatform(),
model: 'text-embedding-3-small',
logStore: $store
);
$docs = [
LogDocumentFactory::createFromString('[2024-01-29 14:23:45] ERROR: Payment gateway timeout'),
LogDocumentFactory::createFromString('[2024-01-29 14:23:46] ERROR: Stripe API returned 504'),
];
$indexer->indexLogDocuments($docs);
// Ask questions!
$result = $agent->ask('Why did the checkout fail?');
echo $result->getContent();
// Root cause analysis
$agent->ask('What caused the 500 errors in payment service?');
// Timeline investigation
$agent->ask('What happened before the database failure?');
// Pattern discovery
$agent->ask('Are there recurring memory leak patterns?');
// Security investigation
$agent->ask('Suspicious auth patterns from IP 192.168.1.100?');
// Memory (testing)
use Symfony\AI\Store\Bridge\Local\InMemoryStore;
$store = new InMemoryStore();
// Production stores
use Symfony\AI\Store\Bridge\Chroma\ChromaStore;
use Symfony\AI\Store\Bridge\Pinecone\PineconeStore;
$store = new ChromaStore($config);
$store = new PineconeStore($config);
$customPrompt = 'You are a security log analyzer. Focus on threats and incidents.';
$agent = new LogInspectorAgent($platform, [$logSearchTool, $requestContextTool], $customPrompt);
use Hakam\AiLogInspector\Chat\LogInspectorChatFactory;
$chat = LogInspectorChatFactory::createSession(
sessionId: 'incident-2026-02-06',
platform: $platform,
searchTool: $logSearchTool,
contextTool: $requestContextTool,
storagePath: sys_get_temp_dir() . '/log-inspector-sessions'
);
$chat->startInvestigation('Payment outage - Feb 6, 2026');
$chat->ask('What payment errors occurred?');
$chat->followUp('Were there any database issues around that time?');
$summary = $chat->summarize();
echo $summary->getContent();