File size: 2,670 Bytes
310260a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
Chat API Schemas

Request and response models for the chat endpoint.
"""

from pydantic import BaseModel, Field, field_validator
from typing import Optional, List, Dict, Any
from datetime import datetime


class ChatRequest(BaseModel):
    """Request model for chat endpoint."""

    message: str = Field(
        ...,
        min_length=1,
        max_length=2000,
        description="User's natural language message"
    )
    conversation_id: Optional[int] = Field(
        default=None,
        description="Existing conversation ID to continue (omit for new conversation)"
    )

    @field_validator('message')
    @classmethod
    def validate_message(cls, v: str) -> str:
        """Validate message is not empty or whitespace-only."""
        if not v or v.strip() == "":
            raise ValueError("Message cannot be empty or whitespace-only")
        return v.strip()


class ToolCallResult(BaseModel):
    """Tool call result metadata."""

    tool: str = Field(..., description="Tool name")
    parameters: Dict[str, Any] = Field(..., description="Tool parameters")
    result: Dict[str, Any] = Field(..., description="Tool execution result")
    duration_ms: Optional[int] = Field(None, description="Execution time in milliseconds")


class ChatResponse(BaseModel):
    """Response model for chat endpoint."""

    conversation_id: int = Field(..., description="Conversation identifier")
    message_id: int = Field(..., description="Assistant message ID")
    assistant_message: str = Field(..., description="Natural language response from agent")
    tool_calls: Optional[List[ToolCallResult]] = Field(
        default=None,
        description="List of MCP tool invocations (empty if no tools used)"
    )
    timestamp: datetime = Field(..., description="Response generation timestamp")

    class Config:
        json_schema_extra = {
            "example": {
                "conversation_id": 456,
                "message_id": 789,
                "assistant_message": "I've added 'Buy groceries tomorrow' to your tasks. Task created successfully!",
                "tool_calls": [
                    {
                        "tool": "create_task",
                        "parameters": {
                            "title": "Buy groceries tomorrow",
                            "description": ""
                        },
                        "result": {
                            "task_id": 101,
                            "status": "success"
                        },
                        "duration_ms": 45
                    }
                ],
                "timestamp": "2026-02-03T10:30:00Z"
            }
        }