phpClaw Launches: Native PHP Runtime for AI Agents

Original title: Show HN: phpClaw – AI agent runtime for PHP with tools, memory and guards
68AI Score

phpClaw is a zero-dependency AI agent runtime for PHP featuring built-in ReAct loops, tool execution, and security guards. It supports automatic multi-LLM provider switching and offers MCP server integration, enabling PHP developers to rapidly build intelligent agents with memory and action capabilities.

Full Report

Contents4 sections

The universal AI agent engine for PHP.

Tools, memory, security, and a ReAct loop, already built. Zero framework dependencies in core. Any LLM provider.

Documentation · Adapters · Why phpClaw · Install · MCP · Security


First agent in seconds

BASH
composer require phpclaw/phpclaw
export ANTHROPIC_API_KEY="sk-ant-..."
PHP
$agent = PhpClaw\Claw::builder()->build();
echo $agent->send('What can you help me with?')->text;

One env var, one builder, one send(). The builder checks ANTHROPIC_API_KEY, then OPENAI_API_KEY, GROQ_API_KEY, GEMINI_API_KEY, MISTRAL_API_KEY, DEEPSEEK_API_KEY, OLLAMA_HOST, in that order, and uses whichever it finds first. No YAML, no agent framework to learn, no vendor lock-in.

Give your agent tools

An agent without tools can only talk. Register the ones your application needs and it starts doing real work:

PHP
use PhpClaw\Claw;
use PhpClaw\Tools\ShellTool;
use PhpClaw\Tools\HttpTool;
use PhpClaw\Tools\FileReadTool;
use PhpClaw\Tools\DatabaseQueryTool;
use PhpClaw\Tools\CodeSearchTool;

$agent = Claw::builder()
    ->tools([
        new ShellTool(allowlist: ['ls', 'df', 'tail']),
        new HttpTool(),
        new FileReadTool(),
        new DatabaseQueryTool($pdo),
        new CodeSearchTool(),
    ])
    ->build();
Text
> Check disk usage and tail the last 20 lines of the error log
> Is api.example.com responding right now?
> Run a read-only SELECT to count today's orders
> Find every place UserService is used in this codebase

The agent decides which tools to call and in what order, running a ReAct loop (reason, act, observe, repeat) until it has an answer or hits the iteration cap. This works identically whether the tools touch your shell, your database, your HTTP APIs, or your codebase.

Why phpClaw

Every "AI in PHP" tutorial ends the same way: an HTTP client bolted onto a provider API, a hand-rolled tool-call loop, and a prayer that the prompt holds up in production. A generic LLM SDK gives you the API client. phpClaw gives you the agent runtime around it: the loop, the guards, the memory, the framework wiring, already assembled.

phpClawGeneric LLM SDK
Tool-calling loopReAct, built inYou write it
Framework-native adapters8, idiomatic per frameworkNone
Prompt injection defence8 default guards + opt-in rate limitingNone
Memory abstractionSwappable driversNone
Streaming + tool-calls togetherHybrid modeVaries
MCP server bundledExpose any app to Claude DesktopNone
Chains and multi-agent graphsPipeline and Graph: loops, human pause and resume, fan-outYou build it
Zero framework deps in coreext-curl, ext-json, ext-mbstring, doneDepends
Core licenseMIT, nothing gatedVaries

Not trying to be everything. phpClaw isn't a RAG framework: there are no embeddings or vector stores. It's built to give an LLM tools, memory and security controls against your real application, and to chain those agents into pipelines and graphs when one call isn't enough.

What phpClaw provides

Agent runtime. A ReAct loop with a hard iteration cap (max_iterations, default 20), pluggable tools, pluggable memory, and skills the model loads on demand through the load_skill tool, all running inside a single reasoning cycle.

Pipelines and graphs. Pipeline chains steps (prompt template, agent, structured output, your own callables) with retry and fallback. Graph runs nodes that loop, branch, pause for a human, resume in another process, and fan out to branches that run inline or are drained by workers from cron, a queue or the CLI. See Pipelines and Graphs.

Provider flexibility. 7 providers auto-detected from environment variables: Anthropic, OpenAI, Groq, Gemini, Mistral, DeepSeek, Ollama. A custom OpenAI-compatible endpoint is also supported, opt-in via PHPCLAW_PROVIDER=custom. Switch providers with ->provider() and ->model(), no code changes elsewhere.

Production controls. 8 security guards on by default (prompt injection, PII, code injection, Unicode, homoglyph, role-switch, destructive SQL, message length), plus rate limiting available as an opt-in guard. Tool results are sanitised unconditionally by ToolOutputGuard, which sits outside the guard registry, and LLM output sanitisation is on by default and can be disabled with ->sanitiseOutput(false). ShellTool is allowlist-only with a hard-coded command blocklist that can't be overridden. HttpTool validates resolved IPs, not just hostnames, closing the DNS-rebinding gap a prefix blocklist alone would miss. FileReadTool/FileWriteTool are workspace-sandboxed and refuse sensitive paths and extensions.

Developer experience. Token-by-token streaming, prompt caching (cached input tokens billed at Anthropic's discounted cache-read rate, see Anthropic's pricing for the exact figure), and extended thinking (Claude's reasoning chain exposed on $response->thinking).

Ecosystem. 8 framework and CMS adapters, an MCP server for exposing your tools to Claude Desktop and Claude Code, and an optional cloud transport for a hosted, continuously-updated prompt-scan guard.

(注:更多技术实现细节与完整 API 文档请查阅原项目 README)