Skip to main content

Distance From Purpose

The distanceFromPurpose operation is an analytical tool designed to measure how much a conversation has drifted from a predefined objective or topic. It is particularly useful for maintaining focus in goal-oriented dialogues, such as customer support chats, automated assistants, or guided sales interactions.

This operation is non-transformative, meaning it only analyzes the content without modifying it.

Overview

The Distance From Purpose operation provides multi-layered analysis to detect conversation drift:

  • Goal-Oriented Chatbots: Ensure that a chatbot remains on track with its designated task (e.g., booking an appointment, answering product questions).
  • Customer Support Quality: Monitor support conversations to see if they are staying on topic and efficiently addressing customer issues.
  • Content Moderation: Identify when conversations are becoming tangential or unproductive.
  • Sales Conversation Management: Keep sales interactions focused on the intended outcome.

The operation analyzes recent conversation messages against a defined purpose statement and returns a drift score with recommended actions.

Configuration

The operation can be configured with the following parameters:

ParameterTypeDefaultDescription
purposeStatementstringRequiredA clear, concise statement describing the ideal focus of the conversation.
analysisMethod'semantic', 'keyword', 'hybrid''hybrid'The method used for analysis. 'semantic' uses meaning, 'keyword' uses specific terms, and 'hybrid' uses both.
windowSizenumber5The number of recent messages to include in the analysis.

Analysis Methods

  • semantic - Uses AI-powered semantic analysis to understand meaning and context
  • keyword - Fast pattern-based detection using specific terms and phrases
  • hybrid - Combines both semantic and keyword analysis for comprehensive coverage

Result Format

The result of the operation provides a score and a recommended action:

FieldTypeDescription
overallDistancenumber (0-1)A score indicating how far the conversation has drifted from the purpose. 0 means on-topic, 1 means off-topic.
confidencenumber (0-1)The confidence level of the analysis.
recommendedAction'continue', 'clarify', 'redirect'A suggested next step. 'continue' if on-topic, 'clarify' for slight drift, 'redirect' for major drift.

Example Configuration

{
"name": "distanceFromPurpose",
"config": {
"purposeStatement": "The user wants to book a flight from New York to London for next week.",
"analysisMethod": "hybrid",
"windowSize": 5
}
}

Examples

curl -X POST https://api.meta-prompt.com/v1/process \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"messages": [
{"role": "user", "content": "I want to book a flight."},
{"role": "assistant", "content": "Sure, where would you like to go?"},
{"role": "user", "content": "I was thinking about the weather in Paris."}
],
"operations": [
{
"name": "distanceFromPurpose",
"config": {
"purposeStatement": "The user wants to book a flight.",
"analysisMethod": "hybrid",
"windowSize": 3
}
}
]
}'

Response:

{
"messages": [
{"role": "user", "content": "I want to book a flight."},
{"role": "assistant", "content": "Sure, where would you like to go?"},
{"role": "user", "content": "I was thinking about the weather in Paris."}
],
"operations": [
{
"name": "distanceFromPurpose",
"result": {
"overallDistance": 0.75,
"confidence": 0.88,
"recommendedAction": "redirect"
}
}
]
}