hakam / ai-log-inspector-agent
AI-powered log inspector agent for PHP
Requires
- php: ^8.2
- psr/log: ^3.0
- symfony/ai-agent: @dev
- symfony/ai-platform: @dev
- symfony/ai-store: @dev
Requires (Dev)
- dg/bypass-finals: ^1.9
- symfony/test-pack: ^1.2
This package is auto-updated.
Last update: 2025-09-12 19:35:59 UTC
README
๐ค๐ฌ Chat With Your Logs Using Smart AI ๐ฌ๐ค
Transform debugging from tedious to effortless! ๐ โ โก
Stop digging through dashboards and complex queries. Just ask your logs directly in plain English.
๐ Traditional vs โก AI-Powered
๐ฌ Real Examples - Ask Anything!
$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."
โ ๏ธ EXPERIMENTAL - Built on Symfony AI (experimental). Not for production use yet.
โจ What Makes It Special
๐ Semantic Search - Understands context, not just keywords
๐ง AI Analysis - Explains what happened and why
โก Lightning Fast - Get answers in seconds, not hours
๐ ๏ธ Tool-Based - Extensible architecture with Symfony AI
๐ Vector Powered - Smart similarity matching
๐ Fallback Ready - Works even when AI is unavailable
๐ Quick Start
Install
composer require hakam/ai-log-inspector-agent
Setup & Use
<?php use Hakam\AiLogInspector\Agent\Agent\LogInspectorAgent;use Symfony\AI\Platform\Capability;use Symfony\AI\Platform\Model;use Symfony\AI\Store\Bridge\Local\InMemoryStore; // Configure your AI platform $platform = new YourAIPlatform(); $model = new Model('your-model', [ Capability::TOOL_CALLING, Capability::INPUT_TEXT, Capability::OUTPUT_TEXT ]); $store = new InMemoryStore(); // Create the agent $agent = new LogInspectorAgent($platform, $model, $store); // Start asking questions! $result = $agent->ask('Why did the checkout fail?'); echo $result->getContent();
Advanced Questions
// 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?');
Response Structure
[ 'success' => true, // Found relevant logs? 'reason' => 'Payment gateway timeout caused...', // AI explanation 'evidence_logs' => [ // Supporting evidence [ 'id' => 'log_001', 'content' => '[2024-01-15] ERROR: ...', 'timestamp' => '2024-01-15T14:23:45Z', 'level' => 'error', 'source' => 'payment-service', 'tags' => ['payment', 'timeout'] ] ] ]
โ๏ธ Configuration
AI Platform Options
// OpenAI use Symfony\AI\Platform\OpenAI\OpenAIPlatform; $platform = new OpenAIPlatform($apiKey); // Anthropic use Symfony\AI\Platform\Anthropic\AnthropicPlatform; $platform = new AnthropicPlatform($apiKey); // Custom Platform class CustomPlatform implements PlatformInterface { // Your implementation }
Vector Store Options
// Memory (testing) $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);
Custom System Prompts
$customPrompt = 'You are a security log analyzer. Focus on threats and incidents.'; $agent = new LogInspectorAgent($platform, $model, $store, $customPrompt);
๐งช Testing & Validation - REAL WORKING PACKAGE
๐ฏ PROOF IT WORKS: Comprehensive end-to-end tests with real Ollama integration.
โ Full Functional Test Suite
13/13 tests PASSING with real Ollama (llama3.2:1b):
- ๐ณ Payment system analysis - Real e-commerce error investigation
- ๐ก๏ธ Security incident detection - Brute force & auth failure analysis
- ๐พ Database performance issues - Connection timeouts & query problems
- ๐ Application error analysis - Exception handling & memory issues
- โก Performance monitoring - API response time analysis
- ๐ 50+ realistic PHP logs from actual applications
๐โโ๏ธ Run Tests Yourself
# Setup Ollama curl -fsSL https://ollama.ai/install.sh | sh ollama pull llama3.2:1b # Run full test suite OLLAMA_MODEL=llama3.2:1b vendor/bin/phpunit test/Functional/
Results: 104 successful assertions, 2-10s response times, multi-platform support proven.
๐ Extend Testing
Want to test with YOUR logs? Add more realistic log examples:
-
Expand
test/fixtures/logs/
with logs from:- โ Laravel applications - Real Laravel/Eloquent errors (included)
- โ Kubernetes pods - OOMKilled, CrashLoopBackOff, resource issues (included)
- โ Microservices - Circuit breakers, service mesh, distributed tracing (included)
- Symfony applications
- API gateways
- Docker containers
-
Test real scenarios:
- "What caused the 3 AM outage?"
- "Show me memory leaks in user service"
- "Find all failed credit card transactions"
- "Analyze API rate limiting errors"
-
Validate with your AI platform:
- OpenAI (full semantic search)
- Anthropic (full semantic search)
- Ollama (intelligent keyword fallback)
This package works with REAL data and REAL AI models - test it yourself!
๐ค Contributing
- Fork the repository
- Create feature branch:
git checkout -b feature/amazing-feature
- Commit changes:
git commit -m 'Add amazing feature'
- Push to branch:
git push origin feature/amazing-feature
- Open Pull Request
Made with โค๏ธ for developers who hate digging through logs!
Transform your debugging experience today ๐