LLM AI Agents

Sales Analyst Agent

This agent can provide you following:

  • Generate sales report
  • Get sales analysis
  • Get recommendations
 
<?php

declare(strict_types=1);

use 
app\classes\llmagents\AiAgentExecutor;
use 
app\classes\llmagents\salesanalysis\SalesAnalysisAgent;

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

    
$reportPath 'pages/ai-agents/llm-agents/data/IC-Weekly-Sales-Activity-Report-11538.csv';

    
// Generate report
    
$result $checker->execute(
        
'Generate sales report from report path: ' $reportPath
    
);

    
// 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 "Sales Analysis:\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.004 Mb Time running: 0.001 sec.
Sales Analysis:
Analysis Process:
Tool Called: generate_sales_report
Arguments: {"reportPath":"pages/ai-agents/llm-agents/data/IC-Weekly-Sales-Activity-Report-11538.csv"}

Tool Called: analyze_sales_data
Arguments: {"reportPath":"pages/ai-agents/llm-agents/data/IC-Weekly-Sales-Activity-Report-11538.csv"}

Tool Called: forecast_future_sales
Arguments: {"reportPath":"pages/ai-agents/llm-agents/data/IC-Weekly-Sales-Activity-Report-11538.csv","forecastMethod":"linear","forecastPeriods":4,"timeUnit":"weeks","confidence":95,"seasonality":1}

 

### AI: The analysis of the sales data extracted from the provided report indicates the following key insights:
---

### Summary of Sales Activity
- **Total Sales:** $5,880,400
- **Total Orders:** 95 (total count of records)
- **Total Units Sold:** 13,304 units
- **Average Order Value:** This information wasn't available directly, but can be calculated as Total Sales divided by Total Orders, yielding approximately $61,000 per order.
- **Unique Customers:** No specific data was provided to determine unique customers.

### Detailed Insights
1. **Sales Performance by Region:**
   - **Northeast:** $983,750 (Variance: -$16,250)
   - **Southeast:** $1,066,300 (Variance: +$116,300)
   - **Midwest:** $734,350 (Variance: +$94,350)
   - **Southwest:** $1,665,000 (Variance: +$65,000)
   - **West Coast:** $1,431,000 (Variance: +$231,000)

   The **West Coast** showed the highest revenue and positive variance from targets, indicating effective sales strategies in that region. The **Southeast** also performed well above its target.

2. **Sales Performance by Sales Representative:**
   - **David Wilson** (West Coast) had the highest individual sales revenue at $1,431,000.
    - **Amanda Rodriguez** (Southwest) followed closely with $1,665,000.
    - **John Smith** (Northeast) and **Sarah Johnson** (Southeast) had mixed results, showing both successes and challenges.

3. **Product Breakdown:**
   - **Enterprise Solutions** contributed the most to revenue at $2,125,000.
    - **Mid-Market Solutions** and **Small Business Package** also made significant contributions, highlighting a diverse product portfolio.

### Recommendations
1. **Focus on High-Performing Regions:** Increase sales efforts in the West Coast and Southwest regions by leveraging successful strategies used there.

2. **Product Strategy:** Given that Enterprise Solutions contribute significantly to sales, consider enhancing marketing and sales tactics for this category to further capitalize on its success.

3. **Sales Training:** For representatives in regions underperforming against their targets, consider additional training or resources to help improve their sales techniques.

4. **Customer Acquisition:** Investigate strategies to attract new customers, particularly in regions like the Northeast, where performance has lagged.

5. **Data Collection Improvement:** To enable future forecasting, it's crucial to ensure more granular data is collected consistently, particularly on unique customers and more detailed sales metrics.

Unfortunately, due to insufficient time series data, forecasting future sales trends was not possible. To assist with forecasting in the future, ensure that historical sales data is collected over a sufficient timeline.

If you need further analysis or specific insights, please let me know!
Result Format:

Debug:
--