LangForge is a robust AI-powered framework designed to automate the creation of LangChain-compatible tools through a modular multi-agent system. This framework enables users to define, modify, and generate custom tools leveraging pre-existing LangChain capabilities, retrieving external knowledge, and integrating human-in-the-loop approval to ensure the highest standards of quality.
Built on LangGraph, a stateful workflow framework, this system orchestrates multiple intelligent agents, each handling specialized tasks, to streamline tool creation and optimization.
The project follows a highly modular architecture, integrating object-oriented principles (OOP) to enhance maintainability, scalability, and extensibility. Each agent encapsulates specific responsibilities, ensuring clean separation of concerns and streamlined debugging.
LangGraphCustomToolBuilder/
βββ README.md # Project documentation (this file)
βββ requirements.txt # List of dependencies
βββ main.py # Main entry point to run the workflow
βββ agents/ # Individual AI agent classes
β βββ base_agent.py
β βββ tool_explorer_agent.py
β βββ research_agent.py
β βββ reasoning_agent.py
β βββ tool_creator_agent.py
β βββ human_approval_agent.py
β βββ analyzer_agent.py
β βββ writer_agent.py
βββ models/ # Pydantic-based data models
β βββ agent_state.py
βββ workflows/ # Graph-based workflow management
β βββ create_workflow.py
βββ tools/ # Generated and predefined tools
βββ __init__.py
βββ custom_search_tool.py
βββ custom_calculator_tool.py
- Generates LangChain-compatible tools based on user input.
- Utilizes LLM-powered reasoning for intelligent tool structuring.
- Supports multiple tool types, including search tools, API clients, and computational tools.
- Implements LangGraph to define structured stateful workflows.
- Each agent performs specialized roles such as research, reasoning, code generation, validation, and documentation.
- Human-in-the-loop intervention allows users to refine generated tools before finalization.
- Supports external web scraping, API calls, and knowledge retrieval.
- Dynamically identifies third-party dependencies required for tool execution.
- Integrates pre-existing LangChain tools when applicable.
- Utilizes LangGraph's memory checkpointing for seamless workflow continuity.
- Allows restarting from the last saved state in case of interruptions.
- Encapsulated agent design following Single Responsibility Principle (SRP).
- Clear separation of concerns for scalability and easy maintenance.
- Supports custom workflow modifications via
create_workflow.py.
Each agent in the workflow executes a specific function, contributing to the seamless generation of tools.
π Analyzes User Request & Identifies Relevant Tools
- Determines whether an existing LangChain tool is sufficient or a new tool must be created.
- Loads pre-existing tools and categorizes them based on functionality.
π Retrieves External Information
- Uses LLM-driven analysis to gather references, APIs, and dependencies.
- Stores research findings within
AgentState.
π§ Performs Structured Step-by-Step Reasoning
- Breaks down tool requirements into a structured implementation plan.
- Ensures input/output consistency with LangChainβs tool framework.
π Generates LangChain-Compatible Python Code
- Uses LLM-powered code synthesis to create a new tool.
- Implements synchronous and asynchronous execution methods.
π Human-in-the-Loop Verification
- Allows manual review of generated code.
- Provides options to approve, modify, or regenerate code based on feedback.
π¬ Validates & Enhances Code Quality
- Checks for syntax errors, missing docstrings, and optimization opportunities.
- Suggests error handling improvements.
π Finalizes Tool Documentation & Storage
- Stores finalized tool in
tools/. - Generates supplementary documentation, including:
- Code structure overview
- Research insights
- Tool dependencies
- Potential enhancements
- Python 3.8+
- OpenAI API key for LLM-powered agents
pip install -r requirements.txtCreate a .env file:
OPENAI_API_KEY=your-api-key-herepython main.pyUser Request: "Create a custom Wikipedia search tool."from typing import Optional, Type
from pydantic import BaseModel, Field
from langchain.tools import BaseTool
class WikipediaSearchInput(BaseModel):
query: str = Field(description="The search term for Wikipedia.")
class WikipediaSearchTool(BaseTool):
name = "wikipedia_search"
description = "Search Wikipedia articles based on a given query."
args_schema: Type[BaseModel] = WikipediaSearchInput
def _run(self, query: str) -> str:
"""Perform Wikipedia search."""
return f"Mock Wikipedia search result for: {query}"
async def _arun(self, query: str) -> str:
"""Asynchronous execution is not supported."""
raise NotImplementedError("Wikipedia search does not support async")This project is licensed under the MIT License.
π€ Author: Namit Jain
π§ Email: namit.cs.rdjps@gmail.com
π LinkedIn: https://www.linkedin.com/in/namit-jain-355367186/
- Integration with Vector Databases for tool indexing.
- Support for additional tool types (e.g., image processing, speech recognition).
- Advanced multi-agent collaboration to handle complex workflows.
- Automated API documentation generation for each tool.
π Empower AI-Driven Tool Development with LangGraph! π