ChatAbstractions logo

ChatAbstractions

Free

LangChain chat model abstractions for dynamic failover, load balancing, chaos engineering, and more! ![GitHub Repo stars](https://img.shields.io/github/stars/andrewnguonly/ChatAbstractions?style=social)

FreeFree tier
Type
Open Source

About ChatAbstractions

ChatAbstractions is an open-source Python library that extends LangChain's BaseChatModel with dynamic model selection and resilience patterns. It provides three main abstractions: ChatDynamic for runtime failover based on environment variable configuration, ChatLoadBalance for distributing requests across models using random, round robin, or least rate limited strategies, and ChatChaos for injecting controlled failures to test LLM application robustness, inspired by Netflix Chaos Monkey. The project demonstrates how to subclass LangChain's chat model interface to add functionality without breaking existing chains, making it ideal for production scenarios requiring high availability and controlled experimentation.

Key Features

Subclasses LangChain's BaseChatModel to add functionality without breaking existing interfaces
ChatDynamic: runtime model selection based on environment variable for failover
ChatLoadBalance: distributes requests across LLMs using random, round robin, or least rate limited strategies
ChatChaos: injects controlled chaotic behavior to test LLM application resilience (chaos engineering)
Supports dynamic failover in case of LLM provider outages or degraded performance
Enables load balancing to mitigate rate limiting and peak usage issues
Implements chaos engineering principles for LLM applications (inspired by Netflix Chaos Monkey)
Requires only implementing _llm_type() and _generate() methods to create custom abstractions

Pros & Cons

Pros
  • Lightweight and easy to integrate with existing LangChain chains
  • Provides production-ready patterns for reliability and testing
  • Open source with clear documentation and examples
  • Modular design allows combining failover, load balancing, and chaos engineering as needed
Cons
  • Limited to LangChain's BaseChatModel interface (requires LangChain dependency)
  • Chaos engineering features may require careful configuration to avoid unintended production impact
  • Does not include built-in monitoring or alerting; users must implement their own observability

Best For

Production systems needing automatic failover between LLM providers (e.g., GPT-4 to GPT-3.5)Load balancing across multiple models to handle rate limits and traffic spikesTesting LLM application resilience through controlled chaos experimentsDynamic model selection based on runtime configuration without code changes

FAQ

What is ChatAbstractions?
ChatAbstractions is a collection of LangChain chat model abstractions that wrap BaseChatModel to add dynamic failover, load balancing, and chaos engineering capabilities.
How does ChatDynamic work?
ChatDynamic selects a chat model at runtime based on the environment variable DYNAMIC_CHAT_MODEL_ID, enabling failover between models like GPT-4 and GPT-3.5.
What load balancing strategies does ChatLoadBalance support?
ChatLoadBalance supports three strategies: random, round robin, and least rate limited, configurable via the load_balance_type parameter (0, 1, or 2).
What is ChatChaos?
ChatChaos is an abstraction that substitutes normal LLM behavior with chaotic behavior to promote chaos engineering principles in LLM applications, inspired by Netflix Chaos Monkey.
Is ChatAbstractions free to use?
Yes, ChatAbstractions is open source and free to use under the license provided in the repository.