Download the PHP package tobiebenezer/php-ai without Composer

On this page you can find all versions of the php package tobiebenezer/php-ai. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-ai

AI Package (ai)

This package provides a Laravel-compatible AI Assistant infrastructure designed to integrate LLMs (e.g., OpenRouter, Gemini) with analytical tools and guardrails.


Features


Installation

Add the local repository to your host project's composer.json file:

Then install the package:

Configuration & Migrations

Publish the configuration file, migrations, and stubs:

Run the migrations to create the configuration table:


How to Write Custom AI Tools

The package discovers all classes implementing Tobiebenezer\Ai\Contracts\Tool inside the configured path (default: app/Ai/Tools/).

Extending AnalyticalTool

For database-backed, analytical querying tools, you should extend the abstract Tobiebenezer\Ai\Tools\AnalyticalTool class. This provides built-in query building, grouping, formatting, filter validation, and aggregation.

Here is an example tool that allows the AI to query a Sales table:

Implementing Tool directly

If you need a tool that does not query the database (e.g. calling an external API), implement Tobiebenezer\Ai\Contracts\Tool directly:


Guardrails

Guardrails monitor prompt context and run-time actions:

  1. InstructionGuardrail: Prepends context-specific instructions to the LLM prompt before execution.
  2. RuntimeGuardrail: Triggers events during execution phases (BEFORE_PROVIDER_REQUEST, BEFORE_TOOL_CALL, AFTER_TOOL_RESULT, BEFORE_FINAL_RESPONSE) to allow sanitizing inputs or denying requests.

Custom Guardrail Example

Overriding Package Guardrails

If you want to customize or replace a default package guardrail (such as CapabilitiesGuardrail), you can override it in your application using one of the following two approaches:

Method 1: Container Binding (Recommended)

You can register an override in your application's AppServiceProvider so that the Laravel container resolves your custom guardrail class whenever the package asks for the default one.

Method 2: Configuration Replacement

Alternatively, publish the configuration file (config/ai.php) and swap the package guardrail class in the guardrails.global or guardrails.groups array with your custom class:

Your custom guardrail must implement the respective contract (Tobiebenezer\Ai\Contracts\InstructionGuardrail or Tobiebenezer\Ai\Contracts\RuntimeGuardrail):


🛠️ Advanced Features

1. Developer Artisan Generators

Automatically bootstrap your package assets using standard Artisan console commands:

2. Request & Tool Call Audit Logs

Run the migrations to create the request log tables:

The package automatically logs:

3. Structured Outputs (JSON Schema)

Force the model to respond in structured JSON format conforming to a schema:

4. Monthly Token Budget

Prevent cost overruns by setting monthly limits in config/ai.php:

When exceeded, requests are blocked automatically and throw a GuardrailException.

5. Self-Healing Exception Recovery

If a tool execution fails (e.g., database query exceptions or column errors), the package intercepts the exception and feeds the error details back to the LLM as the tool result. The LLM can analyze the schema failure, correct its query arguments, and retry successfully.


All versions of php-ai with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3|^8.0
illuminate/contracts Version ^8.0
illuminate/support Version ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tobiebenezer/php-ai contains the following files

Loading the files please wait ...