PHPackages                             cagri/nexus - 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. [Framework](/categories/framework)
4. /
5. cagri/nexus

ActiveLibrary[Framework](/categories/framework)

cagri/nexus
===========

High-performance, provider-agnostic LLM agent framework for PHP. Supports OpenAI, Anthropic, Ollama, and any OpenAI-compatible API.

v0.1.0(3mo ago)01MITPHPPHP ^8.1

Since Mar 24Pushed 3mo agoCompare

[ Source](https://github.com/MuhammedCagri/nexus)[ Packagist](https://packagist.org/packages/cagri/nexus)[ RSS](/packages/cagri-nexus/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Nexus
=====

[](#nexus)

Provider-agnostic LLM agent framework for PHP. Works with OpenAI, Anthropic, Ollama, Groq, DeepSeek, Mistral AI, LM Studio, and any OpenAI-compatible API. All providers support tool calling and streaming.

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

[](#requirements)

PHP 8.1+, ext-curl, ext-json

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

[](#installation)

```
composer require cagri/nexus
```

Quick Start
-----------

[](#quick-start)

```
use Nexus\Nexus;

$nexus = Nexus::using('openai', 'gpt-4o')
    ->withApiKey(getenv('OPENAI_API_KEY'))
    ->create();

$response = $nexus->chat('Hello!');
echo $response->content;
```

Switching providers:

```
$nexus = Nexus::using('anthropic', 'claude-sonnet-4-20250514')
    ->withApiKey(getenv('ANTHROPIC_API_KEY'))
    ->create();

$nexus = Nexus::using('ollama', 'llama3')->create(); // local, no key

$nexus = Nexus::using('custom', 'my-model')
    ->withBaseUrl('https://my-api.example.com/v1')
    ->withApiKey('my-key')
    ->create();
```

Features
--------

[](#features)

### Streaming

[](#streaming)

```
$nexus->stream('Tell me a story.')
    ->onText(fn (string $chunk) => print($chunk))
    ->await();
```

### Agents with Tools

[](#agents-with-tools)

Implement `ToolInterface` (see `examples/03-agent-with-tools.php` for a full example):

```
$agent = Nexus::agent()
    ->withProvider($provider)
    ->withTools([new CalculatorTool(), new WeatherTool()])
    ->withMemory(new InMemoryStore())
    ->withMaxIterations(10)
    ->build();

$response = $agent->run('What is 1547 * 382?');
```

### Attribute-Based Tools

[](#attribute-based-tools)

```
#[AsTool(name: 'weather', description: 'Get current weather')]
class WeatherTool extends AttributeTool
{
    public function handle(
        #[Param(description: 'City name')] string $city,
    ): string {
        return json_encode(['city' => $city, 'temp' => 22]);
    }
}
```

### Structured Output

[](#structured-output)

Map LLM responses to typed PHP objects:

```
$person = $nexus->structured('Extract: "Ahmet, 28, Istanbul"', PersonInfo::class);
echo $person->name; // Ahmet
```

### Prompt Templates

[](#prompt-templates)

```
$response = $nexus->template(
    'Translate "{{text}}" to {{language}}.',
    ['text' => 'Hello', 'language' => 'French'],
);
```

### Middleware

[](#middleware)

```
use Nexus\Middleware\{RetryMiddleware, CacheMiddleware};

$nexus = Nexus::using('openai', 'gpt-4o')
    ->withApiKey(getenv('OPENAI_API_KEY'))
    ->create()
    ->withMiddleware(new RetryMiddleware(maxRetries: 3))
    ->withMiddleware(new CacheMiddleware(ttlSeconds: 300));
```

### Memory

[](#memory)

```
use Nexus\Memory\{InMemoryStore, FileStore};

$memory = new InMemoryStore(maxMessages: 50);                        // session-scoped
$memory = new FileStore('/tmp/conversation.json', maxMessages: 100); // persistent
```

Providers
---------

[](#providers)

- **OpenAI** -- GPT-4o, o1, etc.
- **Anthropic** -- Claude 4, Sonnet, Haiku
- **Ollama** -- Llama, Mistral, Gemma (local)
- **Groq** -- Llama, Mixtral
- **DeepSeek**
- **Mistral AI**
- **LM Studio** (local)
- Any **OpenAI-compatible** API

Architecture
------------

[](#architecture)

```
src/
├── Nexus.php, NexusBuilder.php
├── Agent/           Agent, AgentBuilder
├── Config/          ProviderConfig
├── Contract/        ProviderInterface, ToolInterface, MemoryInterface, MiddlewareInterface
├── Enum/            Provider, Role, FinishReason
├── Http/            Client (cURL)
├── Memory/          InMemoryStore, FileStore
├── Message/         Message, MessageBag, ToolCall
├── Middleware/       Pipeline, RetryMiddleware, CacheMiddleware
├── Prompt/          Template
├── Provider/        AbstractProvider, OpenAI, Anthropic, Ollama, OpenAICompatible
├── Response/        Response
├── Stream/          StreamResponse
├── Structured/      SchemaMapper
└── Tool/            AttributeTool, Parameter, ToolRegistry, Attribute/{AsTool, Param}

```

Built with
----------

[](#built-with)

Built with the assistance of [Claude Code](https://claude.com/product/claude-code).

License
-------

[](#license)

MIT

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance82

Actively maintained with recent releases

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity32

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

91d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/628e3fbde8a471ddbbb6026793dc70d9ed06bc8dc3aa15041344713c05ab405d?d=identicon)[MuhammedCagri](/maintainers/MuhammedCagri)

---

Top Contributors

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

---

Tags

phpaistreamingopenaiAgentmachine learningclaudellmanthropicgptChatGptfunction-callingollamatool-calling

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/cagri-nexus/health.svg)

```
[![Health](https://phpackages.com/badges/cagri-nexus/health.svg)](https://phpackages.com/packages/cagri-nexus)
```

###  Alternatives

[llm-agents/agents

LLM Agents PHP SDK - Autonomous Language Model Agents for PHP

16612.6k9](/packages/llm-agents-agents)[claude-php/claude-php-sdk-laravel

Laravel integration for the Claude PHP SDK - Anthropic Claude API

5219.2k](/packages/claude-php-claude-php-sdk-laravel)

PHPackages © 2026

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