Search by

hameleon2x / llm-orchestra

Hameleon2x

PHP LLM client with a model catalog (OpenAI, OpenRouter, Requesty), retries and fallback models, typed errors, agent loop with tool calling and PSR-3 logging. Framework-agnostic, no SDK dependencies. PHP 7.4+.

Package info

github.com/Hameleon2x/llm-orchestra

pkg:composer/hameleon2x/llm-orchestra

Statistics

Installs: 22

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.4.2 2026-09-04 17:06 UTC

This package is auto-updated.

Last update: 2026-09-04 17:07:38 UTC


README

en ru

llm-orchestra

A PHP LLM client with a model catalog, retries and automatic switching to a backup model on failure, an agent loop with tool calling, typed errors and PSR-3 logging. Framework- and SDK-free — it talks to providers directly over ext-curl.

Installation

composer require hameleon2x/llm-orchestra

Minimal example

<?php
require __DIR__ . '/vendor/autoload.php';

use Hameleon2x\Llm\Dto\Request;
use Hameleon2x\Llm\Orchestra;
use Hameleon2x\Llm\Provider\OpenAiProvider;
use Hameleon2x\Llm\Registry;

$orchestra = new Orchestra(Registry::fromArray([
    'providers' => ['openai' => ['class' => OpenAiProvider::class, 'token' => 'sk-...']],
    'models'    => ['mini'   => ['provider' => 'openai', 'name' => 'gpt-4o-mini']],
    'defaultModel' => 'mini',
]));

$response = $orchestra->execute(Request::simple('Answer briefly.', 'What is PHP?'));

echo $response->isSuccess() ? $response->content : $response->error->category;

Everything beyond providers and models is optional: the fallback chain, retry policy, generation params, pricing and tags are added when you need them.

What's inside

  • A model catalog. The provider is transport only; a model is a key, an API slug, its own params and policy. The same model behind two providers is two entries, so nothing gets mixed up. The config is validated as a whole at build time.
  • Retries and backup models. A single retry level, tunable per error category, and one flat escalation chain per catalog.
  • Typed errors. Category, HTTP status, provider code and raw body instead of parsing message text.
  • A three-layer response. Typed data (content, toolCalls, usage), normalized provider data (extra) and the raw payload (raw) — a new provider field never requires a library release.
  • An agent loop. Tool calls, turn and call limits, pausing for user input, events for your UI.

Documentation

Requirements

  • PHP 7.4+
  • ext-curl, ext-json, ext-mbstring
  • psr/log ^1.1 || ^2.0 || ^3.0

Tests

The checks live in tests/ and need nothing but the library itself:

php tests/run.php            # every suite
php tests/run.php Runner     # only suites and cases matching the filter

Versioning

License

MIT — see LICENSE.