定制 subhashladumor1/larachain 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

subhashladumor1/larachain

Composer 安装命令:

composer require subhashladumor1/larachain

包简介

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

README 文档

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.

subhashladumor1/larachain 适用场景与选型建议

subhashladumor1/larachain 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「larachain」 「laravel-ai」 「ai-agents」 「ai-orchestration」 「intelligent-agents」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 subhashladumor1/larachain 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 subhashladumor1/larachain 我们能提供哪些服务?
定制开发 / 二次开发

基于 subhashladumor1/larachain 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 33
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-04