I built a PHP AI agent library with zero dependencies - here's the code
说明与用途
NanoAgent 是一个 PHP 库,允许在不使用外部语言或依赖的情况下创建 LLM 代理,使用单个 Composer 包和简单的配置数组。
问题
Adding an LLM agent to a PHP application typically requires a Python microservice, leading to extra runtimes, deployments, and network hops.
结果
NanoAgent enables in-process PHP agents with tool-first design, persistent memory, and support for multiple LLM providers, all without external runtimes.
工作流
- Install NanoAgent via Composer:
composer require hammrouni/nanoagent - Instantiate an Agent with LLM configuration:
new Agent(llm: ['provider'=>'groq','model'=>'llama-3.3-70b-versatile','api_key'=>getenv('GROQ_API_KEY')]) - Register a PHP function as a tool:
$agent->tool('weather', fn(string $city)=>"It is 22°C in {$city}.") - Invoke the agent:
$agent->chat('How warm is it in Marrakech?')
证据
If you've tried to add an LLM agent to a PHP application, you've probably hit the same wall: every serious library is Python.
I built NanoAgent: a PHP library that does agents natively. One composer require. Zero runtime dependencies. No Python.
One config array, any provider. OpenAI, Groq, Anthropic, DeepSeek, OpenRouter or a local model behind any OpenAI-compatible endpoint (Ollama, llama.cpp server). Swap with one line.
Tool-first. You map plain PHP functions as tools. Your agent can query your database, hit your internal APIs, read your device telemetry the code you already wrote.
Persistent memory. Conversations survive across requests via pluggable drivers: JSON files, SQLite, MySQL, PostgreSQL or your own.
The agent decides to call weather, your function runs in-process, the result comes back, and the reply is generated. No sidecar, no queue, no second language.
- 记录日期: 2026-10-15T20:55:56.488Z