# Patterns

Design patterns for the Langroid multi-agent LLM framework.

- Repository: https://github.com/langroid/langroid (4121 stars)
- Category: Design
- License: MIT
- Last updated: 2026-11-01
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add langroid/langroid --skill patterns -g -a claude-code -y`
Codex: `npx skills add langroid/langroid --skill patterns -g -a codex -y`
Cursor: `npx skills add langroid/langroid --skill patterns -g -a cursor -y`
Gemini CLI: `npx skills add langroid/langroid --skill patterns -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add langroid/langroid`

## Description

Design patterns for the Langroid multi-agent LLM framework. Covers agent configuration, tools, task control, and integrations.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Langroid Patterns

## Instructions

Below is an INDEX of design patterns organized by category. Each item describes
WHAT you might want to implement, followed by a REFERENCE to a document with
a complete code example.

Scan this index to find patterns matching your needs, then consult the
corresponding document.

---

## Agent & Task Basics

1. **Task Returns Tool Directly**

   Create a Langroid Agent equipped with a single Tool (a ToolMessage), and wrap
   it in a Task so that running the task returns that ToolMessage directly. Use
   this pattern when you want a simple LLM agent that returns a structured
   response.

   - Reference: `./task-return-tool.md`

---

## Tool Handlers

2. **Stateful Handler on Agent**

   Define a STATEFUL tool handler as a METHOD on the agent (not inside the
   ToolMessage). Use this pattern when: (a) the tool handler needs to execute
   external operations (API calls, database queries, file I/O), (b) you need to
   track state across retries (e.g., failure counter), (c) the handler needs
   access to agent-level resources (connections, configs), or (d) you want
   Langroid to automatically loop errors back to the LLM for self-correction.
   The method name must match the `request` field of the ToolMessage. Return a
   string for errors (LLM sees it and can retry), or DoneTool(content=result)
   to terminate successfully.

   - Reference: `./agent-tool-handler-with-state.md`

3. **Handler with Validation**

The rest: https://github.com/langroid/langroid/blob/HEAD/plugins/langroid/skills/patterns/SKILL.md
