Skip to main content

Production HTTP server for LangChain/LangGraph agents โ€” OpenAI-compatible API, streaming, session memory and agent discovery

Project description

Fast LangChain Server

๐Ÿš€ Production HTTP server for LangChain/LangGraph agents with OpenAI-compatible API, streaming, session memory, and agent discovery.

License: MIT Python 3.11+ PyPI version

Overview

Fast LangChain Server transforms your LangChain/LangGraph agents into production-ready HTTP services. Deploy agents with a single line of code, get streaming responses, automatic session management, and built-in observability.

Perfect for building:

  • ๐Ÿค– Agent APIs for client applications
  • ๐Ÿ”— Multi-agent orchestration backends
  • ๐Ÿ“Š LLM-powered microservices
  • ๐ŸŽฏ RAG systems with tool calling

Features

  • OpenAI-Compatible API โ€” Drop-in compatible with OpenAI clients and third-party tools
  • Streaming Responses โ€” Real-time token streaming with Server-Sent Events (SSE)
  • Session Memory โ€” Automatic conversation history management with optional Redis persistence
  • Agent Discovery โ€” Built-in card endpoint to inspect agent capabilities and tools
  • Tool Calling โ€” Native LangChain tool integration with automatic marshaling
  • Production Ready โ€” Health checks, structured logging, request tracing, OpenTelemetry support
  • Type Safe โ€” Pydantic validation on all endpoints
  • Multiple Patterns โ€” Works with create_agent() or custom CompiledStateGraph

Quick Start

Installation

pip install fast-langchain-server

Or with development dependencies:

git clone https://github.com/yourusername/fast-langchain-server.git
cd fast-langchain-server
make dev

Minimal Example

Create an agent.py:

from langchain.agents import create_agent
from langchain_core.tools import tool
from fast_langchain_server import serve

@tool
def add(a: float, b: float) -> float:
    """Add two numbers."""
    return a + b

@tool
def greet(name: str) -> str:
    """Greet someone."""
    return f"Hello, {name}!"

# Create your agent
agent = create_agent(
    model="openai:gpt-4o",
    tools=[add, greet],
    system_prompt="You are a helpful assistant."
)

# Wrap it as an HTTP service
app = serve(agent, tools=[add, greet])

Run it:

AGENT_NAME=my-agent \
  MODEL_API_URL=https://api.openai.com/v1 \
  MODEL_NAME=gpt-4o \
  OPENAI_API_KEY=sk-... \
  fast-langchain-server run agent.py

Visit http://localhost:8000/health to verify it's running.

Usage Patterns

Pattern A: Using create_agent

The modern LangChain 1.x API. Uses LangGraph under the hood:

from langchain.agents import create_agent
from fast_langchain_server import serve

agent = create_agent(
    model="openai:gpt-4o",
    tools=TOOLS,
    system_prompt="Your system prompt here"
)

app = serve(agent, tools=TOOLS)

Pattern B: Custom LangGraph Graph

For more control, bring your own CompiledStateGraph:

from langgraph.prebuilt import create_react_agent
from fast_langchain_server import serve

graph = create_react_agent(model, tools=TOOLS)
app = serve(graph, tools=TOOLS)

API Endpoints

POST /invoke

Invoke the agent synchronously.

curl -X POST http://localhost:8000/invoke \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "user", "content": "What is 2+2?"}]}'

Response:

{
  "output": "4",
  "session_id": "sess_abc123...",
  "messages": [...]
}

POST /stream

Invoke the agent with streaming (SSE).

curl -N http://localhost:8000/stream \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "user", "content": "Tell me a joke"}]}'

Streams delimited JSON events in real-time.

GET /card

Inspect the agent's configuration and available tools.

curl http://localhost:8000/card

Response:

{
  "name": "my-agent",
  "description": "A helpful assistant",
  "tools": [
    {
      "name": "add",
      "description": "Add two numbers",
      "input_schema": {...}
    }
  ]
}

GET /health

Health check endpoint.

curl http://localhost:8000/health

Configuration

Set via environment variables:

Variable Required Default Description
AGENT_NAME โœ“ โ€” Identifier for your agent
MODEL_API_URL โœ“ โ€” Base URL for LLM API (e.g., OpenAI, Ollama)
MODEL_NAME โœ“ โ€” Model identifier (e.g., gpt-4o, llama3.2)
OPENAI_API_KEY For OpenAI โ€” API key (or use model-specific auth)
AGENT_TIMEOUT โ€” 300 Request timeout in seconds
REDIS_URL For persistence โ€” Redis connection URL for session memory
OTEL_EXPORTER_OTLP_ENDPOINT For tracing โ€” OpenTelemetry collector endpoint

Docker

Build

make docker-build

Or manually:

docker build -t langchain-agent-server .

Run

docker run -p 8000:8000 \
  -e AGENT_NAME=my-agent \
  -e MODEL_API_URL=https://api.openai.com/v1 \
  -e MODEL_NAME=gpt-4o \
  -e OPENAI_API_KEY=sk-... \
  -v $(pwd)/agent.py:/app/agent.py \
  langchain-agent-server

Development

Install dev dependencies

make dev

Run tests

make test

Lint

make lint

Run locally with reload

make run

(Edit agent.py and it will reload automatically)

Clean build artifacts

make clean

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Client / LLM App   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
           โ”‚
      HTTP โ”‚ OpenAI-compatible
           โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  FastAPI Server                 โ”‚
โ”‚  โ”œโ”€ /invoke                     โ”‚
โ”‚  โ”œโ”€ /stream                     โ”‚
โ”‚  โ”œโ”€ /card                       โ”‚
โ”‚  โ””โ”€ /health                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
           โ”‚
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚             โ”‚
โ”Œโ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Agent  โ”‚   โ”‚ Session Mem  โ”‚
โ”‚ (User) โ”‚   โ”‚ (Optional    โ”‚
โ”‚        โ”‚   โ”‚  Redis)      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Performance

  • ~100ms latency for simple tool calls (OpenAI API)
  • Streaming reduces perceived latency by delivering tokens in real-time
  • Async I/O handles concurrent requests efficiently
  • Redis caching of session memory reduces round-trips

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Roadmap

  • Batching API for multiple agent invocations
  • Custom session backends (PostgreSQL, DynamoDB)
  • Cost tracking and rate limiting per agent
  • Agent versioning and canary deployments
  • Built-in monitoring dashboard
  • WebSocket support for real-time bidirectional communication

License

This project is licensed under the MIT License โ€” see the LICENSE file for details.

Support


Made with โค๏ธ for the AI community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fast_langchain_server-0.1.2.tar.gz (53.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fast_langchain_server-0.1.2-py3-none-any.whl (29.0 kB view details)

Uploaded Python 3

File details

Details for the file fast_langchain_server-0.1.2.tar.gz.

File metadata

  • Download URL: fast_langchain_server-0.1.2.tar.gz
  • Upload date:
  • Size: 53.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fast_langchain_server-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d81513a2f6c94c19e89442e5e3705f2085d3adbc5777f07aaca764f17347767a
MD5 56a4bb26bc0896bb894ccd257982404f
BLAKE2b-256 13710d63265e2c36bb7c1ca3b7a8b2b06cf1209f8f1f617303a7cee8a0e128d1

See more details on using hashes here.

File details

Details for the file fast_langchain_server-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fast_langchain_server-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 02831edcf526259db8dfbb32503a1bb1ede635d4d91d0adab3b28b6480944b59
MD5 160d6c1852f18a421df0fa7bec211623
BLAKE2b-256 59b3eef6c42c61223b625d232bd9308ae5a6403f2226c1bc5fb44afc6b3788aa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page