Catalog PyPI
PACKAGE EXPLORERView in registry

ai-followup-detector

PyPI

Detect and rewrite follow-up queries for AI applications

aichatbotconversationfollow-uplangchainllmnlp
Versions collected1
Direct dependencies6From release 0.1.1
Last observed21 Oct, 10:43 UTC

README

Version 0.1.1 documentation

AI Follow-Up Detector

Detect and rewrite follow-up queries for AI applications.

ai-followup-detector helps AI applications determine whether a user's latest message is a follow-up to a previous conversation and, when applicable, rewrite it as a standalone query.

Features

  • Detect whether a message is a follow-up
  • Rewrite follow-up messages into standalone queries
  • Works with any LLM that provides an async ainvoke() method
  • Lightweight and framework-agnostic
  • Async-first API
  • Easy to integrate into chatbots, AI agents, and RAG applications

Installation

pip install ai-followup-detector

Quick Start

from ai_followup_detector import FollowUpDetector


class MyLLM:

    async def ainvoke(self, prompt):
        # Connect your LLM here
        return {
            "follow_up": True,
            "follow_up_query": "Show sales for February"
        }


async def main():

    detector = FollowUpDetector(MyLLM())

    result = await detector.detect(
        history=[
            "Show sales for January"
        ],
        message="What about February?"
    )

    print(result)

Example result:

{
    "follow_up": True,
    "follow_up_query": "Show sales for February"
}

How It Works

The detector receives:

  1. Previous conversation history
  2. The user's current message
  3. An LLM implementation

The LLM determines whether the current message depends on the previous conversation.

For example:

Previous:
Show sales for January

Current:
What about February?

The detector can rewrite the follow-up as:

Show sales for February

API

FollowUpDetector

FollowUpDetector(llm)

Creates a follow-up detector using the supplied LLM.

detect()

await detector.detect(
    history: list[str],
    message: str
)

Returns a FollowUpResult containing:

FollowUpResult(
    follow_up=True,
    follow_up_query="Show sales for February"
)

FollowUpResult

from ai_followup_detector import FollowUpResult

The result contains:

FieldTypeDescription
follow_upboolWhether the current message is a follow-up
follow_up_querystrStandalone rewritten query

LLM Integration

The package intentionally does not depend on a specific LLM provider.

Your LLM only needs to expose an asynchronous:

await llm.ainvoke(prompt)

method that returns:

{
    "follow_up": bool,
    "follow_up_query": str
}

This allows the detector to be integrated with different AI/LLM implementations.

Development

Clone the repository:

git clone https://github.com/shripad-vaidya/ai-followup-detector.git
cd ai-followup-detector

Create and activate a virtual environment:

python -m venv .venv

Windows PowerShell:

.venv\Scripts\Activate.ps1

Install development dependencies:

python -m pip install -e ".[dev]"

Run tests:

python -m pytest -v

Run linting:

ruff check .

Optional LangChain Support

LangChain support can be installed with:

pip install "ai-followup-detector[langchain]"

License

This project is licensed under the MIT License.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.1.16 Oct 20266

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
shripad-vaidya/ai-followup-detector

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 10:43 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:df5058e85d6fdce593afae4a5749e154ad0a9259dbe5b10732c8a116eb6a488d