LLM AI Agents

Site Status Checker Agent

This agent gives you a status of following:

  • Check if a site is up and running
  • Dig up DNS info
  • Run ping tests
  • Give you the explanation on why a site might be offline
 
<?php

declare(strict_types=1);

use 
app\classes\llmagents\AiAgentExecutor;
use 
app\classes\llmagents\sitestatuschecker\SiteStatusCheckerAgent;


// Usage example:
try {
    
// Initialize the checker
    
$checker = new AiAgentExecutor(
        
aiAgentSiteStatusCheckerAgent::class,
        
apiKeyOPEN_AI_KEY,
        
model'gpt-4o-mini',
        
finalAnalysisfalse,
        
debugtrue
    
);

    
$url 'https://aiwithphp.org';

    
// Check a specific site with a question
    
$result $checker->execute(
        
'URL to check: ' $url '\nQuestion: What is the current status of this site and are there any performance concerns?'
    
);

    
// Output debug results
    
$agentDebug ??= '';
    
$debugResult '--';
    if (
$agentDebug) {
        
$debugLog $checker->getDebugLog();
        foreach (
$debugLog as $key => $message) {
            
$debugResult .= humanize($key);
            
$debugResult .= "\n=================\n";
            
$debugResult .= $message "\n\n";
        }
    }

    
// Output the results
    
echo "Site Status Analysis:\n";
    echo 
"URL: {$url}\n\n";

    
// Show conversation history
    
echo "Analysis Process:\n";
    foreach (
$result['conversation_history'] as $message) {
        if (isset(
$message->functionCall)) {
            echo 
"Tool Called: {$message->functionCall->name}\n";
            echo 
"Arguments: {$message->functionCall->arguments}\n";
        } elseif (!empty(
$message->content)) {
            echo 
"\n&nbsp;\nAI: {$message->content}\n";
        }
        echo 
"\n";
    }

    if (!empty(
$result['final_analysis'])) {
        echo 
"\nFinal Analysis:\n{$result['final_analysis']}\n";
    }

} catch (
\Exception $e) {
    echo 
'Error: ' $e->getFile() . ' | ' $e->getLine() . "\n";
    echo 
'Error: ' $e->getMessage() . "\n";
}
Result: Memory: 0.002 Mb Time running: < 0.001 sec.
Site Status Analysis:
URL: https://aiwithphp.org

Analysis Process:
Tool Called: check_site_availability
Arguments: {"url":"https://aiwithphp.org"}

Tool Called: get_dns_info
Arguments: {"domain":"aiwithphp.org","url":"https://aiwithphp.org"}

Tool Called: perform_ping_test
Arguments: {"host":"22.36.34.125","url":"https://aiwithphp.org"}

  

### AI: Here's the current status and analysis of the site **https://aiwithphp.org**:
---

1. **Availability**: The site is online and accessible, with an HTTP status code of **200** indicating that the request was successful. The response time was approximately **217.49 ms**, which is generally acceptable for a good user experience.

2. **DNS Information**:
   - **IP Address**: The site is hosted on the IP address **54.36.31.145**.
   - **Name Servers**: The DNS is managed by the name servers **dns101.ovh.net** and **ns101.ovh.net**.

3. **Ping Test**: Although the site is online, the ping test to the IP address returned **0% packet loss**, but it reported a failure in completing the ping test. This could be due to various reasons, such as firewall settings or server configurations that prevent ICMP requests from being responded to.

### Summary
- The website is functioning well with acceptable performance metrics.
- The unsuccessful ping test might indicate that the server is configured to ignore ping requests, which is common for security reasons.

### Recommendations
- If you experience any issues accessing the site, consider checking your internet connection or trying a different network.
- If performance concerns arise, monitoring the response times over different periods could provide insights into any potential issues.
Result Format:

Debug:
--