Universal AI Agent Engine · PHP 8.1+

AI agents for
your PHP framework.

One install. One API key. Agents running in Laravel, Symfony, WordPress, Drupal, Joomla, Magento, PrestaShop and OpenCart, in about a minute.

8 adapters 8 LLM providers 8 security guards MIT licensed
Watch the full demo (67s)
terminal
$
$
$
context memory hits + named skills merged in
guards 8 default guards scan the message
loop think → act → observe
respond text · provider · model · tokens
→

Cycles through all 8 adapters · composer install or zip upload

Everything an agent needs

One API. Every agent feature.

Plain PHP on phpClaw core, the engine under all 8 adapters.

Send a message, get a full response.

One call returns the text, the model that answered and the tokens it used. Add fallback providers and phpClaw tries them in order when a provider fails.

use PhpClaw\Claw;

$claw = Claw::builder()
    ->systemPrompt('You are a concise assistant for a PHP web shop.')
    ->build();

$response = $claw->send('In one sentence: what is composer.lock for?');

echo $response->text;
echo $response->model;
echo $response->totalTokens();

No provider line needed: phpClaw reads PHPCLAW_PROVIDER and your provider's API key, such as ANTHROPIC_API_KEY, from the environment.

Works in your stack

Same agent, your framework's way.

One install, one API key. First agent running before your coffee gets cold.

install
composer require phpclaw/phpclaw-laravel
usage
use PhpClaw\Claw;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class AgentController extends Controller
{
    public function __construct(
        private readonly Claw $agent,
    ) {}

    public function send(Request $request): JsonResponse
    {
        $response = $this->agent->send($request->input('message'));

        return response()->json([
            'text'       => $response->text,
            'provider'   => $response->provider,
            'tokens_in'  => $response->inputTokens,
            'tokens_out' => $response->outputTokens,
        ]);
    }

    public function stream(Request $request): \Symfony\Component\HttpFoundation\StreamedResponse
    {
        return response()->stream(function () use ($request): void {
            $this->agent->stream($request->input('message'), function (string $token): void {
                echo "data: {$token}\n\n";
                ob_flush(); flush();
            });
        }, headers: ['Content-Type' => 'text/event-stream']);
    }
}
run
# Set any one API key
echo "ANTHROPIC_API_KEY=sk-ant-..." >> .env

# Run from the terminal
php artisan phpclaw "which PHP version and packages does this project use?"
→ PHP ^8.2 with laravel/framework ^12.0, from composer.json.
Full API reference, memory drivers, streaming → phpclaw.ai/docs

Provider auto-detection

Works with every major LLM.

Auto-detected from your API key. Switch with one line. No code changes.

1st detected

Anthropic

ANTHROPIC_API_KEY

Default model

claude-haiku-4-5-20251001

2nd detected

OpenAI

OPENAI_API_KEY

Default model

gpt-4o-mini

3rd detected

Groq

GROQ_API_KEY

Default model

llama-3.1-8b-instant

4th detected

Gemini

GEMINI_API_KEY

Default model

gemini-3.5-flash-lite

5th detected

Mistral

MISTRAL_API_KEY

Default model

mistral-small-latest

6th detected

DeepSeek

DEEPSEEK_API_KEY

Default model

deepseek-flash

7th detected

Ollama

OLLAMA_HOST

Default model

qwen2.5:7b

compatible

Custom

base URL + key

Default model

any OpenAI-compatible model

Override any time: PHPCLAW_PROVIDER=groq   PHPCLAW_MODEL=llama-3.3-70b-versatile

Under the hood

How it works.

A clean ReAct loop. Memory and skills merge in, guards scan before the model ever sees it. Tools sandboxed. Memory pluggable. Your framework wires everything together, through its own container or factory.

User Message

CLI · HTTP · Queue · Stream

Message Augmentation

Top 3 memory hits + named skill content prepended

GuardRegistry

8 default guards · InjectionGuard alone has 11 patterns

AgentResponse

text · provider · model · tokens · iterations · duration_ms

P1: Core is framework-zero

packages/core has ZERO framework dependencies. Only PHP 8.1+, ext-curl, ext-json, ext-mbstring.

P8: Security non-negotiable

GuardRegistry::registerDefaults() runs during boot in every adapter, before the engine can serve a single message.

P5: Store Messages control

store_messages = true by default; set false and nothing is stored.

Built for PHP developers

Why phpClaw?

Zero compromises on security, privacy, or framework idioms. Works the way your framework already works.

Feels native to your framework

Each adapter integrates the way the framework expects: Artisan for Laravel, Console for Symfony, WP-CLI for WordPress. No generic wrapper bolted on the side.

Native CLI, native memory driver, and the framework's own wiring: the container in Laravel and Symfony, factories in the CMS adapters.

No vendor lock-in

Anthropic, OpenAI, Groq, Gemini, Mistral and DeepSeek are auto-detected from your API key, and Ollama from OLLAMA_HOST; any other OpenAI-compatible endpoint works through the Custom provider. Switch providers without touching application code.

Override any time: PHPCLAW_PROVIDER=groq PHPCLAW_MODEL=llama-3.3-70b-versatile

Agents remember conversations

Conversations live in your own database. No Redis to run, no extra service to deploy, no vendor store. The adapter uses your platform's own database layer, and each new message is matched against stored memory so the top 3 hits reach the prompt.

Drivers ship for file, array, Redis and every framework-native store.

You control what gets stored

store_messages defaults to true, so history works out of the box. Set it to false and nothing is stored: no conversation row, no prompt, no reply, so each conversation starts empty.

One setting per adapter, no code change, applies to every memory driver.

Running in one API key

Set one API key and run. No setup wizard, no scaffolding step. Everything else has sane defaults you can override later, not now.

ANTHROPIC_API_KEY=sk-ant-… that's the entire setup.

Works inside the tools you already use

Expose any phpClaw app to Claude Desktop, Claude Code, Cursor, Windsurf, and Zed over the Model Context Protocol, no code changes to your existing tools.

composer require phpclaw/phpclaw-mcp: stdio and Streamable HTTP both supported.

Observe every step of every run

54 lifecycle events fire across the agent, tools, providers, memory, guards and graphs: attach a listener to any of them to hook in logging, metrics, or custom behavior.

agent.* · provider.* · tool.* · guard.* · memory.* · conversation.* · and more.

Blocks prompt injection before your model sees it

InjectionGuard scans every message, memory context and matched skill content included, before it ever reaches the LLM. ShellTool runs allowlist-only commands; FileRead/FileWrite are sandboxed to your workspace.

8 guards run by default. GuardRegistry::registerDefaults() runs on every engine boot.

What you can build

Real capabilities, not a demo.

Every example below names the actual mechanism behind it; nothing here is illustrative fiction.

"Which customers signed up this week but never placed an order?"

Ask about your own data

The agent runs a real, read-only query with DatabaseQueryTool, once you enable it, reads the actual result, and answers in plain language, no separate reporting dashboard to build.

"Build a WordPress plugin that adds a shortcode for a countdown timer."

Scaffold and package a plugin, from one command-line prompt

WordPress and Joomla ship a dedicated skill that scaffolds the files, validates them, and packages an installable ZIP from a single prompt run on the command line, once you enable the file_write tool, and you confirm each file write. It's the same install artifact you'd hand-build yourself.

"Show the last 50 error log lines and the disk usage."

Triage a production issue

LogTool reads your framework's real log files; ShellTool (on by default on Magento and in the Drupal Drush and agent service, opt-in elsewhere) runs allowlisted commands only (default: ls, pwd, df, wc, date, uptime, hostname, whoami). The agent reasons over the actual output, not a guess.

"Review this class for PHP best practices."

Get domain-specific guidance without extra prompting

Skills are listed to the model, which loads the guidance it needs with load_skill; naming a skill in your message injects it directly. No need to paste a style guide into every conversation.

"Rewrite the deploy script to add a rollback step."

Let a human confirm anything that changes state

File writes, edits, state-changing shell commands, and ZIP packaging all pass through an approval gate: a real Y/n prompt on the CLI, denied automatically anywhere there's no one to ask. On Laravel and Symfony with durable runs on, a web or queued run pauses instead, until someone approves or denies the call.

Built to run in production

Not a prototype. A dependency you can commit to.

Every claim here is enforced by the codebase, not a marketing promise.

PHP 8.1 through 8.4

Every adapter is tested across the full supported PHP range, not just the latest release. No surprise breakage on a routine PHP upgrade.

Security guards run before your model does

8 security guards run by default. Every adapter wires an approval gate for mutating tools (file write, file edit, shell, zip), so nothing changes state through the agent without a check first. Tools called through the MCP server skip the gate; the ones that change data are flagged destructiveHint: true in tools/list.

CI quality gates on every change

Automated checks run across every adapter and the core engine on every change, not just at release time.

Self-hosted, always

phpClaw runs in your process, on your server. No managed runtime, and your prompts go only to the LLM provider you choose.

MIT licensed

No paywall on the engine, no per-token markup, no usage fees.

The alternative

phpClaw vs. rolling your own.

A single HTTP call to an LLM takes ten minutes. Tool-calling, memory, and prompt-injection guards are the part most teams underestimate, and end up rebuilding for months.

Capability phpClaw Raw API calls
Agentic loop (tool call → result → next step) ✓ —
Persistent, multi-turn memory ✓ —
Prompt-injection guards ✓ —
Native framework CLI + wiring ✓ —
MCP server support ✓ —
Time to a working agent Minutes Days

Model Context Protocol

Connect to AI clients natively.

phpClaw speaks JSON-RPC 2.0 out of the box. One small entry script exposes every tool in your app to Claude Desktop, Claude Code, Cursor and more, with no changes to the tools themselves.

Your PHP App ToolRegistry
phpClaw MCP JSON-RPC 2.0
Claude Desktop stdio
Claude Code stdio
Cursor stdio
Windsurf stdio
Zed stdio
install one package, every client
composer require phpclaw/phpclaw-mcp
stdio Claude Desktop, Claude Code, Cursor, Windsurf, Zed
# mcp-server.php: register your tools, hand them to CliRunner
php mcp-server.php

.mcp.json · project root

{
  "mcpServers": {
    "phpclaw": {
      "command": "php",
      "args": ["mcp-server.php"]
    }
  }
}
Streamable HTTP web clients
# public/mcp.php, served by your web server: one MCP request per PHP request
# requires PHPCLAW_MCP_TOKEN, answers localhost only
$server = new PhpClawMcpServer($registry);
$server->serve(new StreamableHttpTransport((string) getenv('PHPCLAW_MCP_TOKEN')));

The HTTP transport accepts loopback requests only (127.0.0.1 and ::1) and rejects anything carrying an Origin header with a 403. PHPCLAW_MCP_TOKEN is required: without it the transport refuses to start. Never expose on a public IP.

Full MCP documentation

Quick start

Get started in about a minute.

Pick your framework and follow a few short steps. That's it.

Env-var driven config One API key to start Native CLI per framework
1

Install the adapter

composer require phpclaw/phpclaw-laravel
2

Set your API key any of: ANTHROPIC · OPENAI · GROQ · GEMINI · MISTRAL · DEEPSEEK …

echo "ANTHROPIC_API_KEY=sk-ant-…" >> .env
3

Run

php artisan phpclaw "hello"
→ Hello! I'm your phpClaw agent, running in Laravel.
How can I help you today?

Ready to go deeper?

Memory drivers, streaming, multi-turn conversations, custom tools…

FAQ

Common questions

Everything you need to know before adding an AI agent to your PHP app.

What is phpClaw?

phpClaw is an open-source AI agent engine for PHP. A single Composer package (or an admin-uploaded plugin for WordPress, Joomla, PrestaShop, and OpenCart) adds a production-ready AI agent to your existing app, with tool-calling, memory, and security built in. It runs on your own server, inside the framework you already use.

How do I build an AI agent in PHP?

Run composer require phpclaw/phpclaw, set one provider key such as ANTHROPIC_API_KEY, and call PhpClaw\Claw::builder()->build()->send('your message')->text. Pass tools to the builder's tools() method so the agent can read files, query the database or call APIs, and it runs a reason, act and observe loop until the task is done.

Can I add an AI agent to Laravel or WordPress?

Yes. For Laravel, run composer require phpclaw/phpclaw-laravel, add your API key to .env, then run php artisan phpclaw "hello". For WordPress, upload the phpClaw plugin ZIP under Plugins, Add New, Upload Plugin, paste your API key under phpClaw, Settings, and chat in wp-admin or run wp phpclaw send. Symfony, Drupal, Joomla, Magento, PrestaShop and OpenCart have adapters too.

Do I need Python or a separate AI service to run AI agents in PHP?

No. phpClaw is plain PHP 8.1 or newer, needing only the curl, json and mbstring extensions. The agent runs inside your existing app and calls the model provider you choose directly from your server.

Is phpClaw free?

Yes. phpClaw is open-source under the MIT license. It is fully self-hosted, with no per-token markup and no usage fees.

Which PHP frameworks and CMSs does phpClaw support?

phpClaw ships eight first-party adapters: Laravel, Symfony, WordPress, Drupal, Joomla, PrestaShop, OpenCart, and Magento. It also runs on plain PHP with no framework.

Which LLM providers can I use?

Eight are supported: Anthropic, OpenAI, Groq, Gemini, Mistral, DeepSeek, and local Ollama, plus a Custom option for any OpenAI-compatible endpoint. Set one API key and switch providers at any time without changing application code.

Do I need to fine-tune a model or send my data to a third party?

No. phpClaw needs no fine-tuning and no training data. You choose the provider, and with local Ollama your prompts never leave your server.

Is phpClaw secure?

Yes. Eight security guards run by default, including prompt-injection, destructive-SQL and PII detection, blocking unsafe input before it reaches the model. Message storage is a single setting you control.

Open source · MIT

Build the next adapter.

ToolInterface, MemoryInterface, GuardInterface and SkillInterface are public and documented. Publish your own phpclaw-{framework} to Packagist.

11 steps Full guide
  1. 01

    composer.json

    phpclaw/phpclaw in require (not require-dev)

  2. 02

    ToolInterface

    name() · description() · inputSchema() · execute(), plus routing + capability on adapter tools

  3. 03

    MemoryInterface

    get · set · forget · flush · all · has + TTL · optional search()

  4. 04

    Bootstrap class

    ServiceProvider · Plugin · Bundle · Module

  5. 05

    bootRegistries()

    GuardRegistry::registerDefaults() runs before the engine serves anything

  6. 06

    CLI command

    Artisan / Console / WP-CLI / Drush / bin/magento…

  7. 07

    Custom guard

    Optional: IP allowlist, domain rules… (rate limiting ships built-in, opt-in)

  8. 08

    Lifecycle hooks

    54 events: agent.before → graph.join

  9. 09

    MemoryRegistry

    Lazy factory: register your DB driver

  10. 10

    Tests

    ArrayMemory in unit tests · real coverage, not just the report-only CI gate

  11. 11

    Publish

    Packagist + PR to add to community list

Pre-publish checklist
  • declare(strict_types=1) in every file
  • Concrete classes are final; extend via interfaces (abstract bases allowed)
  • phpclaw/phpclaw in require, not require-dev
  • GuardRegistry::registerDefaults() runs during boot, before the engine handles a message
  • Adapter tools use HasToolExecutionContract: plan() · perform() · verify() · complete() · requiredCapability()
  • inputSchema() uses new \stdClass() for no-param tools (ToolRegistry auto-normalises [], but be explicit)
  • Tests use ArrayMemory, no real DB or file I/O in unit tests
  • Real test coverage per class: CI's coverage gate is whole-package and report-only, not a merge blocker
  • README covers: install → quick start → config table → providers

phpClaw is open source under the MIT License.

Self-hosted · no usage fees · contributions welcome

Star on GitHub

For teams shipping to production

Need a custom tool, integration, or adapter?

We build tailored phpClaw integrations for your CRM, ERP, or internal systems, working directly with the people who maintain phpClaw.