מודל נתונים
סכמת ה-Database - 6 טבלאות SQLAlchemy
Entity Relationship Diagram
┌─────────────────────────┐ ┌─────────────────────────┐
│ MCPSystemPrompt │ │ MCPFunction │
├─────────────────────────┤ ├─────────────────────────┤
│ PK id │ │ PK id │
│ name │ │ name │
│ display_name │ │ display_name │
│ base_prompt │ │ category │
│ personality │ │ description │
│ customer_instructions│ │ parameters (JSON) │
│ invoice_instructions │ │ is_active │
│ repair_instructions │ └─────────────────────────┘
│ inventory_instructions│
│ temperature │ ┌─────────────────────────┐
│ max_tokens │ │ MCPKnowledgeBase │
│ is_default │ ├─────────────────────────┤
└───────────┬─────────────┘ │ PK id │
│ │ category │
│ 1 │ subcategory │
│ │ title │
▼ N │ content │
┌─────────────────────────┐ │ keywords (JSON) │
│ MCPConversation │ │ related_modules(JSON)│
├─────────────────────────┤ │ priority │
│ PK id │ └─────────────────────────┘
│ uuid │
│ FK user_id │───────────────────────────────────┐
│ FK prompt_id │ │
│ FK customer_id │───────▶ customers │
│ FK invoice_id │───────▶ invoices │
│ FK repair_id │───────▶ repairs │
│ primary_context_type │ │
│ primary_context_id │ ┌─────────────────────────┐ │
│ title │ │ MCPActionLog │ │
│ status │ ├─────────────────────────┤ │
│ current_intent │ │ PK id │ │
│ context_memory (JSON)│ │ FK conversation_id │◀┘
│ extracted_entities │ │ FK message_id │
│ message_count │ │ FK user_id │
│ total_tokens │ │ action_type │
└───────────┬─────────────┘ │ function_name │
│ │ target_module │
│ 1 │ target_id │
│ │ request_data (JSON) │
▼ N │ response_data (JSON) │
┌─────────────────────────┐ │ status │
│ MCPMessage │ │ error_message │
├─────────────────────────┤ └─────────────────────────┘
│ PK id │
│ FK conversation_id │
│ role │
│ content │
│ function_name │
│ function_args (JSON) │
│ function_result(JSON)│
│ detected_intent │
│ detected_entities │
│ context_type │
│ total_tokens │
│ response_time_ms │
│ status │
└─────────────────────────┘
טבלאות מפורטות
MCPSystemPrompt
mcp_system_prompts
פרומפטים מערכת מתקדמים עם הנחיות מודולריות
| שדה | סוג | תיאור |
|---|---|---|
| id | Integer | Primary Key |
| name | String(100) | שם ייחודי (באנגלית) |
| display_name | String(200) | שם תצוגה (בעברית) |
| version | String(20) | גרסה (1.0.0) |
| base_prompt | Text | הפרומפט הבסיסי |
| personality | Text | אישיות הבוט |
| customer_instructions | Text | הנחיות לטיפול בלקוחות |
| invoice_instructions | Text | הנחיות לטיפול בחשבוניות |
| repair_instructions | Text | הנחיות לטיפול בתיקונים |
| inventory_instructions | Text | הנחיות לטיפול במלאי |
| response_style | Text | סגנון תשובות |
| temperature | Numeric(3,2) | Temperature (0.0-2.0) |
| max_tokens | Integer | מקסימום טוקנים |
| is_active | Boolean | האם פעיל |
| is_default | Boolean | האם ברירת מחדל |
| created_at | DateTime | תאריך יצירה |
MCPConversation
mcp_conversations
שיחות עם הקשר מודולרי - קישור ללקוח/חשבונית/תיקון
| שדה | סוג | תיאור |
|---|---|---|
| id | Integer | Primary Key |
| uuid | String(36) | UUID ייחודי |
| user_id FK | Integer | משתמש (users.id) |
| prompt_id FK | Integer | פרומפט (mcp_system_prompts.id) |
| customer_id FK | Integer | לקוח מקושר (customers.id) |
| invoice_id FK | Integer | חשבונית מקושרת (invoices.id) |
| repair_id FK | Integer | תיקון מקושר (repairs.id) |
| primary_context_type | String(50) | סוג הקשר: customer, invoice, repair |
| primary_context_id | Integer | ID של הישות הראשית |
| title | String(255) | כותרת השיחה |
| status | String(20) | סטטוס: active, archived |
| current_intent | String(50) | הכוונה הנוכחית |
| context_memory | JSON | זיכרון הקשר (ישויות, עובדות) |
| extracted_entities | JSON | ישויות שחולצו |
| actions_taken | JSON | פעולות שבוצעו |
| message_count | Integer | מספר הודעות |
| total_tokens | Integer | סה"כ טוקנים |
| last_message_at | DateTime | תאריך הודעה אחרונה |
MCPMessage
mcp_messages
הודעות עם מידע על Function Calling וזיהוי כוונות
| שדה | סוג | תיאור |
|---|---|---|
| id | Integer | Primary Key |
| conversation_id FK | Integer | שיחה (mcp_conversations.id) |
| role | String(20) | תפקיד: user, assistant, system, function |
| content | Text | תוכן ההודעה |
| function_name | String(100) | שם הפונקציה שנקראה |
| function_args | JSON | ארגומנטים לפונקציה |
| function_result | JSON | תוצאת הפונקציה |
| detected_intent | String(50) | כוונה שזוהתה |
| detected_entities | JSON | ישויות שזוהו |
| context_type | String(50) | סוג הקשר |
| input_tokens | Integer | טוקנים בקלט |
| output_tokens | Integer | טוקנים בפלט |
| total_tokens | Integer | סה"כ טוקנים |
| response_time_ms | Integer | זמן תגובה (ms) |
| status | String(20) | סטטוס: pending, completed, error |
| error_message | Text | הודעת שגיאה (אם יש) |
MCPFunction
mcp_functions
הגדרות פונקציות בפורמט OpenAI Function Calling
| שדה | סוג | תיאור |
|---|---|---|
| id | Integer | Primary Key |
| name | String(100) | שם הפונקציה (ייחודי) |
| display_name | String(200) | שם תצוגה |
| category | String(50) | קטגוריה: customer, invoice, repair, inventory, analytics |
| description | Text | תיאור הפונקציה |
| parameters | JSON | JSON Schema לפרמטרים |
| handler_module | String(200) | מודול ה-handler |
| handler_function | String(100) | שם פונקציית ה-handler |
| is_active | Boolean | האם פעילה |
| is_dangerous | Boolean | האם דורשת אישור |
| example_calls | JSON | דוגמאות לקריאות |
MCPActionLog
mcp_action_logs
לוג פעולות לביקורת - כל פעולה על המודולים נרשמת
| שדה | סוג | תיאור |
|---|---|---|
| id | Integer | Primary Key |
| conversation_id FK | Integer | שיחה |
| message_id FK | Integer | הודעה |
| user_id FK | Integer | משתמש |
| action_type | String(50) | סוג: query, create, update, summarize, analyze |
| function_name | String(100) | שם הפונקציה |
| target_module | String(50) | מודול יעד |
| target_id | Integer | ID של הרשומה המושפעת |
| request_data | JSON | נתוני הבקשה |
| response_data | JSON | נתוני התגובה |
| status | String(20) | סטטוס: success, failed, pending |
| error_message | Text | הודעת שגיאה |
| ip_address | String(50) | כתובת IP |
| created_at | DateTime | תאריך הפעולה |
MCPKnowledgeBase
mcp_knowledge_base
בסיס ידע - FAQ, מדיניות, נהלים ומוצרים
| שדה | סוג | תיאור |
|---|---|---|
| id | Integer | Primary Key |
| category | String(50) | קטגוריה: faq, policy, procedure, product |
| subcategory | String(50) | תת-קטגוריה |
| title | String(255) | כותרת |
| content | Text | תוכן |
| keywords | JSON | מילות מפתח לחיפוש |
| related_modules | JSON | מודולים קשורים |
| is_active | Boolean | האם פעיל |
| priority | Integer | עדיפות (גבוה יותר = חשוב יותר) |
| created_at | DateTime | תאריך יצירה |
| updated_at | DateTime | תאריך עדכון |
דוגמת קוד SQLAlchemy
from app import db
from app.models_mcp_chatbot import MCPConversation, MCPMessage
# יצירת שיחה חדשה
conversation = MCPConversation(
uuid='550e8400-e29b-41d4-a716-446655440000',
user_id=1,
title='שיחה חדשה',
customer_id=123,
primary_context_type='customer',
context_memory={'phone': ['0501234567']},
extracted_entities=[{'type': 'phone', 'value': '0501234567'}]
)
db.session.add(conversation)
db.session.commit()
# הוספת הודעה
message = MCPMessage(
conversation_id=conversation.id,
role='user',
content='מה היתרה של 050-1234567?',
detected_intent='customer_balance',
detected_entities=[{'type': 'phone', 'value': '0501234567'}]
)
db.session.add(message)
db.session.commit()
# שליפת שיחות עם הקשר ללקוח
conversations = MCPConversation.query.filter(
MCPConversation.customer_id == 123
).order_by(MCPConversation.last_message_at.desc()).all()
# שליפת הודעות של שיחה
messages = conversation.messages.all()