Skip to content

CodeUltr0n/LangGraph-Ai-Agent

Repository files navigation

LangGraph Agentic AI Workspace

Orchestrating Advanced Conversational, Human-in-the-Loop, and Multi-Agent Workflows

Python LangChain LangGraph Groq Tavily

An educational and production-ready workspace demonstrating agentic design patterns using LangGraph and LangChain. The project exhibits three core architectures: basic state-based conversational agents, human-in-the-loop orchestration with interrupts, and multi-agent coordination with specialized roles.


View Architecture View Setup Explore Workflows


How It Works

This repository contains independent modules built on top of LangGraph's state machine execution model. Each module addresses a specific complexity pattern in AI agent design.

View System Orchestration & Flow Diagram
graph TD
    classDef main fill:#1C3C3C,stroke:#333,stroke-width:1px,color:#fff;
    classDef chatbot fill:#3776AB,stroke:#333,stroke-width:1px,color:#fff;
    classDef human fill:#F55036,stroke:#333,stroke-width:1px,color:#fff;
    classDef multi fill:#008080,stroke:#333,stroke-width:1px,color:#fff;
    classDef tool fill:#f4f4f4,stroke:#333,stroke-width:1px,color:#333;

    Workspace([User Prompt]) --> Route{Select Workflow}
    
    %% Pattern 1
    Route -->|Basic Chat| P1[1-BasicChatBot]:::chatbot
    P1 --> ChatbotNode[ChatBot Node]:::chatbot
    ChatbotNode -->|Response| Output1([User Response])

    %% Pattern 2
    Route -->|Human Approval| P2[Human Assistance]:::human
    P2 --> HILChat[Chatbot Node]:::human
    HILChat -->|Conditional Edge| HILTools[Tool Node]:::tool
    HILTools -->|TavilySearch| WebSearch[Web Search]:::tool
    HILTools -->|human_assistance| Interrupt[State Interrupt]:::human
    Interrupt -->|Input Data| ResumedChat[Resume Execution]:::human

    %% Pattern 3
    Route -->|Multi-Agent| P3[Multi-Agent System]:::multi
    P3 --> ResAgent[Researcher Agent]:::multi
    ResAgent -->|Execute Search| SearchTool[search_web]:::tool
    SearchTool --> WritAgent[Technical Writer]:::multi
    WritAgent -->|Summarize| Summary[write_summary]:::tool
Loading

Key Features

  • State-Based Graph Orchestration — Flexible node-and-edge configuration utilizing LangGraph StateGraph with explicit state variables and message reducers (add_messages).
  • Human-in-the-Loop Interruption — Mid-execution pauses utilizing LangGraph interrupt and MemorySaver checkpointer memory to request manual user inputs or reviews before resuming.
  • Supervised Multi-Agent Architecture — Specialized agent routines (Researcher & Writer) cooperating dynamically via state passing and tool node routing.
  • High-Speed Inference — Integrates groq:llama-3.3-70b-versatile via LangChain's unified init_chat_model for low-latency completions.
  • Dynamic Web Grounding — Live internet queries using Tavily search APIs to provide real-time contexts.

Tech Stack

Layer Technology Description
State Orchestration LangGraph Builds execution graphs, custom node actions, state checkpointing, and conditional edges.
Agent Abstraction LangChain Core model bindings, tool validation decorators, system prompts wrappers, and chat initialization.
Inference Engine ChatGroq Utilizes Groq Cloud APIs for Llama 3.3 execution.
Search Grounding Tavily Search Real-time search grounding integration for factual agent verification.
State Persistence MemorySaver In-memory checkpointer allowing manual interrupts, resumes, and state tracking.

Project Structure

.
├── 1-BasiChatBot/
│   └── 1-basicchatbot.ipynb      # Basic StateGraph conversational agent
├── HumanAssitance/
│   └── HumaninLoop.ipynb         # Interrupt checkpointer and human-in-the-loop tool
├── MultiAgents/
│   └── Agents.ipynb              # Hierarchical multi-agent research & write graph
├── main.py                       # Global entrypoint script
├── pyproject.toml                # UV tool configuration & dependency specifications
├── requirements.txt              # Standard requirements file
├── .env                          # API secrets (GROQ & TAVILY)
└── README.md                     # System documentation

Getting Started

Prerequisites

Installation

# Clone the repository
git clone https://github.com/your-username/langgraph-agentic-ai.git
cd langgraph-agentic-ai

# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies using uv (recommended)
uv pip install -r requirements.txt
# Or using standard pip:
pip install -r requirements.txt

Configuration

Create a .env file in the root of the project to configure your credentials:

GROQ_API_KEY=your_groq_api_key_here
TAVILY_API_KEY=your_tavily_api_key_here

The Workflows

1. Basic ChatBot

Located in 1-basicchatbot.ipynb, this workflow configures a single-node graph mapping user prompts directly to the Groq inference engine. It demonstrates the fundamental mechanics of message serialization, graph node compilation, and invocation streaming.

2. Human-in-the-Loop Interruption

Located in HumaninLoop.ipynb, this workflow uses a memory checkpointer (MemorySaver). When the chatbot attempts to trigger the human_assistance tool, the system invokes an interrupt, stopping execution and persisting the state. The user can inspect the state, edit the payload, and resume the graph run dynamically.

3. Multi-Agent System & Supervisor Architecture

Located in Agents.ipynb, this module explores advanced multi-agent orchestrations. It transitions from a basic linear handoff to an intelligent Supervisor-led corporate team structure managed dynamically by the LLM.


🌟 Dual-Orchestration Designs

A. Sequential Handoff Flow (Linear ReAct)

A straight-line state transition where the Researcher performs the initial grounding and automatically passes control to the Technical Writer to output a finalized markdown summary.

graph LR
    classDef agent fill:#008080,stroke:#333,stroke-width:1px,color:#fff;
    classDef tool fill:#f4f4f4,stroke:#333,stroke-width:1px,color:#333;
    
    Researcher[Researcher Agent]:::agent -->|search_web| Tavily[Tavily Search]:::tool
    Tavily --> Writer[Technical Writer Agent]:::agent
    Writer -->|write_summary| Out([Final Report])
Loading
B. Hierarchical Supervisor Pattern (Stateful Routing)

An advanced state machine where a centralized Supervisor Agent controls a group of specialized agents. The Supervisor reads the current conversation state and dynamically determines who works next, routing control iteratively until the task is complete.

graph TD
    classDef supervisor fill:#F55036,stroke:#333,stroke-width:1px,color:#fff;
    classDef worker fill:#3776AB,stroke:#333,stroke-width:1px,color:#fff;
    classDef router fill:#1C3C3C,stroke:#333,stroke-width:1px,color:#fff;

    Task([User Request]) --> Supervisor[Supervisor Agent]:::supervisor
    Supervisor -->|LLM Routing Decision| Router{State Router}:::router
    
    Router -->|assign researcher| Researcher[Researcher Agent]:::worker
    Router -->|assign analyst| Analyst[Analyst Agent]:::worker
    Router -->|assign writer| Writer[Writer Agent]:::worker
    Router -->|DONE| End([Final Compiled Report])

    Researcher -->|return research_data| Supervisor
    Analyst -->|return analysis| Supervisor
    Writer -->|return final_report| Supervisor
Loading

Note

SupervisorState Definition The state of the supervisor model is tracked using custom schema definitions:

class SupervisorState(MessagesState):
    next_agent: str      # Tracks routing targets (researcher/analyst/writer/end)
    research_data: str   # Gathers facts and search summaries
    analysis: str        # Houses analytic insights and strategic risks
    final_report: str    # Gathers the final report markdown compiled by the writer
    task_complete: bool  # Signal flag to trigger END
    current_task: str    # Stores original user request metadata

🛠️ Team Member Profiles & Prompts

View Agent System Prompts & Configurations
  1. Supervisor Agent
    • Role: Dynamic Project Manager.
    • Instruction: Evaluates variables {has_research}, {has_analysis}, and {has_report}. Invokes groq:llama-3.3-70b-versatile to decide the next step. Outputs only researcher, analyst, writer, or DONE.
  2. Researcher Agent
    • Role: Gathers source information, details, background facts, and current trends.
  3. Analyst Agent
    • Role: Reviews raw research data to provide actionable key insights, strategic risks, opportunities, and structured recommendations.
  4. Writer Agent
    • Role: Synthesizes the analysis and research findings into a publication-grade Executive Report.

Tip

Dynamic Routing Logic The supervisor routes messages using a declarative LangGraph conditional edge mapping function:

def router(state: SupervisorState) -> Literal["supervisor", "researcher", "analyst", "writer", "__end__"]:
    next_agent = state.get("next_agent", "supervisor")
    if next_agent == "end" or state.get("task_complete", False):
        return END
    return next_agent

Customization

The workspace is designed to be highly modular and extensible. You can adapt it to any set of services:

Component Target File Modification Details
Change LLM Model pyproject.toml / Jupyter Notebooks Modify init_chat_model("groq:llama-3.3-70b-versatile") parameters in notebooks.
Alter Agent Roles Agents.ipynb Edit system_msg strings in the researcher_agent or writer_agent blocks.
Add Custom Tools Jupyter Notebooks Decorate new Python functions with @tool and bind them to the model (e.g., llm.bind_tools(...)).
Add Checkpointers HumaninLoop.ipynb Replace MemorySaver with persistent databases (e.g., SqliteSaver or PostgresSaver) for production.

Acknowledgments


About

Intelligent agentic design patterns using LangGraph, LangChain, and Groq. Implements stateful chat loops, human-in-the-loop tool interruption, and hierarchical supervisor multi-agent orchestrations.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors