NANOAGENT / v0.6
NanoAgent

§1 — OVERVIEW

NanoAgent

Add AI agents to your PHP app in an afternoon — no Python sidecar, no framework to learn. Swap providers, hand it tools, connect MCP servers, and let it remember conversations across requests.

  • PHP 8.0–8.4
  • 0 runtime dependencies
  • MIT licensed
$ composer require hammrouni/nanoagent
Your PHP code calls Agent, which routes to your Tools, connected MCP servers, the configured provider, and a memory driver that stores the conversation. Your code Agent Tools MCP servers Provider your PHP functions Streamable HTTP Groq, OpenAI, Anthropic, ... Memory files, SQLite, MySQL, Postgres

FIG. 0 — one Agent, wired to your tools, any MCP server, the provider you configure, and the memory that keeps the conversation.

§2 — SPECIFICATIONS

Providers OpenAI, Groq, Anthropic, DeepSeek, OpenRouter — switched with one config array
Architecture Tool-first. Register plain PHP functions the agent can call.
Protocols MCP over Streamable HTTP — register a server, its tools work like local ones
Memory Conversations persist across requests — files, SQLite, MySQL, PostgreSQL, or your own driver
Runtime PHP 8.0–8.4, tested in CI across the full range
Footprint One Composer package. No config DSL, no framework lock-in.
License MIT

§3 — USAGE

Three steps: create an agent, give it something to call, then hand it a goal.

FIG. 1 — a basic agent

agent.php
use NanoAgent\Agent;

$agent = new Agent(llm: [
    'provider' => 'groq',
    'model'    => 'llama-3.3-70b-versatile',
    'api_key'  => getenv('GROQ_API_KEY'),
]);

echo $agent->chat('Explain what NanoAgent does, in one sentence.');

FIG. 2 — give it a tool

tools.php
use NanoAgent\Tools\FunctionTool;

$calculator = new FunctionTool(
    name: 'calculator',
    description: 'Add two numbers',
    parameters: [
        'type' => 'object',
        'properties' => [
            'a' => ['type' => 'integer'],
            'b' => ['type' => 'integer'],
        ],
        'required' => ['a', 'b'],
    ],
    callable: fn(array $args) => $args['a'] + $args['b']
);

$agent = new Agent(llm: [ /* ... */ ], tools: [$calculator]);

FIG. 3 — a goal with background context

task.php
use NanoAgent\Task;

$task = new Task($agent);
$task->addContext('Project', 'NanoAgent Library');

echo $task->execute('Summarize the project in one line.');

§4 — MCP DEMO

Connect to any Model Context Protocol server and its tools become available to the agent alongside your own — no separate integration code. Each registered tool ships its JSON Schema on every turn, so pass an allowlist to keep a large server's per-request cost down; re-calling registerMcpServer() on the same client reconciles instead of duplicating.

FIG. 4 — ask a remote MCP server

mcp.php
use NanoAgent\Mcp\McpClient;

$agent = new Agent(llm: [ /* ... */ ]);

$mcpClient = new McpClient('https://mcp.deepwiki.com/mcp');
$names = $agent->registerMcpServer($mcpClient, allowlist: ['ask_question']);

echo $agent->chat('Ask the facebook/react repo what it does.');

§5 — MEMORY

PHP forgets everything between requests. Attach a memory driver and the agent loads the conversation for a session, then saves it after every reply.

FIG. 5 — remember the conversation

memory.php
use NanoAgent\Memory\FileMemory;
use NanoAgent\Memory\PdoMemory;

// Run on every request: a fresh Agent picks up where the last one left off.
$memory = new FileMemory(__DIR__ . '/storage/memory');
// or SQLite, MySQL, PostgreSQL:
// $memory = PdoMemory::sqlite(__DIR__ . '/memory.sqlite');

$agent = new Agent(llm: [ /* ... */ ]);
$agent->setMemory($memory, 'user-' . $userId);

echo $agent->chat($_POST['message']);

Setting up a database table? See the PdoMemory guide for connections, schemas and cleanup.

§6 — ARTICLES

The NanoAgent series: 12 articles, one pattern each. Plus essays on why PHP for AI agents.

The Series 12-Part Series: From Your First Agent to Multi-Tool Orchestration
Cheatsheet The 12-Pattern Cheatsheet — every pattern, one page
dev.to Why I Keep Coming Back to PHP (Even for AI Agents)
LinkedIn LinkedIn article

§7 — GET STARTED

Ship your first agent today.

$ composer require hammrouni/nanoagent

Prefer to talk it through? Email hammrouni.khaled@gmail.com — I take on PHP AI-agent integrations and answer within a day.