What is PocketFlow PHP?
PocketFlow PHP is a lightweight, graph-based framework designed for PHP developers who need to build sophisticated LLM-powered applications without the bloat of heavy dependencies. It provides a simple yet powerful abstraction for creating complex, stateful workflows, giving you complete control over your architecture. If you've been looking for a focused, "bring-your-own-client" solution to orchestrate LLM interactions in PHP, this is it.
Key Features
✨ Lightweight & Focused Core At just ~400 lines of pure PHP, the framework is incredibly lean. This minimalist design means zero bloat, faster integration, and a codebase you can understand in minutes. It provides the essential tools for workflow orchestration without imposing unnecessary features or dependencies.
🔗 Graph-Based Workflow Engine Structure your application logic using a simple yet powerful graph abstraction. You define individual Nodes for specific tasks (like calling an API or processing data) and connect them into a Flow. This makes it easy to visualize, manage, and scale complex, multi-step processes with clear state management.
🚀 Completely Framework & LLM Agnostic PocketFlow PHP is not tied to any specific PHP framework (like Laravel or Symfony) or LLM provider. This "Bring Your Own Client" philosophy is a core strength; you can use any HTTP client (Guzzle, cURL) or SDK (OpenAI, Anthropic) you prefer, ensuring maximum flexibility and avoiding vendor lock-in.
⚡ Optional Asynchronous Support For performance-critical applications, you can leverage optional asynchronous execution. By integrating with ReactPHP, PocketFlow PHP allows you to run nodes in parallel, significantly speeding up I/O-bound workflows like concurrent API calls.
Use Cases
Here are a few ways you can put PocketFlow PHP to work immediately:
Build Custom LLM-Powered Agents Create a dedicated LLMNode that encapsulates calls to any language model provider. You can chain these nodes together to perform sequential tasks, such as summarizing text, then translating the summary, and finally saving the result. The framework's state management ensures data flows seamlessly between each step.
Develop Interactive Chatbots with Memory The graph-based structure is perfect for building conversational AI. By creating a ChatNode that loops back to itself, you can easily implement a REPL (Read-Eval-Print Loop). The shared state (&$shared) allows you to maintain conversation history, giving your chatbot persistent memory across multiple turns.
Implement Complex Logic with Conditional Routing Go beyond simple linear workflows. A node's outcome can determine the next step in the flow. For example, after an LLM call, you can route to a SuccessNode if the output is valid, an ErrorNode if it fails, or a RetryNode to attempt the call again. This enables you to build resilient, intelligent systems that can handle varied outcomes.
Unique Advantages
PocketFlow PHP was built to fill a specific gap in the PHP ecosystem for a truly minimalist LLM framework.
Unlike comprehensive frameworks like LLPhant or LangChain PHP, which can exceed 15,000 lines of code, PocketFlow PHP remains focused at around 400 lines. This makes it an ideal choice when you need control and simplicity, not an all-in-one, opinionated solution.
While other tools often bundle specific LLM providers, leading to heavier dependencies, PocketFlow PHP is intentionally client-agnostic. This gives you the freedom to choose the best LLM and integration method for your specific project without being locked into a particular ecosystem.
It is pure, modern PHP (8.1+), ensuring it works in any project, from a simple script to a large-scale application, without requiring a specific framework like Symfony or Laravel for compatibility.
Conclusion
PocketFlow PHP offers a refreshing, back-to-basics approach for building with LLMs in the PHP ecosystem. It provides the essential, robust foundation for workflow orchestration while empowering you with the freedom to choose your own tools and architecture. It's the ideal framework for developers who value minimalism, control, and elegant design.
Explore the documentation and start building your first LLM workflow today!
FAQ
1. Does PocketFlow PHP include an OpenAI or Anthropic client? No, and this is a key design feature. PocketFlow PHP is "client-agnostic," meaning you bring your own LLM client. This gives you full control to use any provider (OpenAI, Mistral, Google Gemini, etc.) and any HTTP client or SDK you prefer, avoiding vendor lock-in and unnecessary dependencies.
2. Is PocketFlow PHP tied to a specific framework like Laravel or Symfony? No. It is a standalone, framework-agnostic library written in pure PHP. You can integrate it into any PHP project, whether it's built on a major framework, a custom MVC, or is a simple command-line script.
3. What do I need to get started with PocketFlow PHP? All you need is PHP 8.1+ and Composer. For asynchronous workflows, you'll need to add react/socket as an optional dependency. From there, you can start building by extending the Node class and defining your first Flow.





