subhashladumor1/larachain

LaraChain - LangChain-inspired AI orchestration framework for PHP and Laravel

Maintainers

Package info

github.com/subhashladumor1/larachain

pkg:composer/subhashladumor1/larachain

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.1 2026-03-08 06:11 UTC

This package is auto-updated.

Last update: 2026-03-08 06:12:11 UTC


README

Latest Version on Packagist GitHub Tests Action Status

LaraChain is a LangChain-inspired AI orchestration framework built specifically for Laravel 12. In 2026, building AI apps is no longer just about calling an APIβ€”it's about building Stateful Workflows, Agentic Tools, and Modern RAG pipelines. LaraChain provides the primitives to build these with professional-grade elegance and type safety.

πŸ—ΊοΈ How LaraChain Works

LaraChain follows a "Runnable" architecture where every componentβ€”prompts, models, retrievers, and parsersβ€”can be piped together.

graph LR
    A[Input Variables] --> B[PromptTemplate]
    B -->|Pipe| C[ChatModel]
    C -->|Pipe| D[OutputParser]
    D --> E[Final PHP Object]
    
    subgraph "The RAG Loop"
        F[PDF/Web/CSV] --> G[TextSplitter]
        G --> H[EmbeddingModel]
        H --> I[VectorStore]
        I -->|Retrieve| B
    end
Loading

πŸš€ Key Features

Feature Description
LCEL-style Piping Use the .pipe() pattern to chain components like a pro.
Smart Agents ReAct (Reasoning + Acting) agents that use tools and make decisions.
Advanced RAG Document loaders, recursive text splitting, and vector retrieval.
Postgres Support Native pgvector integration for production-ready storage.
Memory Drivers Stateful conversation buffers to maintain context.
Laravel 12 Native Deeply integrated with the Laravel AI SDK and Service Container.

πŸ“‚ Folder Structure

larachain/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ Agents/           # ReAct and Agentic logic
β”‚   β”œβ”€β”€ Chains/           # Pipeline orchestration (Sequential, Router)
β”‚   β”œβ”€β”€ Contracts/        # Interfaces for all components
β”‚   β”œβ”€β”€ DocumentLoaders/  # Reading PDF, Web, CSV contents
β”‚   β”œβ”€β”€ Embeddings/       # Vector generation logic
β”‚   β”œβ”€β”€ Laravel/          # Service Providers and Facades
β”‚   β”œβ”€β”€ Memory/           # Conversation state management
β”‚   β”œβ”€β”€ Messages/         # Message objects (User, Assistant, System)
β”‚   β”œβ”€β”€ Models/           # AI Model wrappers (ChatModel)
β”‚   β”œβ”€β”€ Parsers/          # Output formatting (JSON, XML)
β”‚   β”œβ”€β”€ Prompts/          # Template management
β”‚   β”œβ”€β”€ Retrieval/        # Document retrieval logic
β”‚   β”œβ”€β”€ Support/          # Traits and Helpers (HasPipe)
β”‚   β”œβ”€β”€ TextSplitters/    # Document chunking logic
β”‚   β”œβ”€β”€ Toolkits/         # Grouped tools (File, Database)
β”‚   β”œβ”€β”€ Tools/            # Individual tool implementations
β”‚   └── VectorStores/     # Storage drivers (In-Memory, Postgres)

πŸ“– Functional API Guide

1. The Pipe Pattern (Recommended)

The hallmark of LaraChain 2026 is the ability to chain components elegantly.

use LaraChain\Prompts\PromptTemplate;
use LaraChain\Models\ChatModel;
use LaraChain\Parsers\JsonParser;

$chain = PromptTemplate::make('Extract data from this text: {text} into JSON format.')
    ->pipe(new ChatModel('gpt-4o'))
    ->pipe(new JsonParser());

$output = $chain->invoke(['text' => 'My name is John and I live in London.']);
// Returns: ['name' => 'John', 'location' => 'London']

2. Intelligent Agents

An agent can use specialized tools to complete complex tasks.

use LaraChain\Agents\AgentExecutor;
use LaraChain\Toolkits\FileToolkit;

$agent = AgentExecutor::make()
    ->tools((new FileToolkit())->getTools());

$response = $agent->run("Read config.json and summarize it in readme.md");

3. RAG (Postgres + Recursive Chunking)

Handle large documents with state-of-the-art chunking and production storage.

use LaraChain\TextSplitters\RecursiveCharacterTextSplitter;
use LaraChain\VectorStores\PostgresVectorStore;
use LaraChain\Embeddings\EmbeddingModel;

$splitter = new RecursiveCharacterTextSplitter(chunkSize: 1000, chunkOverlap: 200);
$chunks = $splitter->splitText($largePdfContent);

$store = new PostgresVectorStore(new EmbeddingModel());
$store->addTexts($chunks);

βš–οΈ LaraChain vs. LangChain (For Laravel)

Feature LangChain (Python/JS) LaraChain (PHP/Laravel)
Syntax Pipe Operator (|) Fluent .pipe() Method
Integration Ad-hoc Native Service Providers / Facades
I/O General Laravel FileSystem / DB Facades
Agents LangGraph ReAct / Future LaraGraph
Models Custom Drivers Laravel AI SDK (Native)

πŸ“ˆ Use Cases

  1. Semantic Document Search: Build a "Chat with your PDF" app in minutes using RecursiveSplitter and PostgresVectorStore.
  2. Autonomous Code Auditor: Use the FileToolkit and AgentExecutor to scan your repository for security flaws.
  3. Structured Data Extraction: Pipe raw OCR text through a ChatModel and JsonParser to ingest invoices into your database.

πŸ› οΈ Installation & Setup

composer require subhashladumor1/larachain
php artisan vendor:publish --tag="larachain-config"

Refer to LARACHAIN_VERIFICATION_2026.md for detailed verification of all 2026 market features.

πŸ› οΈ Multi-Provider Management

LaraChain uses a Driver-based Architecture (similar to Laravel's Database or Mail systems). You can configure and switch between providers at runtime.

1. Configuration (config/larachain.php)

Define multiple LLM, Vector, and Embedding providers:

'default' => [
    'llm' => 'openai',
    'vectorstore' => 'postgres',
],

'llms' => [
    'openai' => ['model' => 'gpt-4o'],
    'anthropic' => ['model' => 'claude-3-5-sonnet'],
],

2. Switching Providers at Runtime

Use the LaraChain facade to swap drivers dynamically:

// Use Anthropic instead of the default OpenAI
$model = LaraChain::model('anthropic');

// Use a specific vector store
$vectorStore = LaraChain::vectors()->driver('memory');

// Chain them together
$chain = PromptTemplate::make('Hello {name}')
    ->pipe($model)
    ->pipe(new JsonParser());

βš™οΈ Configuration

Contributions are welcome! Pull requests for new Vector Drivers (Pinecone, Qdrant) are prioritized.

πŸ“„ License

The MIT License (MIT). See License File.