NANOAGENT / v0.4
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.

  • 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, and the configured provider. Your code Agent Tools MCP servers Provider your PHP functions Streamable HTTP Groq, OpenAI, Anthropic, ...

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

§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
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.

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');
$agent->registerMcpServer($mcpClient);

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

§5 — ARTICLES

Writing about NanoAgent and why it exists.

dev.to Why I Keep Coming Back to PHP (Even for AI Agents)
LinkedIn LinkedIn article

§6 — GET STARTED

Ship your first agent today.

$ composer require hammrouni/nanoagent