beliefstate intercepts LLM conversations, extracts factual claims, and updates a local belief database in the background to catch contradictions before they reach your users.
The problem
The model makes claims early in the session, then contradicts them later because it does not maintain active state.
Even with long context windows, crucial facts established early in a session get buried or ignored as the prompt grows.
How it works
One decorator wraps your existing function. Works with any provider SDK.
The system prompt gets relevant facts before the LLM call.
The response returns to the user immediately. Zero latency added.
beliefstate extracts factual claims from both user and assistant messages as subject–predicate–value triples.
The checker evaluates contradictions using embedding similarity and NLI.
The dispatcher applies your strategy: warn, ask, block, or update.
Quickstart
beliefstate integrates without altering your core logic. The decorator intercepts messages, queries the database, and injects state automatically.
You retain full control over the LLM arguments. You can also query the session database directly or use manual hooks for custom workflows.
Providers
Capabilities
Fires background tasks for extraction and checking after returning the response.
Utilizes vector embeddings and natural language inference rather than exact string matching.
Extracts beliefs from both user messages and assistant responses every turn, with per-source confidence caps.
Implements automated retries and fail-fast triggers to prevent downtime.
Provides middleware for FastAPI and callbacks for LangChain and LlamaIndex.
Supports permanent session deletion with task draining and receipts.
Get started
Install in less than a minute. Add state to your agent conversations today.