kafka-agent-bridge
kafka-agent-bridge is a small Python library for developers who already know LangGraph or CrewAI and want Kafka to be the event bus without hand-rolling consumers, retries, idempotency, result publishing, and dead-letter handling. It fills the space between heavyweight streaming-agent platforms and raw framework glue code.
Quickstart
pip install -e '.[langgraph,redis,dev]'
docker compose up
from kafka_agent_bridge import KafkaAgentBridge
from kafka_agent_bridge.adapters import LangGraphAdapter
adapter = LangGraphAdapter(graph=compiled_graph)
bridge = KafkaAgentBridge(
bootstrap_servers="localhost:9092",
consumer_group="reports-agent",
idempotency_backend="redis://localhost:6379",
)
bridge.register(
topic="reports.requested",
handler=adapter,
adapter="langgraph",
output_topic="reports.completed",
dlq_topic="reports.dlq",
)
await bridge.start()
Run the included LangGraph example:
make dev
make example-fraud
Kafka UI is available at http://localhost:8080.
Architecture
Kafka topic
|
v
KafkaAgentBridge
|-- JsonDeserializer -> EventEnvelope
|-- AgentRouter -> topic glob, X-Agent-Type, predicate
|-- IdempotencyGuard -> Redis or in-memory TTL cache
|-- LangGraphAdapter / CrewAIAdapter / custom handler
|-- KafkaResultProducer -> output topic
|
+-- DeadLetterQueue -> *.dlq after retries
LangGraph graphs can use KafkaCheckpointer:
thread_id -> compacted Kafka topic agent.checkpoints
What Is Included
KafkaAgentBridgeasync runtime with multiple topic registrations.AgentRouterwith glob, header, and predicate routing.KafkaResultProducerwith JSON serialization and configurable batching.EventEnvelopePydantic model for consumed messages.- Redis-backed or in-memory idempotency guard.
- Retry and dead-letter publishing.
LangGraphAdapter,CrewAIAdapter, andKafkaCheckpointer.- Docker Compose with Kafka, Redis, and Kafka UI.
Avro and Schema Registry support are intentionally stubbed for v0.2.
Comparison
| Approach | Best For | Tradeoff | How It Is Handled |
|---|---|---|---|
| kafka-agent-bridge | Python teams wiring LangGraph or CrewAI into Kafka quickly | Lightweight v0.1 surface; advanced Kafka tuning remains explicit | Sensible defaults cover the common path, while consumer_kwargs, producer_kwargs, retry settings, DLQ topics, and idempotency backends stay configurable when a production workload needs them. |
| Confluent Streaming Agents | Teams already on Confluent's managed ecosystem | More platform coupling and operational surface area | Use it when managed Confluent services are already the standard; use this library when teams want a smaller OSS Python layer over plain Kafka. |
| Hand-rolling | Highly custom Kafka and agent orchestration needs | Rebuilds routing, retries, DLQ, idempotency, and checkpointing yourself | Start with this library for the repeated plumbing, then drop down to custom handlers, predicates, adapters, and raw Kafka kwargs where the workflow genuinely needs custom behavior. |
The intent is not to hide Kafka forever. The bridge makes the default path small, then leaves explicit escape hatches for teams that need partitioning, offset, batching, security, or consumer-group tuning.
Local Development
python -m venv venv
venv/bin/pip install -e '.[all,dev]'
make test
make lint
Contributing
Issues and pull requests are welcome. For now, keep contributions focused on small, well-tested improvements: adapter behavior, Kafka operational safety, examples, and documentation. Please include tests for behavior changes and keep public APIs typed and documented.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kafka_agent_bridge-0.1.0.tar.gz.
File metadata
- Download URL: kafka_agent_bridge-0.1.0.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80c75e645fe27a07aed6514e20c4e3fc904e3a9de0573d6fd0ef468c7e9f1db3
|
|
| MD5 |
c13e2d33bfcacdf72949d7c099a2c7cc
|
|
| BLAKE2b-256 |
33ccb5aa970cf3ee1b5b3060cc4e80173b95f416e0ca58a8d0883b606bb24ca2
|
File details
Details for the file kafka_agent_bridge-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kafka_agent_bridge-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee1cde562659e67760d1da5b5cd8fe7c8a13db1965dd77511c3df38b76faf7f6
|
|
| MD5 |
bdd2868b145a3361fb42595089f804ae
|
|
| BLAKE2b-256 |
1a7b5b8b9665ac8f113dff43d53448f2e5ed3496d1f768f0040f1ff41f25f5ff
|