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:
| Parameter | Type | Default | Description |
|---|---|---|---|
purposeStatement | string | Required | A 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. |
windowSize | number | 5 | The number of recent messages to include in the analysis. |
Analysis Methods
semantic- Uses AI-powered semantic analysis to understand meaning and contextkeyword- Fast pattern-based detection using specific terms and phraseshybrid- Combines both semantic and keyword analysis for comprehensive coverage
Result Format
The result of the operation provides a score and a recommended action:
| Field | Type | Description |
|---|---|---|
overallDistance | number (0-1) | A score indicating how far the conversation has drifted from the purpose. 0 means on-topic, 1 means off-topic. |
confidence | number (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
- REST API
- JavaScript SDK
- Python
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"
}
}
]
}
import { MetaPrompt } from '@meta-prompt/sdk-js';
const client = new MetaPrompt('YOUR_API_KEY');
const result = await client.process(
[
{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.'}
],
[
{
name: 'distanceFromPurpose',
config: {
purposeStatement: 'The user wants to book a flight.',
analysisMethod: 'hybrid',
windowSize: 3
}
}
]
);
console.log(result.operations[0].result);
// Output:
// {
// overallDistance: 0.75,
// confidence: 0.88,
// recommendedAction: "redirect"
// }
// Example with on-topic conversation
const onTopicResult = await client.process(
[
{role: 'user', content: 'I need to book a flight to London.'},
{role: 'assistant', content: 'What dates are you looking at?'},
{role: 'user', content: 'Next Tuesday through Friday.'}
],
[
{
name: 'distanceFromPurpose',
config: {
purposeStatement: 'The user wants to book a flight to London.',
analysisMethod: 'semantic'
}
}
]
);
console.log(onTopicResult.operations[0].result);
// Output:
// {
// overallDistance: 0.1,
// confidence: 0.95,
// recommendedAction: "continue"
// }