# Langroid

> Multi-agent LLM programming in Python, without LangChain underneath

- Category: Agents & Automation / Multi-Agent Systems
- Language: Python
- Licence: MIT
- Repository: https://github.com/langroid/langroid
- Website: https://langroid.github.io/langroid/
- Canonical page: https://ai-tldr.dev/tools/langroid/

## In short

Langroid is a lightweight Python framework for building LLM-powered applications out of collaborating agents. It sits in the Multi-Agent Systems category of the Agents & Automation tools and is open-source, written in Python and licensed MIT. To get started: install Langroid.

## Overview

Langroid is a lightweight Python framework for building LLM-powered applications out of collaborating agents. You set up Agents, equip each with optional components — an LLM, a vector store, tools and functions — assign them tasks, and let them solve a problem by exchanging messages. The project describes this multi-agent paradigm as inspired by the Actor model, though you do not need to know anything about that to use it.

Its defining design decision is what it leaves out: Langroid does not use LangChain or any other LLM framework underneath, and it works with practically any LLM behind an OpenAI-compatible API, including local models served through Ollama. The two core abstractions are small — `ChatAgent` holds an agent's configuration and conversation state, and `Task` wraps an agent in a loop that can talk to a user or to other agents' tasks via `add_sub_task`.

The framework comes out of CMU and UW-Madison researchers and ships a set of specialised agents beyond plain chat: `DocChatAgent` for retrieval-augmented question answering, `SQLChatAgent` and `TableChatAgent` for querying databases and dataframes in natural language, `Neo4jChatAgent` for knowledge graphs, and structured information extraction. It also adapts MCP servers' tools into Langroid `ToolMessage` instances, so an agent can call them like any other tool.

## What it does

- Agent + Task abstractions: wrap an agent in a task, then compose tasks into multi-agent loops with `add_sub_task`
- No LangChain or other framework dependency underneath — works with practically any LLM via an OpenAI-compatible API, local or hosted
- Specialised agents included: DocChatAgent (RAG), SQLChatAgent, TableChatAgent, Neo4jChatAgent and structured information extraction
- MCP tool adapter that converts an MCP server's tools into Langroid ToolMessage instances for any agent
- Conversation state maintained per agent, so follow-up turns keep context without manual history plumbing
- Optional extras for document chat, vector stores and databases, installed only when you need them

## Getting started

Langroid installs from PyPI as a small core with optional extras. Set the API key for whichever provider you point it at, then build up from a bare LLM call to a two-agent loop.

1. Install Langroid

   Install the core package, then add extras only for the parts you use — document chat, databases, or local Hugging Face embeddings.

```bash
pip install langroid

# optional extras
pip install "langroid[doc-chat]"
pip install "langroid[db]"
pip install "langroid[hf-embeddings]"
pip install "langroid[all]"
```

2. Configure a model and call it directly

   `OpenAIGPTConfig` points at any model served behind an OpenAI-compatible API — a hosted model, or a local one such as `ollama/mistral`.

```python
import langroid as lr
import langroid.language_models as lm

llm_cfg = lm.OpenAIGPTConfig(
    # any model served via an OpenAI-compatible API
    chat_model=lm.OpenAIChatModel.GPT4o,  # or, e.g., "ollama/mistral"
)
mdl = lm.OpenAIGPT(llm_cfg)
response = mdl.chat("What is the capital of Ontario?", max_tokens=10)
```

3. Wrap the model in an Agent, then a Task

   A `ChatAgent` keeps conversation state across calls; wrapping it in a `Task` runs the interactive loop with a user or another agent.

```python
agent_cfg = lr.ChatAgentConfig(llm=llm_cfg)
agent = lr.ChatAgent(agent_cfg)
agent.llm_response("What is the capital of China?")
response = agent.llm_response("And India?")  # maintains conversation state

task = lr.Task(agent, name="Bot", system_message="You are a helpful assistant")
task.run("Hello")  # kick off with user saying "Hello"
```

4. Compose two agents into a loop

   Give each agent its own task and system message, then attach one as a sub-task. Here a Teacher asks questions and a single-round Student answers them.

```python
teacher_agent = lr.ChatAgent(agent_cfg)
teacher_task = lr.Task(
    teacher_agent, name="Teacher",
    system_message="""
      Ask your student concise numbers questions, and give feedback.
      Start with a question.
      """
)
student_agent = lr.ChatAgent(agent_cfg)
student_task = lr.Task(
    student_agent, name="Student",
    system_message="Concisely answer the teacher's questions.",
    single_round=True,
)

teacher_task.add_sub_task(student_task)
teacher_task.run()
```

## When to use it

- Reach for it when you want explicit multi-agent structure — a reviewer agent checking a writer agent, or a planner delegating to workers — rather than one prompt doing everything
- Reach for it to build document question answering with DocChatAgent instead of assembling a retrieval pipeline by hand
- Reach for it to put natural language in front of a SQL database, a dataframe or a Neo4j graph via the specialised chat agents
- Reach for it when you want to stay off the larger frameworks and keep the option of swapping in a local model behind an OpenAI-compatible endpoint
