Observed since 21 Oct, 10:43 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Detect and rewrite follow-up queries for AI applications
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.
ainvoke() methodpip install ai-followup-detector
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"
}
The detector receives:
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
FollowUpDetectorFollowUpDetector(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"
)
FollowUpResultfrom ai_followup_detector import FollowUpResult
The result contains:
| Field | Type | Description |
|---|---|---|
follow_up | bool | Whether the current message is a follow-up |
follow_up_query | str | Standalone rewritten query |
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.
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 .
LangChain support can be installed with:
pip install "ai-followup-detector[langchain]"
This project is licensed under the MIT License.
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.1.1 | 6 Oct 2026 | 6 |
This describes our collected data; it is not a security assessment.
Shared repository data · GitHub
Observed since 21 Oct, 10:43 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:df5058e85d6fdce593afae4a5749e154ad0a9259dbe5b10732c8a116eb6a488d