PHPackages                             droath/nextus-ai - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. droath/nextus-ai

ActiveLibrary

droath/nextus-ai
================

Nextus AI is a unified Laravel client library for multiple LLM providers (OpenAI, Anthropic, Perplexity), providing seamless backend integration for AI-powered applications.

013PHPCI failing

Since Nov 2Pushed 6mo agoCompare

[ Source](https://github.com/droath/nexus-ai)[ Packagist](https://packagist.org/packages/droath/nextus-ai)[ RSS](/packages/droath-nextus-ai/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Nextus AI - Laravel LLM Provider Client
=======================================

[](#nextus-ai---laravel-llm-provider-client)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3b1d95c475d5768fa73d0597d29e324d9dbd9b76c5c71f61af008146cc761156/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64726f6174682f6e65787475732d61692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/droath/nextus-ai)[![GitHub Tests Action Status](https://camo.githubusercontent.com/beee1d43a888c3ac36e1a81ba7dee8dbfd743fb779e08a1338fc40cff0aad0f6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f64726f6174682f6e65787475732d61692f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/droath/nextus-ai/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/c7a7f3300238e1e52f82a094a20e021332a86524b525e98b4d42194a72dc52b5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f64726f6174682f6e65787475732d61692f7068707374616e2e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/droath/nextus-ai/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/d522debfce888d1a216034fa0a2943ed4edf5fb0b5efcc446851a7e3defb089e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64726f6174682f6e65787475732d61692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/droath/nextus-ai)

Nextus AI is a unified Laravel client library designed for multiple LLM providers, including OpenAI, Anthropic Claude, and Perplexity. This package offers a consistent interface for working with Large Language Models, featuring agent coordination, tool execution, and flexible memory strategies.

Features
--------

[](#features)

- **Multi-Provider Support**: Seamlessly switch between OpenAI, Anthropic Claude, and Perplexity with a unified API
- **Driver Pattern Architecture**: Clean abstraction layer for LLM provider integrations
- **Agent System**: Coordinate multiple AI agents with parallel, sequential, or router strategies
- **Tool Integration**: Define and execute tools that LLMs can call during conversations
- **Memory Strategies**: Flexible memory management with database, session, or null strategies
- **Streaming Support**: Real-time streaming responses from compatible providers
- **Testing Helpers**: Built-in fake clients and testing utilities
- **Laravel Integration**: Native Laravel service provider with auto-discovery

Requirements
------------

[](#requirements)

- PHP 8.3 or higher
- Laravel 11.x or higher
- Valid API keys for desired LLM providers

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require droath/nextus-ai
```

The service provider will be automatically discovered by Laravel.

Configuration
-------------

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag="nextus-ai-config"
```

This will create `config/nextus-ai.php` where you can configure your LLM providers.

### Environment Variables

[](#environment-variables)

Add your API keys to your `.env` file:

```
# OpenAI Configuration
OPENAI_API_KEY=your-openai-api-key
OPENAI_ORGANIZATION=your-org-id  # Optional

# Anthropic Claude Configuration
CLAUDE_API_KEY=your-claude-api-key

# Perplexity Configuration
PERPLEXITY_API_KEY=your-perplexity-api-key
```

### Database Migrations

[](#database-migrations)

If you plan to use the database memory strategy or agent memory features, run the migrations:

```
php artisan migrate
```

Usage
-----

[](#usage)

### Basic Chat Example

[](#basic-chat-example)

```
use Droath\NextusAi\Facades\NextusAiClient;
use Droath\NextusAi\Drivers\Enums\LlmProvider;
use Droath\NextusAi\Messages\UserMessage;

// Using OpenAI with Message objects (recommended)
$response = NextusAiClient::driver(LlmProvider::OPENAI)
    ->chat()
    ->withMessages([
        UserMessage::make('What is Laravel?')
    ])();

echo $response->getMessage();

// Alternative: Using array syntax (also supported)
$response = NextusAiClient::driver(LlmProvider::OPENAI)
    ->chat()
    ->withMessages([
        ['role' => 'user', 'content' => 'What is Laravel?']
    ])();
```

### Using Different Providers

[](#using-different-providers)

```
use Droath\NextusAi\Facades\NextusAiClient;
use Droath\NextusAi\Messages\UserMessage;
use Droath\NextusAi\Messages\SystemMessage;
use Droath\NextusAi\Drivers\Enums\LlmProvider;

// Using Claude with Message objects
$driver = NextusAiClient::driver(LlmProvider::CLAUDE);
$claudeResponse = $driver->chat()
    ->withModel('claude-3-5-sonnet-20241022')
    ->withMessages([
        SystemMessage::make('You are a helpful programming assistant.'),
        UserMessage::make('Explain async programming')
    ])();

// Using Perplexity
$driver = NextusAiClient::driver(LlmProvider::PERPLEXITY);
$perplexityResponse = $driver->chat()
    ->withMessages([
        UserMessage::make('Latest news on AI developments')
    ])();
```

### Message Classes

[](#message-classes)

The package provides dedicated message classes for better type safety and structure:

```
use Droath\NextusAi\Facades\NextusAiClient;
use Droath\NextusAi\Drivers\Enums\LlmProvider;
use Droath\NextusAi\Messages\UserMessage;
use Droath\NextusAi\Messages\SystemMessage;
use Droath\NextusAi\Messages\AssistantMessage;

// Create messages using the make() method
$systemMessage = SystemMessage::make('You are a helpful assistant.');
$userMessage = UserMessage::make('Hello, how are you?');

// Send conversation with multiple messages
$driver = NextusAiClient::driver(LlmProvider::OPENAI);
$response = $driver->chat()
    ->withMessages([
        SystemMessage::make('You are a helpful assistant specialized in Laravel.'),
        UserMessage::make('What are the new features in Laravel 11?'),
    ])();

// UserMessage supports context for additional metadata
$messageWithContext = UserMessage::make(
    'Analyze this code',
    context: 'This is a Laravel controller with CRUD operations'
);
```

**Available Message Classes:**

- `UserMessage` - Messages from the user
- `SystemMessage` - System instructions/prompts
- `AssistantMessage` - Messages from the AI assistant

### Working with Agents

[](#working-with-agents)

Create intelligent agents that can coordinate tasks:

```
use Droath\NextusAi\Agents\Agent;
use Droath\NextusAi\Agents\AgentCoordinator;
use Droath\NextusAi\Agents\Enums\AgentStrategy;

// Create specialized agents
$researchAgent = Agent::make()
    ->setSystemPrompt('You are a research assistant specialized in gathering information.');

$writerAgent = Agent::make()
    ->setSystemPrompt('You are a content writer who creates engaging articles.');

// Coordinate agents with a strategy
$coordinator = AgentCoordinator::make(
    'Create a blog post about Laravel',
    [$researchAgent, $writerAgent],
    AgentStrategy::SEQUENTIAL
);

$result = $coordinator->run($resource);
```

### Using Tools

[](#using-tools)

Define tools that LLMs can invoke:

```
use Droath\NextusAi\Facades\NextusAiClient;
use Droath\NextusAi\Drivers\Enums\LlmProvider;
use Droath\NextusAi\Messages\UserMessage;
use Droath\NextusAi\Tools\Tool;
use Droath\NextusAi\Tools\ToolProperty;

$weatherTool = Tool::make('get_weather')
    ->describe('Get the current weather for a location')
    ->using(function (array $arguments) {
        // Your tool implementation here
        $location = $arguments['location'];
        $unit = $arguments['unit'] ?? 'fahrenheit';

        // Example: fetch weather from an API
        return "The current weather in {$location} is 72 degrees {$unit}.";
    })
    ->withProperties([
        ToolProperty::make('location', 'string')
            ->describe('The city and state, e.g. San Francisco, CA')
            ->required(),
        ToolProperty::make('unit', 'string')
            ->describe('Temperature unit: celsius or fahrenheit')
            ->withEnums(['celsius', 'fahrenheit']),
    ]);

$driver = NextusAiClient::driver(LlmProvider::OPENAI);
$response = $driver->chat()
    ->withTools([$weatherTool])
    ->withMessages([
        UserMessage::make('What is the weather in San Francisco?')
    ])();

// If the LLM decides to use the tool, it will be automatically executed
// and the response will include the tool's output
```

### Memory Strategies

[](#memory-strategies)

Use memory to maintain context across interactions:

```
use Droath\NextusAi\Memory\MemoryDefinition;
use Droath\NextusAi\Memory\MemoryStrategyFactory;
use Droath\NextusAi\Agents\Agent;

// Database memory strategy
$memoryDefinition = new MemoryDefinition('database', [
    'connection' => 'mysql',
    'table' => 'llm_agent_memory'
]);

$factory = new MemoryStrategyFactory($memoryDefinition);
$memory = $factory->createInstance();

$agent = Agent::make()
    ->setSystemPrompt('You remember previous conversations')
    ->setMemory($memory);

// Store information
$memory->set('user_preference', 'prefers concise answers');

// Retrieve later
$preference = $memory->get('user_preference');
```

### Streaming Responses

[](#streaming-responses)

Get real-time streaming responses using callbacks:

```
use Droath\NextusAi\Facades\NextusAiClient;
use Droath\NextusAi\Messages\UserMessage;
use Droath\NextusAi\Drivers\Enums\LlmProvider;
use Droath\NextusAi\Responses\NextusAiResponseMessage;

$driver = NextusAiClient::driver(LlmProvider::OPENAI);
$streamOutput = '';

$chat = $driver->chat()
    ->withModel('gpt-4')
    ->withMessages([
        UserMessage::make('Write a long story')
    ])
    ->usingStream(
        function (string $chunk, bool $initialized) use (&$streamOutput) {
            // Process each chunk as it arrives
            echo $chunk;
            $streamOutput .= $chunk;
        },
        function (NextusAiResponseMessage $response) {
            // Called when streaming is complete
            echo "\n\nStreaming finished!";
        }
    );

// Execute the chat request
$response = $chat();
```

Supported LLM Providers
-----------------------

[](#supported-llm-providers)

### OpenAI

[](#openai)

- Models: GPT-4, GPT-4 Turbo, GPT-3.5 Turbo, and more
- Features: Chat, embeddings, function calling, streaming
- Configuration: API key, organization ID (optional), base URL (optional)

### Anthropic Claude

[](#anthropic-claude)

- Models: Claude 3.5 Sonnet, Claude 3 Opus, Claude 3 Haiku
- Features: Chat, function calling, streaming
- Configuration: API key

### Perplexity

[](#perplexity)

- Models: Various Perplexity models
- Features: Chat with web search capabilities
- Configuration: API key

Advanced Features
-----------------

[](#advanced-features)

### Agent Coordination Strategies

[](#agent-coordination-strategies)

1. **Parallel**: Execute multiple agents simultaneously
2. **Sequential**: Execute agents one after another, passing results
3. **Router**: Intelligently route requests to the most appropriate agent

### Memory Strategies

[](#memory-strategies-1)

- **Database Strategy**: Persistent storage using Laravel's database
- **Session Strategy**: Session-based temporary storage
- **Null Strategy**: No memory persistence (stateless)

### Custom Drivers

[](#custom-drivers)

Extend the package to support additional LLM providers by implementing the driver interface:

```
use Droath\NextusAi\Drivers\NextusAiDriver;

class CustomDriver extends NextusAiDriver
{
    // Implement required methods
}
```

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

Run code style checks:

```
vendor/bin/pint
```

Run static analysis:

```
vendor/bin/phpstan analyse
```

### Testing Your Application

[](#testing-your-application)

Use the built-in fake client for testing:

```
use Droath\NextusAi\Facades\NextusAi;
use Droath\NextusAi\Responses\NextusAiResponseMessage;

NextusAi::fake(
    responseCallback: fn() => NextusAiResponseMessage::fromString('Fake response')
);

// Your test code here
```

Console Commands
----------------

[](#console-commands)

### Memory Cleanup

[](#memory-cleanup)

Clean up expired memory entries:

```
# Perform cleanup
php artisan nextus-ai:memory:cleanup

# Dry run to see what would be cleaned
php artisan nextus-ai:memory:cleanup --dry-run
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Travis Tomka](https://github.com/droath)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance46

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/371104?v=4)[Travis Tomka](/maintainers/droath)[@droath](https://github.com/droath)

---

Top Contributors

[![droath](https://avatars.githubusercontent.com/u/371104?v=4)](https://github.com/droath "droath (12 commits)")

### Embed Badge

![Health badge](/badges/droath-nextus-ai/health.svg)

```
[![Health](https://phpackages.com/badges/droath-nextus-ai/health.svg)](https://phpackages.com/packages/droath-nextus-ai)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
