Home/Inference & Serving/ChatAbstractions
ChatAbstractions logo

ChatAbstractions

andrewnguonly/ChatAbstractions

LangChain chat model abstractions for dynamic failover, load balancing, chaos engineering, and more!

GraphCanon updated 2w · GitHub synced 2w

84 stars5 forksLast push 2y Python MIT

Decision brief

ChatAbstractions is a Python-based collection of abstractions wrapped around LangChain's `BaseChatModel` that enable dynamic failover, load balancing, and chaos engineering without altering existing chat interfaces.

Good fit when

  • - When you need dynamic model selection in your application to switch between different LLMs at runtime based on performance or outages.
  • - If you require a robust solution for load balancing across multiple language models during peak usage times to prevent rate limitations.

Avoid when

  • - This tool is not recommended if you are looking for static solutions where the chat model or load balancing policies do not change at runtime.
  • - If you require integration with a specific set of models that aren't compatible with LangChain's `BaseChatModel`, this might not be suitable.
Pricing:
freemium
Requirements:
Min 2 GB RAM

Observed Jul 12, 2026 · Source: enrich:decision_facts

Verify the decision

Maintenance and security

Full trust report
Maintenance
Dormant (921d since push)
As of 2w
Provenance
Not a fork · Personal account
As of 2w
Security (OSV)
16 low (16 low)
As of 1mo

Public GitHub metadata and optional OSV scans. Signals, not a guarantee. Trust methodology.

Install

pip install ChatAbstractions
PyPI

Similar tools

Same-category neighbours. No typed graph edges are catalogued for this tool yet.

Evidence and technical details

Sourced facts, taxonomy, compatibility claims, README excerpt, and machine-readable endpoints.

Overview

A collection of chat model abstractions that wrap LangChain's `BaseChatModel` to add functionalities like dynamic model selection, failover, and load balancing without breaking existing interfaces.

Capability facts

Languages
python

Source: github.language · Aug 8, 2026

Categories

Compatibility

Sourced claims from the README excerpt - not unsourced marketing copy.

LangChain integrationLangChain

Source: README excerpt (regex_v1, Aug 8, 2026)

collection of chat model abstractions that demonstrates how to wrap (subclass) [LangChain's `BaseChatModel`](https://github.com/langchain-ai/langchain/blob/v0.0.350/libs
Source link
Python runtimePython

Source: README excerpt (regex_v1, Aug 8, 2026)

```python from typing import Any, List, Optional
Source link

Tags

README

ChatAbstractions

This repo is a collection of chat model abstractions that demonstrates how to wrap (subclass) LangChain's BaseChatModel in order to add functionality to a chain without breaking existing chat model interfaces. The use cases for wrapping chat models in this manner are mostly focused on dynamic model selection. However, other use cases are possible as well.

Subclassing BaseChatModel requires implementing 2 methods: _llm_type() and _generate().

from typing import Any, List, Optional

from langchain.callbacks.manager import CallbackManagerForLLMRun
from langchain.chat_models.base import BaseChatModel
from langchain.schema import ChatResult
from langchain.schema.messages import BaseMessage


class ChatSubclass(BaseChatModel):

    @property
    def _llm_type(self) -> str:
        """Return type of chat model."""
        raise NotImplementedError

    def _generate(
        self,
        messages: List[BaseMessage],
        stop: Optional[List[str]] = None,
        run_manager: Optional[CallbackManagerForLLMRun] = None,
        **kwargs: Any,
    ) -> ChatResult:
        """Add custom logic here."""
        raise NotImplementedError

ChatDynamic

The implementation of ChatDynamic demonstrates the ability to select a chat model at runtime based on environment variable configuration. In the event of an outage or degraded performance by an LLM provider, this functionality (i.e. failover) may be desirable.

# set environment variable DYNAMIC_CHAT_MODEL_ID=gpt-4

# initialize chat models
gpt_4_model = ChatOpenAI(model="gpt-4")
gpt_3_5_model = ChatOpenAI(model="gpt-3.5-turbo")

# specify all models that can be selected in the ChatDynamic instance
chat_dynamic_model = ChatDynamic(
    models={
        "gpt-4": gpt_4_model,
        "gpt-3_5": gpt_3_5_model,
    },
    default_model="gpt-4",
)

Reading: Dynamic Failover and Load Balancing LLMs With LangChain

ChatLoadBalance

The implementation of ChatLoadBalance demonstrates the ability to select a method of load balancing (random, round robin, least rate limited) between LLM models. In the event of rate limiting or peak usage times, this functionality may be desirable.

# initialize chat models
gpt_4_model = ChatOpenAI(model="gpt-4")
gpt_3_5_model = ChatOpenAI(model="gpt-3.5-turbo")

# specify all models that can be selected in the ChatLoadBalance instance
chat_load_balance_model = ChatLoadBalance(
    models=[gpt_4_model, gpt_3_5_model],
    load_balance_type=1,  # 0 - random, 1 - round robin, 2 - least rate limited
)

Reading: Dynamic Failover and Load Balancing LLMs With LangChain

ChatChaos

The implementation of ChatChaos demonstrates the ability to substitute normal LLM behavior with chaotic behavior. The purpose of this abstraction is to promote the Principles of Chaos Engineering in the context of LLM applications. This abstraction is inspired by Netflix's Chaos Monkey.

# initialize chat model
gpt_3_5_model = ChatOpenAI(model="gpt-3.5-turbo")

# configure ChatChaos
chat_chaos_model = ChatChaos(
    model=gpt_3_5_model,
    enabled=True,
    cron=croniter("0 * * * *"),
    duration_mins=60,
    ratio=1.0,
    enable_malformed_json=False,
    enable_hallucination=True,
    enable_latency=False,
    hallucination_prompt="Write a poem about the Python programming language.",
)

Reading: ChatChaos: The Good, the Bad, and the Ugly

ChatNotDiamond

The implementation of ChatNotDiamond demonstrates the abi

For agents

This page has a .md twin and JSON over the API.

Was this helpful?

Anonymous feedback helps us improve pages and translations.