PHPackages                             langgraph/langgraph-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. langgraph/langgraph-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

langgraph/langgraph-php
=======================

A PHP implementation of LangGraph for building language model workflows

v1.0(7mo ago)420MITPHPPHP &gt;=7.4

Since Sep 26Pushed 7mo agoCompare

[ Source](https://github.com/hqzhon/langgraph-php)[ Packagist](https://packagist.org/packages/langgraph/langgraph-php)[ RSS](/packages/langgraph-langgraph-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

LangGraph PHP SDK
=================

[](#langgraph-php-sdk)

[![Latest Version on Packagist](https://camo.githubusercontent.com/13586d6befe1bd56a33ad56701711843cfd24a7208ed1dd462e534fca88b5663/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c616e6767726170682f6c616e6767726170682d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/langgraph/langgraph-php)

A powerful PHP implementation of Python's LangGraph. This SDK enables you to build stateful, multi-agent applications with complex, graph-based logic. It provides the core components to create robust and scalable AI workflows in your PHP projects.

✨ Core Features
---------------

[](#-core-features)

- **Stateful Graphs**: Create graphs where state is passed between nodes, allowing for complex, long-running workflows.
- **Node &amp; Edge Control**: Define nodes as units of work and use edges to control the flow, including conditional branching.
- **Agent System**: A built-in factory for creating and managing AI agents.
- **AI Model Integration**: Easily connect to various large language models (e.g., DeepSeek, Qwen).
- **Persistence (Checkpointing)**: Save and restore the state of your graphs, allowing workflows to be paused and resumed.
- **Streaming**: Support for real-time streaming of responses from nodes.

🚀 Installation
--------------

[](#-installation)

You can install the package via Composer:

```
composer require langgraph/langgraph-php
```

🛠️ Usage &amp; Functionality
----------------------------

[](#️-usage--functionality)

Here’s how to use the core features of the LangGraph PHP SDK.

### 1. Creating a Basic Workflow

[](#1-creating-a-basic-workflow)

The fundamental building block is the `StateGraph`. You define a state class, add nodes (functions or callables), and connect them with edges.

```
use LangGraph\UnifiedGraph\StateGraph;
use LangGraph\UnifiedGraph\State\State;

// 1. Define the state structure for your graph
class MyState extends State {
    // Your state properties here
}

// 2. Initialize the graph with the state class
$graph = new StateGraph(MyState::class);

// 3. Add nodes, which are functions that modify the state
$graph->addNode('start', function (MyState $state) {
    echo "Executing node: start\n";
    $state->set('message', 'Hello from the start!');
    return $state;
});

$graph->addNode('middle', function (MyState $state) {
    echo "Executing node: middle\n";
    $state->set('message', $state->get('message') . ' ... and now the middle!');
    return $state;
});

$graph->addNode('end', function (MyState $state) {
    echo "Executing node: end\n";
    $state->set('message', $state->get('message') . ' ... finished!');
    return $state;
});

// 4. Define the workflow by adding edges
$graph->addEdge('start', 'middle');
$graph->addEdge('middle', 'end');

// 5. Set the entry and finish points
$graph->setEntryPoint('start');
$graph->setFinishPoint('end');

// 6. Compile the graph and run it
$runnable = $graph->compile();
$initialState = new MyState(['value' => 1]);
$finalState = $runnable->execute($initialState);

print_r($finalState->getData());
// Outputs: [ 'value' => 1, 'message' => 'Hello from the start! ... and now the middle! ... finished!' ]
```

### 2. Conditional Logic

[](#2-conditional-logic)

You can direct the flow of your graph based on the current state using conditional edges. This allows for dynamic, branching workflows.

```
// A function to decide the next step
$decider = function (MyState $state) {
    if ($state->get('value', 0) > 5) {
        return 'end_workflow';
    } else {
        return 'continue_processing';
    }
};

// Add a conditional edge from 'start'
$graph->addConditionalEdges('start', $decider, [
    'end_workflow' => 'end',
    'continue_processing' => 'middle',
]);
```

### 3. Using AI Agents

[](#3-using-ai-agents)

The SDK includes an `AgentFactory` to easily create model-based agents that can be used as nodes in your graph.

First, configure your model API keys in `config/model.php`.

```
use LangGraph\Agent\AgentFactory;
use LangGraph\Model\Factory\ModelFactory;
use LangGraph\Model\Config\ModelConfig;

// Setup factories
$modelConfig = new ModelConfig(require 'config/model.php');
$modelFactory = new ModelFactory($modelConfig->all());
$agentFactory = new AgentFactory($modelFactory);

// Create an agent
$researcherAgent = $agentFactory->createModelBasedAgent(
    'researcher',
    'deepseek', // Or another model like 'qwen'
    'You are a helpful research assistant.'
);

// Use the agent to process a query
$response = $researcherAgent->execute('What is LangGraph?');
echo $response;
```

### 4. Persistence with Checkpoints

[](#4-persistence-with-checkpoints)

Save the state of a workflow at any point and resume it later. The SDK includes a `MemoryCheckpointSaver` for simple use cases.

```
use LangGraph\UnifiedGraph\Checkpoint\MemoryCheckpointSaver;

// Set a checkpoint saver on the graph
$checkpointSaver = new MemoryCheckpointSaver();
$graph->setCheckpointSaver($checkpointSaver);

$runnable = $graph->compile();

// Run the workflow with a unique ID to enable checkpointing
$threadId = 'user_session_123';
$initialState = new MyState(['value' => 1]);
$finalState = $runnable->execute($initialState, $threadId);

// You can now retrieve checkpoints for this thread
$checkpoints = $checkpointSaver->list($threadId);
```

📚 Documentation
---------------

[](#-documentation)

For detailed documentation and FAQs, please refer to our documentation:

- [中文文档](docs/zh/README.md) - Chinese documentation
- [English Documentation](docs/en/README.md) - English documentation

Advanced Examples
-----------------

[](#advanced-examples)

For more complex examples, including multi-agent collaboration, streaming, and web integrations, please explore the scripts in the `bin/` and `examples/` directories.

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please read `CONTRIBUTING.md` for details.

📄 License
---------

[](#-license)

This project is licensed under the MIT License. See the `LICENSE` file for more information.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance62

Regular maintenance activity

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

234d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f1e38da79c9b8a8e1f21e6aa6a835b827ad044da414e5aa7412db9a7a5434d9?d=identicon)[zhonghq](/maintainers/zhonghq)

---

Top Contributors

[![hqzhon](https://avatars.githubusercontent.com/u/5800873?v=4)](https://github.com/hqzhon "hqzhon (10 commits)")

---

Tags

aiworkflowAgentchatbotllmLanguage Modellanggraph

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/langgraph-langgraph-php/health.svg)

```
[![Health](https://phpackages.com/badges/langgraph-langgraph-php/health.svg)](https://phpackages.com/packages/langgraph-langgraph-php)
```

###  Alternatives

[maestroerror/laragent

Power of AI Agents in your Laravel project

630106.4k](/packages/maestroerror-laragent)[symfony/ai-agent

PHP library for building agentic applications.

30536.7k44](/packages/symfony-ai-agent)[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

310107.9k1](/packages/cognesy-instructor-php)[ardagnsrn/ollama-php

This is a PHP library for Ollama. Ollama is an open-source project that serves as a powerful and user-friendly platform for running LLMs on your local machine. It acts as a bridge between the complexities of LLM technology and the desire for an accessible and customizable AI experience.

20755.8k](/packages/ardagnsrn-ollama-php)[soukicz/llm

LLM client with support for cache, tools and async requests

445.6k](/packages/soukicz-llm)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
