PM-034 Conversational AI API Documentation

Project: PM-034 Conversational AI Date: August 8, 2025 Status: ✅ Phase 3 Complete - API Documentation

Overview

The PM-034 Conversational AI API provides advanced conversation context management with anaphoric reference resolution. This API enables users to have natural, context-aware conversations where references like “that issue”, “the document”, and “show me the first item” are automatically resolved using a 10-turn context window and <150ms latency.

Base URL

/api/v1/conversation

Authentication

All endpoints require authentication. Include your API key in the request headers:

Authorization: Bearer YOUR_API_KEY

Response Format

All API responses follow a consistent JSON format:

{
  "data": {
    // Response data
  },
  "meta": {
    "timestamp": "2025-08-08T20:25:00Z",
    "request_id": "req_conv_123456789",
    "conversation_context": {
      "resolved_references": [],
      "context_window_size": 10,
      "performance_ms": 25.3
    }
  }
}

Error Handling

The API uses standard HTTP status codes and returns error details in the response body:

{
  "error": {
    "code": "CONVERSATION_ERROR",
    "message": "Unable to resolve reference",
    "details": {
      "reference": "that issue",
      "reason": "No previous issue mentions in conversation"
    }
  }
}

Conversation Management Endpoints

Process Conversational Message

POST /api/v1/conversation/message

Process a natural language message with conversation context and anaphoric reference resolution.

Request Body:

{
  "message": "Show me that issue again",
  "session_id": "conv_session_123",
  "user_context": {
    "user_id": "user_456",
    "project_context": ["project_789"]
  },
  "conversation_settings": {
    "context_window": 10,
    "reference_resolution": true,
    "performance_mode": "balanced"
  }
}

Response:

{
  "message": "Here are the details for GitHub issue #85",
  "intent": {
    "category": "QUERY",
    "action": "show_issue_details",
    "confidence": 0.95,
    "original_message": "Show me that issue again",
    "resolved_message": "Show me GitHub issue #85 again"
  },
  "conversation_context": {
    "original_message": "Show me that issue again",
    "resolved_message": "Show me GitHub issue #85 again",
    "resolved_references": [
      {
        "original": "that issue",
        "resolved": "GitHub issue #85",
        "type": "definite_reference",
        "confidence": 0.98,
        "source_turn": 2
      }
    ],
    "context_window_size": 10,
    "performance_ms": 23.7
  },
  "workflow_id": "wf_query_456",
  "requires_clarification": false
}

Validation Rules:

Get Conversation Context

GET /api/v1/conversation/{session_id}/context

Retrieve the current conversation context with turn history and resolved references.

Query Parameters:

Example Request:

GET /api/v1/conversation/conv_session_123/context?window_size=5&include_entities=true

Response:

{
  "conversation_id": "conv_session_123",
  "created_at": "2025-08-08T19:30:00Z",
  "updated_at": "2025-08-08T20:25:00Z",
  "turns": [
    {
      "turn_number": 1,
      "user_message": "Create GitHub issue for login bug",
      "assistant_response": "I created GitHub issue #85 for the login bug. The issue has been assigned to the development team.",
      "entities": ["#85", "login bug", "development team"],
      "timestamp": "2025-08-08T19:35:00Z",
      "resolved_references": []
    },
    {
      "turn_number": 2,
      "user_message": "Show me that issue again",
      "assistant_response": "Here are the details for GitHub issue #85",
      "entities": ["#85"],
      "timestamp": "2025-08-08T20:25:00Z",
      "resolved_references": [
        {
          "original": "that issue",
          "resolved": "GitHub issue #85",
          "confidence": 0.98
        }
      ]
    }
  ],
  "context_window_size": 10,
  "total_turns": 2,
  "metadata": {
    "user_id": "user_456",
    "project_context": ["project_789"]
  }
}

Update Conversation Settings

PUT /api/v1/conversation/{session_id}/settings

Update conversation behavior and performance settings.

Request Body:

{
  "context_window": 15,
  "reference_resolution": true,
  "performance_mode": "high_accuracy",
  "cache_ttl": 300,
  "entity_extraction": true
}

Response:

{
  "conversation_id": "conv_session_123",
  "settings": {
    "context_window": 15,
    "reference_resolution": true,
    "performance_mode": "high_accuracy",
    "cache_ttl": 300,
    "entity_extraction": true
  },
  "updated_at": "2025-08-08T20:25:00Z"
}

Validation Rules:

Get Reference Resolution History

GET /api/v1/conversation/{session_id}/references

Retrieve the history of resolved anaphoric references for analysis and debugging.

Query Parameters:

Example Request:

GET /api/v1/conversation/conv_session_123/references?limit=10&confidence_threshold=0.8

Response:

{
  "conversation_id": "conv_session_123",
  "references": [
    {
      "turn_number": 2,
      "original_text": "that issue",
      "resolved_entity": "GitHub issue #85",
      "reference_type": "definite_reference",
      "confidence": 0.98,
      "resolution_time_ms": 15.3,
      "context_used": ["turn_1"],
      "timestamp": "2025-08-08T20:25:00Z"
    },
    {
      "turn_number": 4,
      "original_text": "the first item",
      "resolved_entity": "GitHub issue #85",
      "reference_type": "definite_reference",
      "confidence": 0.92,
      "resolution_time_ms": 12.7,
      "context_used": ["turn_1", "turn_2"],
      "timestamp": "2025-08-08T20:30:00Z"
    }
  ],
  "total_references": 2,
  "average_confidence": 0.95,
  "average_resolution_time_ms": 14.0
}

Resolve References (Batch)

POST /api/v1/conversation/resolve-references

Batch resolve multiple anaphoric references for testing and analysis.

Request Body:

{
  "session_id": "conv_session_123",
  "messages": [
    "Show me that issue",
    "Update the first document",
    "Close the login bug"
  ],
  "resolution_options": {
    "context_window": 10,
    "confidence_threshold": 0.8,
    "include_alternatives": true
  }
}

Response:

{
  "session_id": "conv_session_123",
  "resolutions": [
    {
      "original_message": "Show me that issue",
      "resolved_message": "Show me GitHub issue #85",
      "references": [
        {
          "original": "that issue",
          "resolved": "GitHub issue #85",
          "confidence": 0.98,
          "alternatives": [
            {"entity": "GitHub issue #86", "confidence": 0.23}
          ]
        }
      ],
      "resolution_time_ms": 18.5
    },
    {
      "original_message": "Update the first document",
      "resolved_message": "Update requirements_v2.pdf",
      "references": [
        {
          "original": "the first document",
          "resolved": "requirements_v2.pdf",
          "confidence": 0.89,
          "alternatives": []
        }
      ],
      "resolution_time_ms": 22.1
    }
  ],
  "batch_performance": {
    "total_time_ms": 45.2,
    "average_time_ms": 22.6,
    "success_rate": 1.0
  }
}

QueryRouter Integration Patterns

Conversation-Aware Query Routing

The QueryRouter automatically integrates with ConversationManager when a session_id is provided:

Integration Example:

from services.queries import QueryRouter
from services.conversation.conversation_manager import ConversationManager

# Initialize conversation-aware routing
router = QueryRouter(
    project_query_service=project_queries,
    conversation_query_service=conversation_queries,
    file_query_service=file_queries
)

conversation_manager = ConversationManager(
    redis_client=redis_client,
    context_window_size=10
)

# Process message with conversation context
result = await router.classify_and_route(
    message="Show me that issue again",
    session_id="conv_session_123",
    conversation_manager=conversation_manager
)

# Result includes conversation context
print(result["conversation_context"]["resolved_message"])
# Output: "Show me GitHub issue #85 again"

Anaphoric Reference Parameters

All conversation endpoints support these anaphoric reference parameters:

Reference Types Supported:

Resolution Algorithm Parameters:

{
  "reference_resolution": {
    "enabled": true,
    "confidence_threshold": 0.8,
    "context_window": 10,
    "resolution_strategies": [
      "recency_weighted",
      "entity_matching",
      "semantic_similarity"
    ],
    "fallback_behavior": "preserve_original"
  }
}

Performance Configuration:

{
  "performance": {
    "target_latency_ms": 150,
    "cache_ttl_seconds": 300,
    "circuit_breaker": {
      "failure_threshold": 5,
      "recovery_timeout": 30
    }
  }
}

Usage Examples

Basic Conversational Interaction

import requests

# Start a conversation
conversation_data = {
    "message": "Create a GitHub issue for the login bug",
    "session_id": "my_session_123",
    "user_context": {"user_id": "developer_1"}
}

response = requests.post(
    "https://api.example.com/api/v1/conversation/message",
    json=conversation_data,
    headers={"Authorization": "Bearer YOUR_API_KEY"}
)

result = response.json()
print(f"Created: {result['intent']['action']}")

# Follow up with anaphoric reference
followup_data = {
    "message": "Show me that issue again",
    "session_id": "my_session_123"
}

response = requests.post(
    "https://api.example.com/api/v1/conversation/message",
    json=followup_data,
    headers={"Authorization": "Bearer YOUR_API_KEY"}
)

result = response.json()
print(f"Resolved: {result['conversation_context']['resolved_message']}")
# Output: "Show me GitHub issue #85 again"

Context Window Management

# Get current conversation context
response = requests.get(
    "https://api.example.com/api/v1/conversation/my_session_123/context",
    params={"window_size": 5, "include_entities": True},
    headers={"Authorization": "Bearer YOUR_API_KEY"}
)

context = response.json()
print(f"Context has {len(context['turns'])} turns")

# Update conversation settings
settings_data = {
    "context_window": 15,
    "performance_mode": "high_accuracy"
}

response = requests.put(
    "https://api.example.com/api/v1/conversation/my_session_123/settings",
    json=settings_data,
    headers={"Authorization": "Bearer YOUR_API_KEY"}
)

print("Settings updated successfully")

Reference Resolution Analysis

# Get reference resolution history
response = requests.get(
    "https://api.example.com/api/v1/conversation/my_session_123/references",
    params={"confidence_threshold": 0.9, "limit": 10},
    headers={"Authorization": "Bearer YOUR_API_KEY"}
)

references = response.json()
for ref in references["references"]:
    print(f"'{ref['original_text']}' → '{ref['resolved_entity']}' ({ref['confidence']:.2f})")

# Batch resolve for testing
batch_data = {
    "session_id": "my_session_123",
    "messages": [
        "Update that issue",
        "Close the bug",
        "Show me the document"
    ]
}

response = requests.post(
    "https://api.example.com/api/v1/conversation/resolve-references",
    json=batch_data,
    headers={"Authorization": "Bearer YOUR_API_KEY"}
)

batch_results = response.json()
print(f"Batch resolution completed in {batch_results['batch_performance']['total_time_ms']}ms")

Advanced QueryRouter Integration

# Using conversation-aware query routing with custom configuration
from services.queries import QueryRouter
from services.conversation.conversation_manager import ConversationManager

# Configure conversation manager
conversation_manager = ConversationManager(
    redis_client=redis_client,
    context_window_size=15,
    cache_ttl=600
)

# Configure query router
router = QueryRouter(
    project_query_service=project_queries,
    conversation_query_service=conversation_queries,
    file_query_service=file_queries,
    enable_llm_classification=True
)

# Process conversational query
result = await router.classify_and_route(
    message="What's the status of that sprint task?",
    session_id="sprint_session_456",
    conversation_manager=conversation_manager,
    user_context={
        "team_id": "team_alpha",
        "project_id": "proj_123"
    }
)

# Access resolved conversation context
if "conversation_context" in result:
    ctx = result["conversation_context"]
    print(f"Original: {ctx['original_message']}")
    print(f"Resolved: {ctx['resolved_message']}")
    print(f"References: {len(ctx['resolved_references'])}")
    print(f"Performance: {ctx['performance_ms']}ms")

Error Codes

Code Description
CONVERSATION_ERROR General conversation processing error
REFERENCE_RESOLUTION_FAILED Unable to resolve anaphoric reference
CONTEXT_WINDOW_EXCEEDED Requested window size too large
SESSION_NOT_FOUND Conversation session does not exist
CACHE_UNAVAILABLE Redis cache temporarily unavailable
PERFORMANCE_DEGRADED Performance targets not met, circuit breaker active

Performance Targets

Rate Limiting

Rate limit headers are included in responses:

X-RateLimit-Limit: 500
X-RateLimit-Remaining: 499
X-RateLimit-Reset: 1640995200
X-Conversation-Context-Window: 10
X-Performance-Target-MS: 150

Integration Notes

ConversationManager Architecture

QueryRouter Integration

Performance Considerations

SDK Support

Official SDKs with conversation support available for:

See the Conversation SDK Documentation for detailed usage examples.

Support

For Conversational AI API support: