PHPackages                             langchain-laravel/langchain - 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. langchain-laravel/langchain

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

langchain-laravel/langchain
===========================

A powerful Laravel package integrating multiple AI providers (OpenAI, Claude, Llama, DeepSeek) with advanced capabilities including text generation, translation, code analysis, AI agents, and mathematical reasoning.

6122PHPCI failing

Since May 29Pushed 1y agoCompare

[ Source](https://github.com/YourWisemaker/langchain-laravel)[ Packagist](https://packagist.org/packages/langchain-laravel/langchain)[ RSS](/packages/langchain-laravel-langchain/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependenciesVersions (2)Used By (0)

LangChain Laravel
=================

[](#langchain-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/69c9adb2bbfd29d9b23aa3c5de9b9927adb824c2b4d685edf0f1cc268a83cf1e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c616e67636861696e2d6c61726176656c2f6c616e67636861696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/langchain-laravel/langchain)[![Total Downloads](https://camo.githubusercontent.com/67e3dd3061d32ad3fbd3f6c8b3a1d74e21c23c21d02b1a4cddadc5ce1a3344de/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c616e67636861696e2d6c61726176656c2f6c616e67636861696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/langchain-laravel/langchain)[![GitHub Tests Action Status](https://camo.githubusercontent.com/48d53ec60c2068da4d0f9c6381862e24a2a58956113a89c82d2374705c740f17/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f596f7572576973656d616b65722f6c616e67636861696e2d6c61726176656c2f63692e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/YourWisemaker/langchain-laravel/actions?query=workflow%3Aci+branch%3Amain)[![License](https://camo.githubusercontent.com/475e6d324e02e2bd3e715d49f5c96a826ea879e775d77bc644a624a8ce374b0d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c616e67636861696e2d6c61726176656c2f6c616e67636861696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/langchain-laravel/langchain)

A powerful Laravel package that integrates multiple AI providers (OpenAI, Claude, Llama, DeepSeek) with advanced capabilities including text generation, translation, code analysis, AI agents, and mathematical reasoning.

✨ Features
----------

[](#-features)

### Core AI Capabilities

[](#core-ai-capabilities)

- **Multi-Provider Support**: OpenAI, Claude (Anthropic), Llama, and DeepSeek models
- **Enhanced AI Capabilities**: Text generation, translation, code generation/analysis, AI agents, summarization
- **Advanced Reasoning**: Mathematical problem solving and complex reasoning (DeepSeek)
- **Multi-Language Support**: Built-in translation and language-specific responses
- **Code Intelligence**: Generate, analyze, and explain code in any programming language

### Developer Experience

[](#developer-experience)

- **Dynamic Provider Switching**: Change AI providers on the fly
- **Unified API**: Consistent interface across all providers and capabilities
- **Custom Provider Support**: Register and use your own AI providers
- **Model Aliases**: Use friendly names for complex model identifiers
- **Fallback Strategy**: Automatic failover between providers
- **AI Agent Framework**: Create specialized AI agents with roles and context

### Production Ready

[](#production-ready)

- **Configurable**: Extensive configuration options via environment variables
- **Usage Tracking**: Monitor API usage and costs
- **Error Handling**: Comprehensive error handling and logging
- **Caching**: Built-in response caching for improved performance
- **Testing**: Comprehensive test suite with 95%+ coverage
- **Documentation**: Extensive documentation and examples

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Laravel 10.0 or higher
- Composer

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require langchain-laravel/langchain
```

Publish the configuration file:

```
php artisan vendor:publish --tag=langchain-config
```

Add your AI provider API keys to your `.env` file:

```
# OpenAI Configuration
OPENAI_API_KEY=your_openai_api_key_here

# Claude Configuration (optional)
CLAUDE_API_KEY=your_claude_api_key_here

# Llama Configuration (optional)
LLAMA_API_KEY=your_llama_api_key_here

# DeepSeek Configuration (optional)
DEEPSEEK_API_KEY=your_deepseek_api_key_here

# Set default provider
LANGCHAIN_DEFAULT_PROVIDER=openai
```

Quick Start
-----------

[](#quick-start)

### Basic Usage (Default Provider)

[](#basic-usage-default-provider)

```
use LangChainLaravel\Facades\LangChain;

// Simple text generation using default provider
$result = LangChain::generateText('Write a short poem about Laravel');

if ($result['success']) {
    echo $result['text'];
    echo "Tokens used: " . $result['usage']['total_tokens'];
} else {
    echo "Error: " . $result['error'];
}
```

### Multi-Provider Usage

[](#multi-provider-usage)

```
// Use OpenAI specifically
$openaiResult = LangChain::openai('Explain Laravel routing', [
    'model' => 'gpt-4',
    'max_tokens' => 200
]);

// Use Claude specifically
$claudeResult = LangChain::claude('Write a technical blog post intro', [
    'model' => 'claude-3-sonnet-20240229',
    'max_tokens' => 300
]);

// Use Llama specifically
$llamaResult = LangChain::llama('Generate PHP code for user authentication', [
    'model' => 'meta-llama/Llama-2-70b-chat-hf',
    'max_tokens' => 400
]);
```

### Dynamic Provider Selection

[](#dynamic-provider-selection)

```
// Switch provider at runtime
$provider = env('AI_PROVIDER', 'openai');
$result = LangChain::generateText('Create a README template', [], $provider);

// Set default provider
LangChain::setDefaultProvider('claude');
$result = LangChain::generateText('Now using Claude as default');
```

### Provider Management

[](#provider-management)

```
// Get available providers
$providers = LangChain::getAvailableProviders();
// Returns: ['openai', 'claude', 'llama', 'deepseek']

// Check if provider is valid
if (LangChain::isValidProvider('claude')) {
    $result = LangChain::claude('Hello from Claude!');
}

// Register a custom provider
LangChain::registerProvider('custom-ai', CustomAIProvider::class);

// Get current default provider
$current = LangChain::getDefaultProvider();
```

Usage Examples
--------------

[](#usage-examples)

### Basic Text Generation

[](#basic-text-generation)

```
use LangChainLaravel\Facades\LangChain;

// Using default provider
$result = LangChain::generateText('Explain quantum computing');

// Using specific providers
$result = LangChain::openai('Write a story about AI');
$result = LangChain::claude('Analyze this business proposal');
$result = LangChain::llama('Generate creative content');
$result = LangChain::deepseek('Solve this mathematical problem');
```

### Enhanced AI Capabilities

[](#enhanced-ai-capabilities)

```
// Multi-language translation
$translation = LangChain::translateText(
    'Hello, how are you?',
    'Spanish',
    'English'
);
// Result: 'Hola, ¿cómo estás?'

// Code generation
$code = LangChain::generateCode(
    'Create a PHP function to validate email addresses',
    'php'
);

// Code analysis and explanation
$explanation = LangChain::explainCode(
    'function fibonacci(n) { return n  $this->getConfig('default_model'),
            'temperature' => 0.7,
            'max_tokens' => 1000,
        ];
    }

    protected function validateConfig(): void
    {
        if (empty($this->getConfig('api_key'))) {
            throw new \RuntimeException('API key is required');
        }
    }
}
```

2. **Register your provider**:

```
// Register the custom provider
LangChain::registerProvider('my-ai', CustomAIProvider::class);

// Use your custom provider
$result = LangChain::generateText('Hello!', [], 'my-ai');
```

3. **Configure your provider** in `config/langchain.php`:

```
'providers' => [
    // ... existing providers
    'my-ai' => [
        'api_key' => env('MY_AI_API_KEY'),
        'base_url' => env('MY_AI_BASE_URL'),
        'default_model' => env('MY_AI_MODEL', 'default-model'),
    ],
],
```

For a complete example, see [`examples/CustomProviderExample.php`](examples/CustomProviderExample.php).

Testing
-------

[](#testing)

```
composer test
```

Run tests with coverage:

```
composer test-coverage
```

Run static analysis:

```
composer analyse
```

Documentation
-------------

[](#documentation)

- [Installation Guide](docs/installation.md)
- [Usage Guide](docs/usage-guide.md)
- [API Reference](docs/api.md)
- [Testing Guide](docs/testing-guide.md)

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

If you discover a security vulnerability within LangChain Laravel, please send an e-mail to the maintainers. All security vulnerabilities will be promptly addressed.

Credits
-------

[](#credits)

- [Wisemaker](https://github.com/YourWisemaker)
- [All Contributors](https://github.com/YourWisemaker/langchain-laravel/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity17

Early-stage or recently created project

 Bus Factor1

Top contributor holds 90% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0b700ba68803025a1baa0a8972167143c726bfa87065e618a7287efc9bce8dce?d=identicon)[YourWisemaker](/maintainers/YourWisemaker)

---

Top Contributors

[![YourWisemaker](https://avatars.githubusercontent.com/u/29248258?v=4)](https://github.com/YourWisemaker "YourWisemaker (9 commits)")[![google-labs-jules[bot]](https://avatars.githubusercontent.com/in/842251?v=4)](https://github.com/google-labs-jules[bot] "google-labs-jules[bot] (1 commits)")

### Embed Badge

![Health badge](/badges/langchain-laravel-langchain/health.svg)

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

###  Alternatives

[dazzle-php/event

Dazzle Events &amp; Dispatchers.

161.7k6](/packages/dazzle-php-event)

PHPackages © 2026

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