Skip to content

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LangGraph Agents

A small, reusable framework for building LLM agents on top of LangGraph — plus two example applications that show different ways to put agents to work, including an experimental "agent-as-the-backend" web app where LLM agents implement the REST API and generate the UI at request time.

Agents are backed by Azure OpenAI and call tools you provide; one set of example tools does full CRUD against Azure AI Search.

What's inside

A reusable agent base (agents/)

A thin, composable layer over LangGraph's StateGraph + ToolNode agent loop, with checkpointed memory and human-in-the-loop support:

  • Agent — the base class. Wires a model, a list of tools, and a system prompt into a compiled LangGraph graph (agent → tools → agent) with a MemorySaver checkpointer. Supports interrupts so a tool can pause and ask a human, via pluggable message_listener / user_input_listener callbacks.
  • CommandLineAgent — an Agent wired for interactive terminal chat: it prints the agent's progress and reads user input from the console (including resuming after an interrupt).
  • WorkflowAgent — an Agent for non-interactive, programmatic use. run_workflow(data) feeds JSON in and returns the parsed JSON result — handy for using an agent as a step inside a larger pipeline.
  • HTMLAgent — an Agent specialized to return a complete, renderable HTML page.

Tools (tools/)

  • tools.py — interaction primitives: ask_for_instruction (pauses for human input via a LangGraph interrupt) and report_progress.
  • ai_search_tools.py — Azure AI Search operations: search, create/update/delete documents, and list/create/delete/describe indexes.
  • html_tools.py — helpers for generating Bootstrap HTML (templates, buttons, search bars, list rendering).

Example apps

  • main.py — a command-line Azure AI Search assistant. A CommandLineAgent is given the AI Search tools and a system prompt, so you can manage indexes and documents in plain English ("find documents about X", "create an index with these fields", "delete that document").

  • app.py — an experimental Flask app where agents are the backend. Instead of hand-written route handlers, each request is handed to an agent:

    • POST /api/<path> — a WorkflowAgent interprets the path + payload, picks the right AI Search tool (search/create/update/delete), runs it, and returns JSON.
    • GET /ui/<path> — an HTMLAgent generates a complete Bootstrap web page for the requested view on the fly.

    It's a deliberately exploratory pattern — useful for prototyping and for thinking about how much of an API an agent can stand in for — not a production design.

Installation

python -m venv venv
source venv/bin/activate        # Windows: venv\Scripts\activate
pip install -r requirements.txt

Configuration

Create a .env file in the project root (it is gitignored):

# Azure OpenAI
AZURE_OPENAI_ENDPOINT=your_azure_openai_endpoint
AZURE_OPENAI_KEY=your_azure_openai_key
AZURE_OPENAI_DEPLOYMENT_NAME=your_deployment_name
AZURE_OPENAI_API_VERSION=your_api_version

# Azure AI Search (only needed for the AI Search tools / example apps)
AZURE_SEARCH_SERVICE_ENDPOINT=your_azure_search_endpoint
AZURE_SEARCH_INDEX_NAME=your_index_name
AZURE_SEARCH_API_KEY=your_azure_search_api_key

Usage

Run the command-line AI Search assistant

python main.py

Run the agent-backed web app

python app.py        # serves on http://127.0.0.1:5000 (debug)
# then hit, e.g. POST http://127.0.0.1:5000/api/search  or  GET http://127.0.0.1:5000/ui/search

Build your own agent

import os

from dotenv import load_dotenv
from langchain_openai import AzureChatOpenAI

from agents import CommandLineAgent
from tools import ask_for_instruction, report_progress

load_dotenv()

model = AzureChatOpenAI(
    azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
    api_version=os.getenv("AZURE_OPENAI_API_VERSION"),
    api_key=os.getenv("AZURE_OPENAI_KEY"),
    deployment_name=os.getenv("AZURE_OPENAI_DEPLOYMENT_NAME"),
    temperature=0,
)

agent = CommandLineAgent(
    model=model,
    tools=[ask_for_instruction, report_progress],
    agent_prompt="You are a helpful assistant that can provide information.",
)

agent.run()

To use an agent programmatically instead, swap CommandLineAgent for WorkflowAgent and call agent.run_workflow({...}) to get a parsed JSON result back.

Requirements

  • Python 3.10+
  • An Azure OpenAI deployment (and an Azure AI Search service for the search tools)

Status

This is a personal, work-in-progress project for exploring agent patterns with LangGraph. The agent base classes are reusable; the example apps — especially the agent-as-the-backend Flask app — are experiments meant for learning and prototyping rather than production use.

License

MIT — see LICENSE.

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages