langchain-rabbitmq
Production-grade LangChain tools for RabbitMQ.
Give your AI agents the full power of RabbitMQ — queue management, exchange routing,
message operations, and broker monitoring — through 21 structured LangChain tools.
Table of contents
- Features
- Installation
- Quick start
- Tools reference
- Configuration
- Advanced usage
- Compatibility
- Contributing
- License
Features
- 21 LangChain tools covering every RabbitMQ operation an agent needs
- Pydantic v2 schemas — every argument is validated before touching the broker
- Sync and async —
_run/_arunon every tool; backed bypikaandaio-pika - LCEL / Runnable compatible — drop tools straight into any LangChain chain
- Structured error types —
RabbitMQConnectionError,RabbitMQChannelError,RabbitMQMessageError,RabbitMQAdminErrorsurface as agent-readable strings, never raw tracebacks - Retry logic via
tenacitywith configurable back-off - SSL/TLS support for encrypted broker connections
- Management API integration for monitoring and admin tasks
- ≥ 90 % test coverage — unit, integration (Testcontainers), and E2E agent tests
Installation
pip install langchain-rabbitmq
For development (tests, linting, docs):
pip install "langchain-rabbitmq[dev,docs]"
# or
make install
Quick start
import os
from langchain_rabbitmq import RabbitMQToolkit
# Credentials read from environment variables automatically
os.environ["RABBITMQ_URL"] = "amqp://guest:guest@localhost:5672/"
toolkit = RabbitMQToolkit.from_settings()
tools = toolkit.get_tools() # returns all 21 BaseTool instances
# Use with any LangChain agent
from langchain.agents import create_react_agent
agent = create_react_agent(llm=your_llm, tools=tools, prompt=your_prompt)
Minimal environment
docker run -d --name rabbitmq \
-p 5672:5672 -p 15672:15672 \
rabbitmq:3.12-management
Tools reference
| Category | Tool name | Description |
|---|---|---|
| Queue | rabbitmq_declare_queue |
Declare a durable or transient queue |
rabbitmq_delete_queue |
Delete a queue (optional: if-empty / if-unused guards) | |
rabbitmq_purge_queue |
Remove all messages from a queue | |
rabbitmq_bind_queue |
Bind a queue to an exchange with a routing key | |
rabbitmq_unbind_queue |
Remove a queue–exchange binding | |
rabbitmq_get_queue_info |
Fetch message count, consumer count, and state | |
| Exchange | rabbitmq_declare_exchange |
Declare a direct / fanout / topic / headers exchange |
rabbitmq_delete_exchange |
Delete an exchange | |
rabbitmq_bind_exchange |
Create an exchange-to-exchange binding | |
| Message | rabbitmq_publish_message |
Publish with routing key, headers, TTL, persistence |
rabbitmq_consume_message |
Pull a single message (basic.get) | |
rabbitmq_ack_message |
Acknowledge a delivery by tag | |
rabbitmq_nack_message |
Negative-acknowledge with optional requeue | |
rabbitmq_reject_message |
Reject a single delivery | |
| Admin | rabbitmq_list_queues |
List all queues with stats (Management API) |
rabbitmq_list_exchanges |
List all exchanges | |
rabbitmq_list_bindings |
List all bindings | |
rabbitmq_get_node_stats |
Fetch node CPU, memory, and socket metrics | |
rabbitmq_check_health |
Ping the broker and return health status | |
rabbitmq_get_connection_info |
Report open connections and channel count | |
rabbitmq_close_connection |
Gracefully close the AMQP connection |
Configuration
All settings are loaded from environment variables via RabbitMQSettings
(backed by pydantic-settings).
| Variable | Default | Description |
|---|---|---|
RABBITMQ_URL |
amqp://guest:guest@localhost:5672/ |
Full AMQP connection URL |
RABBITMQ_HOST |
localhost |
Broker hostname (used when RABBITMQ_URL is not set) |
RABBITMQ_PORT |
5672 |
AMQP port |
RABBITMQ_VHOST |
/ |
Virtual host |
RABBITMQ_USER |
guest |
AMQP username |
RABBITMQ_PASSWORD |
guest |
AMQP password |
RABBITMQ_SSL |
false |
Enable TLS |
RABBITMQ_SSL_CA_CERTS |
— | Path to CA bundle (PEM) |
RABBITMQ_CONNECTION_TIMEOUT |
10 |
Connection timeout (seconds) |
RABBITMQ_MANAGEMENT_API_URL |
— | Base URL of the Management HTTP API |
RABBITMQ_MANAGEMENT_USER |
(same as AMQP user) | Management API username |
RABBITMQ_MANAGEMENT_PASSWORD |
(same as AMQP password) | Management API password |
Programmatic configuration
from langchain_rabbitmq.config import RabbitMQSettings
from langchain_rabbitmq import RabbitMQToolkit
settings = RabbitMQSettings(
host="broker.internal",
port=5672,
virtual_host="production",
username="app",
password="s3cr3t",
ssl=True,
management_api_url="http://broker.internal:15672",
)
toolkit = RabbitMQToolkit(settings=settings)
Advanced usage
Async agent
from langchain_rabbitmq import RabbitMQToolkit
toolkit = RabbitMQToolkit.from_settings()
tools = toolkit.get_tools()
# All tools implement _arun — use with async LangChain runtimes
result = await tools[0].ainvoke({"name": "orders", "durable": True})
Individual tools
from langchain_rabbitmq.tools.queue import DeclareQueueTool
from langchain_rabbitmq.config import RabbitMQSettings
tool = DeclareQueueTool(settings=RabbitMQSettings())
result = tool.invoke({"name": "orders", "durable": True})
print(result) # "Queue 'orders' declared successfully."
Error handling
All errors derive from RabbitMQToolException and are returned to the agent as
human-readable strings. The agent can react and retry without seeing raw stack traces.
from langchain_rabbitmq.exceptions import (
RabbitMQConnectionError,
RabbitMQChannelError,
RabbitMQMessageError,
RabbitMQAdminError,
)
Compatibility
| langchain-rabbitmq | langchain-core | pika | aio-pika | RabbitMQ | Python |
|---|---|---|---|---|---|
| 0.1.x | ≥ 0.2.0 | ≥ 1.3 | ≥ 9.0 | 3.9 – 3.13 | 3.10 – 3.12 |
Contributing
See CONTRIBUTING.md for commit conventions, branch strategy, and how to run the test suite.
make test # all tests (requires Docker for integration tests)
make test-unit # unit tests only — no broker needed
make lint # ruff check
make typecheck # pyrefly strict
make security # bandit scan
License
MIT © 2024 MiltonJ23
Metadata
Release files for langchain-rabbitmq 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| langchain_rabbitmq-0.1.0.tar.gz | 84.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langchain_rabbitmq-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 133.9 kB
Release files / langchain_rabbitmq-0.1.0.tar.gz
| Download URL | langchain_rabbitmq-0.1.0.tar.gz |
|---|---|
| Size | 84.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b21af6fb9a0348e67ab5af5fea1bc6ac0cb33f22ae339e635a0ae8879297f80f
|
|
BLAKE2b-256 checksum How to use checksums |
4f72da1a7f279f9990de252d2b005684a2eceeba604d9d439cbcf97287fd4d73
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 21, 2026.
Transparency logRelease files / langchain_rabbitmq-0.1.0-py3-none-any.whl
| Download URL | langchain_rabbitmq-0.1.0-py3-none-any.whl |
|---|---|
| Size | 49.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cb3c428bdd06c98d600aa44184f17e064bf319345f7cfe7fa2765db93d486802
|
|
BLAKE2b-256 checksum How to use checksums |
59777726f899d3320f31e897d277063ef8d54bcd1e7b2199d85abe295e673e86
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 21, 2026.
Transparency log