letschatty 0.4.332__py3-none-any.whl → 0.4.333__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- letschatty/models/ai_microservices/__init__.py +3 -3
- letschatty/models/ai_microservices/expected_output.py +36 -1
- letschatty/models/ai_microservices/lambda_events.py +142 -27
- letschatty/models/ai_microservices/lambda_invokation_types.py +3 -1
- letschatty/models/ai_microservices/n8n_ai_agents_payload.py +3 -1
- letschatty/models/analytics/events/__init__.py +2 -1
- letschatty/models/analytics/events/chat_based_events/ai_agent_execution_event.py +71 -0
- letschatty/models/analytics/events/company_based_events/asset_events.py +0 -3
- letschatty/models/analytics/events/event_type_to_classes.py +0 -4
- letschatty/models/analytics/events/event_types.py +45 -0
- letschatty/models/chat/continuous_conversation.py +1 -1
- letschatty/models/company/assets/ai_agents_v2/ai_agents_decision_output.py +1 -1
- letschatty/models/company/assets/ai_agents_v2/chatty_ai_agent.py +7 -1
- letschatty/models/company/assets/ai_agents_v2/chatty_ai_agent_in_chat.py +4 -1
- letschatty/models/company/assets/ai_agents_v2/chatty_ai_mode.py +2 -2
- letschatty/models/company/assets/ai_agents_v2/get_chat_with_prompt_response.py +1 -0
- letschatty/models/company/assets/ai_agents_v2/pre_qualify_config.py +14 -2
- letschatty/models/company/assets/automation.py +18 -0
- letschatty/models/data_base/collection_interface.py +101 -29
- letschatty/models/data_base/mongo_connection.py +92 -9
- letschatty/models/utils/custom_exceptions/custom_exceptions.py +38 -1
- letschatty/services/ai_agents/smart_follow_up_context_builder_v2.py +5 -2
- letschatty/services/chatty_assets/__init__.py +12 -0
- letschatty/services/chatty_assets/asset_service.py +190 -13
- letschatty/services/chatty_assets/assets_collections.py +137 -0
- letschatty/services/chatty_assets/base_container.py +3 -2
- letschatty/services/chatty_assets/base_container_with_collection.py +35 -26
- letschatty/services/chatty_assets/collections/__init__.py +38 -0
- letschatty/services/chatty_assets/collections/ai_agent_collection.py +19 -0
- letschatty/services/chatty_assets/collections/ai_agent_in_chat_collection.py +32 -0
- letschatty/services/chatty_assets/collections/ai_component_collection.py +21 -0
- letschatty/services/chatty_assets/collections/chain_of_thought_collection.py +30 -0
- letschatty/services/chatty_assets/collections/chat_collection.py +21 -0
- letschatty/services/chatty_assets/collections/contact_point_collection.py +21 -0
- letschatty/services/chatty_assets/collections/fast_answer_collection.py +21 -0
- letschatty/services/chatty_assets/collections/filter_criteria_collection.py +18 -0
- letschatty/services/chatty_assets/collections/flow_collection.py +20 -0
- letschatty/services/chatty_assets/collections/product_collection.py +20 -0
- letschatty/services/chatty_assets/collections/sale_collection.py +20 -0
- letschatty/services/chatty_assets/collections/source_collection.py +21 -0
- letschatty/services/chatty_assets/collections/tag_collection.py +19 -0
- letschatty/services/chatty_assets/collections/topic_collection.py +21 -0
- letschatty/services/chatty_assets/collections/user_collection.py +20 -0
- letschatty/services/chatty_assets/example_usage.py +44 -0
- letschatty/services/chatty_assets/services/__init__.py +37 -0
- letschatty/services/chatty_assets/services/ai_agent_in_chat_service.py +73 -0
- letschatty/services/chatty_assets/services/ai_agent_service.py +23 -0
- letschatty/services/chatty_assets/services/chain_of_thought_service.py +70 -0
- letschatty/services/chatty_assets/services/chat_service.py +25 -0
- letschatty/services/chatty_assets/services/contact_point_service.py +29 -0
- letschatty/services/chatty_assets/services/fast_answer_service.py +32 -0
- letschatty/services/chatty_assets/services/filter_criteria_service.py +30 -0
- letschatty/services/chatty_assets/services/flow_service.py +25 -0
- letschatty/services/chatty_assets/services/product_service.py +30 -0
- letschatty/services/chatty_assets/services/sale_service.py +25 -0
- letschatty/services/chatty_assets/services/source_service.py +28 -0
- letschatty/services/chatty_assets/services/tag_service.py +32 -0
- letschatty/services/chatty_assets/services/topic_service.py +31 -0
- letschatty/services/chatty_assets/services/user_service.py +32 -0
- letschatty/services/continuous_conversation_service/continuous_conversation_helper.py +11 -0
- letschatty/services/events/__init__.py +6 -0
- letschatty/services/events/events_manager.py +218 -1
- letschatty/services/factories/analytics/ai_agent_event_factory.py +161 -0
- letschatty/services/factories/analytics/events_factory.py +63 -1
- letschatty/services/factories/lambda_ai_orchestrartor/lambda_events_factory.py +25 -8
- letschatty/services/messages_helpers/get_caption_or_body_or_preview.py +6 -4
- {letschatty-0.4.332.dist-info → letschatty-0.4.333.dist-info}/METADATA +1 -1
- {letschatty-0.4.332.dist-info → letschatty-0.4.333.dist-info}/RECORD +70 -34
- {letschatty-0.4.332.dist-info → letschatty-0.4.333.dist-info}/LICENSE +0 -0
- {letschatty-0.4.332.dist-info → letschatty-0.4.333.dist-info}/WHEEL +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
from .expected_output import ExpectedOutputQualityTest, ExpectedOutputSmartTag
|
|
2
2
|
from .lambda_events import (
|
|
3
|
-
|
|
4
|
-
QualityTestInteractionCallbackEvent,
|
|
5
|
-
AllQualityTestEvent,
|
|
3
|
+
IncomingMessageAIDecision, QualityTestCallbackEvent, SmartTaggingCallbackEvent,
|
|
4
|
+
QualityTestInteractionCallbackEvent, QualityTestEvent,
|
|
5
|
+
AllQualityTestEvent, SmartTaggingEvent, QualityTestEventData, AllQualityTestEventData,ChatData,
|
|
6
6
|
ComparisonAnalysisCallbackMetadata, InteractionCallbackMetadata, SmartTaggingCallbackMetadata,
|
|
7
7
|
SmartTaggingPromptEvent
|
|
8
8
|
)
|
|
@@ -6,9 +6,10 @@ from typing import List, Optional, Literal
|
|
|
6
6
|
from datetime import datetime
|
|
7
7
|
|
|
8
8
|
from letschatty.models.utils.types.message_types import MessageType
|
|
9
|
-
from ...models.company.assets.ai_agents_v2.ai_agents_decision_output import ChainOfThoughtInChatRequest, IncomingMessageAIDecision, IncomingMessageDecisionAction
|
|
9
|
+
from ...models.company.assets.ai_agents_v2.ai_agents_decision_output import ChainOfThoughtInChatRequest, IncomingMessageAIDecision, IncomingMessageDecisionAction, SmartFollowUpDecision, SmartFollowUpDecisionAction
|
|
10
10
|
from ...models.company.assets.automation import Automation
|
|
11
11
|
from ...models.company.form_field import CollectedData
|
|
12
|
+
from ...models.chat.chat import Area
|
|
12
13
|
|
|
13
14
|
class ExpectedOutputQualityTest(BaseModel):
|
|
14
15
|
accuracy: float = Field(description="The accuracy of the comparison analysis")
|
|
@@ -169,6 +170,12 @@ class ExpectedOutputIncomingMessage(BaseModel):
|
|
|
169
170
|
action: IncomingMessageDecisionAction
|
|
170
171
|
messages: List[str] = Field(description="Array of message strings to send to the customer. Required for send/suggest actions, optional for escalate action, empty array for skip/remove actions.")
|
|
171
172
|
chain_of_thought: ChainOfThoughtInChatRequest = Field(description="REQUIRED: Your reasoning process and response decision explanation")
|
|
173
|
+
confidence: Optional[int] = Field(
|
|
174
|
+
default=None,
|
|
175
|
+
ge=0,
|
|
176
|
+
le=100,
|
|
177
|
+
description="Confidence level 0-100"
|
|
178
|
+
)
|
|
172
179
|
|
|
173
180
|
def to_incoming_message_decision_output(self) -> IncomingMessageAIDecision:
|
|
174
181
|
messages_drafts = [
|
|
@@ -187,3 +194,31 @@ class ExpectedOutputIncomingMessage(BaseModel):
|
|
|
187
194
|
return incoming_decision
|
|
188
195
|
|
|
189
196
|
|
|
197
|
+
class ExpectedOutputSmartFollowUp(BaseModel):
|
|
198
|
+
action: SmartFollowUpDecisionAction
|
|
199
|
+
messages: List[str] = Field(description="Array of message strings to send to the customer. Required for send/suggest actions, optional for escalate action, empty array for skip/remove/postpone actions.")
|
|
200
|
+
chain_of_thought: ChainOfThoughtInChatRequest = Field(description="REQUIRED: Your reasoning process and response decision explanation")
|
|
201
|
+
next_call_time: Optional[datetime] = Field(default=None, description="The next call time for the smart follow up (required for postpone_delta_time action)")
|
|
202
|
+
reason: Optional[str] = Field(default=None, description="Reason for the decision (especially for postpone/postponed actions)")
|
|
203
|
+
area: Optional[Area] = Field(default=None, description="The area to move the chat after the decision")
|
|
204
|
+
|
|
205
|
+
def to_smart_follow_up_decision_output(self) -> SmartFollowUpDecision:
|
|
206
|
+
messages_drafts = [
|
|
207
|
+
MessageDraft(
|
|
208
|
+
type=MessageType.TEXT,
|
|
209
|
+
content=ChattyContentText(body=message),
|
|
210
|
+
is_incoming_message=False
|
|
211
|
+
)
|
|
212
|
+
for message in self.messages
|
|
213
|
+
]
|
|
214
|
+
smart_follow_up_decision = SmartFollowUpDecision(
|
|
215
|
+
action=self.action,
|
|
216
|
+
next_call_time=self.next_call_time,
|
|
217
|
+
messages=messages_drafts,
|
|
218
|
+
chain_of_thought=self.chain_of_thought,
|
|
219
|
+
reason=self.reason,
|
|
220
|
+
area=self.area
|
|
221
|
+
)
|
|
222
|
+
return smart_follow_up_decision
|
|
223
|
+
|
|
224
|
+
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
from letschatty.models.company.assets.ai_agents_v2.chatty_ai_agent_in_chat import HumanInterventionReason
|
|
1
2
|
from letschatty.models.company.assets.chat_assets import ChainOfThoughtInChatTrigger
|
|
2
3
|
from pydantic import BaseModel, Field, model_validator
|
|
3
|
-
from typing import Dict, Any, List, Optional
|
|
4
|
+
from typing import Dict, Any, List, Optional, TYPE_CHECKING
|
|
4
5
|
|
|
5
6
|
from letschatty.models.base_models.ai_agent_component import AiAgentComponentType
|
|
6
7
|
from letschatty.models.utils.types.identifier import StrObjectId
|
|
7
8
|
from .lambda_invokation_types import InvokationType, LambdaAiEvent
|
|
8
|
-
from .expected_output import ExpectedOutputIncomingMessage, ExpectedOutputSmartTag, ExpectedOutputQualityTest, IncomingMessageAIDecision
|
|
9
|
-
from ...models.company.assets.ai_agents_v2.ai_agents_decision_output import IncomingMessageDecisionAction
|
|
9
|
+
from .expected_output import ExpectedOutputIncomingMessage, ExpectedOutputSmartFollowUp, ExpectedOutputSmartTag, ExpectedOutputQualityTest, IncomingMessageAIDecision
|
|
10
|
+
from ...models.company.assets.ai_agents_v2.ai_agents_decision_output import IncomingMessageDecisionAction, SmartFollowUpDecision
|
|
10
11
|
|
|
11
12
|
class SmartTaggingCallbackMetadata(BaseModel):
|
|
12
13
|
chat_id: StrObjectId
|
|
13
14
|
company_id: StrObjectId
|
|
15
|
+
trigger: ChainOfThoughtInChatTrigger
|
|
14
16
|
|
|
15
17
|
class ComparisonAnalysisCallbackMetadata(BaseModel):
|
|
16
18
|
test_case_id: StrObjectId
|
|
@@ -22,21 +24,8 @@ class InteractionCallbackMetadata(BaseModel):
|
|
|
22
24
|
ai_agent_id: StrObjectId
|
|
23
25
|
company_id: StrObjectId
|
|
24
26
|
interaction_index: int
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
chat_id: StrObjectId
|
|
28
|
-
company_id: StrObjectId
|
|
29
|
-
ai_agent_id: StrObjectId
|
|
30
|
-
cot_id: StrObjectId
|
|
31
|
-
trigger: str
|
|
32
|
-
# Trigger info is in: incoming_message_ids for user_message,
|
|
33
|
-
# triggered_by_user_id for manual_trigger, smart_follow_up_id for follow_up
|
|
34
|
-
triggered_by_user_id: Optional[StrObjectId] = None
|
|
35
|
-
|
|
36
|
-
class IncomingMessageCallbackEvent(LambdaAiEvent):
|
|
37
|
-
type: InvokationType = InvokationType.INCOMING_MESSAGE_CALLBACK
|
|
38
|
-
data: IncomingMessageAIDecision
|
|
39
|
-
callback_metadata: IncomingMessageCallbackMetadata
|
|
27
|
+
trigger: ChainOfThoughtInChatTrigger
|
|
28
|
+
chain_of_thought_id: StrObjectId
|
|
40
29
|
|
|
41
30
|
class QualityTestCallbackEvent(LambdaAiEvent):
|
|
42
31
|
type: InvokationType = InvokationType.SINGLE_QUALITY_TEST_CALLBACK
|
|
@@ -54,6 +43,50 @@ class QualityTestInteractionCallbackEvent(LambdaAiEvent):
|
|
|
54
43
|
data["data"]["chain_of_thought"]["chatty_ai_agent_id"] = data["callback_metadata"]["ai_agent_id"]
|
|
55
44
|
return data
|
|
56
45
|
|
|
46
|
+
@model_validator(mode="before")
|
|
47
|
+
@classmethod
|
|
48
|
+
def set_chain_of_thought_id(cls, values: Dict[str, Any]):
|
|
49
|
+
"""
|
|
50
|
+
Get the chain_of_thought_id from callback_metadata and set it in data.chain_of_thought.id
|
|
51
|
+
|
|
52
|
+
Handles both cases:
|
|
53
|
+
- data is a JSON string (needs parsing)
|
|
54
|
+
- data is already a dict
|
|
55
|
+
"""
|
|
56
|
+
import json
|
|
57
|
+
|
|
58
|
+
data = values.get("data")
|
|
59
|
+
callback_metadata = values.get("callback_metadata")
|
|
60
|
+
|
|
61
|
+
if not data or not callback_metadata:
|
|
62
|
+
return values
|
|
63
|
+
|
|
64
|
+
# Get chain_of_thought_id from callback_metadata (could be dict or object)
|
|
65
|
+
if isinstance(callback_metadata, dict):
|
|
66
|
+
chain_of_thought_id = callback_metadata.get("chain_of_thought_id")
|
|
67
|
+
else:
|
|
68
|
+
chain_of_thought_id = getattr(callback_metadata, "chain_of_thought_id", None)
|
|
69
|
+
|
|
70
|
+
if not chain_of_thought_id:
|
|
71
|
+
return values
|
|
72
|
+
|
|
73
|
+
# Parse data if it's a JSON string
|
|
74
|
+
if isinstance(data, str):
|
|
75
|
+
try:
|
|
76
|
+
data = json.loads(data)
|
|
77
|
+
values["data"] = data
|
|
78
|
+
except (json.JSONDecodeError, TypeError):
|
|
79
|
+
return values
|
|
80
|
+
|
|
81
|
+
# If data is a dict, set the id in chain_of_thought
|
|
82
|
+
if isinstance(data, dict):
|
|
83
|
+
chain_of_thought = data.get("chain_of_thought")
|
|
84
|
+
if isinstance(chain_of_thought, dict):
|
|
85
|
+
chain_of_thought["id"] = chain_of_thought_id
|
|
86
|
+
|
|
87
|
+
return values
|
|
88
|
+
|
|
89
|
+
|
|
57
90
|
class SmartTaggingCallbackEvent(LambdaAiEvent):
|
|
58
91
|
type: InvokationType = InvokationType.SMART_TAGGING_CALLBACK
|
|
59
92
|
data: ExpectedOutputSmartTag
|
|
@@ -77,6 +110,11 @@ class FollowUpEvent(LambdaAiEvent):
|
|
|
77
110
|
type: InvokationType = InvokationType.FOLLOW_UP
|
|
78
111
|
data: ChatData
|
|
79
112
|
|
|
113
|
+
|
|
114
|
+
class SmartFollowUpDecisionOutputEvent(LambdaAiEvent):
|
|
115
|
+
type: InvokationType = InvokationType.FOLLOW_UP
|
|
116
|
+
data: ExpectedOutputSmartFollowUp
|
|
117
|
+
|
|
80
118
|
class QualityTestEventData(BaseModel):
|
|
81
119
|
chat_example_id: StrObjectId
|
|
82
120
|
company_id: StrObjectId
|
|
@@ -130,11 +168,9 @@ class DoubleCheckerCallbackMetadata(BaseModel):
|
|
|
130
168
|
company_id: StrObjectId
|
|
131
169
|
ai_agent_id: StrObjectId
|
|
132
170
|
incoming_messages_ids: List[str]
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
# triggered_by_user_id for manual_trigger, smart_follow_up_id for follow_up
|
|
137
|
-
triggered_by_user_id: Optional[StrObjectId] = None
|
|
171
|
+
trigger: ChainOfThoughtInChatTrigger
|
|
172
|
+
chain_of_thought_id: StrObjectId
|
|
173
|
+
|
|
138
174
|
|
|
139
175
|
class DoubleCheckerForIncomingMessagesAnswerEvent(LambdaAiEvent):
|
|
140
176
|
type: InvokationType = InvokationType.DOUBLE_CHECKER_FOR_INCOMING_MESSAGES_ANSWER
|
|
@@ -142,13 +178,73 @@ class DoubleCheckerForIncomingMessagesAnswerEvent(LambdaAiEvent):
|
|
|
142
178
|
|
|
143
179
|
class DoubleCheckerForIncomingMessagesAnswerCallbackEvent(LambdaAiEvent):
|
|
144
180
|
type: InvokationType = InvokationType.DOUBLE_CHECKER_FOR_INCOMING_MESSAGES_ANSWER_CALLBACK
|
|
145
|
-
data:
|
|
181
|
+
data: ExpectedOutputIncomingMessage
|
|
146
182
|
callback_metadata: DoubleCheckerCallbackMetadata
|
|
147
183
|
|
|
148
|
-
|
|
184
|
+
@model_validator(mode="before")
|
|
185
|
+
@classmethod
|
|
186
|
+
def set_chain_of_thought_id(cls, values: Dict[str, Any]):
|
|
187
|
+
"""
|
|
188
|
+
Get the chain_of_thought_id from callback_metadata and set it in data.chain_of_thought.id
|
|
189
|
+
|
|
190
|
+
Handles both cases:
|
|
191
|
+
- data is a JSON string (needs parsing)
|
|
192
|
+
- data is already a dict
|
|
193
|
+
"""
|
|
194
|
+
import json
|
|
195
|
+
|
|
196
|
+
data = values.get("data")
|
|
197
|
+
callback_metadata = values.get("callback_metadata")
|
|
198
|
+
|
|
199
|
+
if not data or not callback_metadata:
|
|
200
|
+
return values
|
|
201
|
+
|
|
202
|
+
# Get chain_of_thought_id from callback_metadata (could be dict or object)
|
|
203
|
+
if isinstance(callback_metadata, dict):
|
|
204
|
+
chain_of_thought_id = callback_metadata.get("chain_of_thought_id")
|
|
205
|
+
else:
|
|
206
|
+
chain_of_thought_id = getattr(callback_metadata, "chain_of_thought_id", None)
|
|
207
|
+
|
|
208
|
+
if not chain_of_thought_id:
|
|
209
|
+
return values
|
|
210
|
+
|
|
211
|
+
# Parse data if it's a JSON string
|
|
212
|
+
if isinstance(data, str):
|
|
213
|
+
try:
|
|
214
|
+
data = json.loads(data)
|
|
215
|
+
values["data"] = data
|
|
216
|
+
except (json.JSONDecodeError, TypeError):
|
|
217
|
+
return values
|
|
218
|
+
|
|
219
|
+
# If data is a dict, set the id in chain_of_thought
|
|
220
|
+
if isinstance(data, dict):
|
|
221
|
+
chain_of_thought = data.get("chain_of_thought")
|
|
222
|
+
if isinstance(chain_of_thought, dict):
|
|
223
|
+
chain_of_thought["id"] = chain_of_thought_id
|
|
224
|
+
|
|
225
|
+
return values
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
# Smart Follow-Up Decision Output Events
|
|
230
|
+
|
|
231
|
+
class SmartFollowUpDecisionOutputData(BaseModel):
|
|
232
|
+
"""Data for smart follow-up decision output"""
|
|
149
233
|
chat_id: StrObjectId
|
|
150
234
|
company_id: StrObjectId
|
|
151
235
|
ai_agent_id: StrObjectId
|
|
236
|
+
smart_follow_up_output: ExpectedOutputSmartFollowUp
|
|
237
|
+
smart_follow_up_id: Optional[StrObjectId] = None
|
|
238
|
+
|
|
239
|
+
class SmartFollowUpDecisionOutputEvent(LambdaAiEvent):
|
|
240
|
+
"""
|
|
241
|
+
Event for smart follow-up decision output.
|
|
242
|
+
|
|
243
|
+
Similar to incoming message decision but for follow-ups.
|
|
244
|
+
Bypasses double checker and sends directly to API.
|
|
245
|
+
"""
|
|
246
|
+
type: InvokationType = InvokationType.SMART_FOLLOW_UP_DECISION_OUTPUT
|
|
247
|
+
data: SmartFollowUpDecisionOutputData
|
|
152
248
|
|
|
153
249
|
|
|
154
250
|
# New AI Agent Context Building Events (for new architecture)
|
|
@@ -183,7 +279,7 @@ class GetChatWithPromptForFollowUpEventData(BaseModel):
|
|
|
183
279
|
"""Data for get chat with prompt for follow-up event"""
|
|
184
280
|
chat_id: StrObjectId
|
|
185
281
|
company_id: StrObjectId
|
|
186
|
-
smart_follow_up_id: StrObjectId
|
|
282
|
+
smart_follow_up_id: Optional[StrObjectId] = Field(default=None, description="Smart follow-up ID")
|
|
187
283
|
# Trigger information
|
|
188
284
|
trigger: ChainOfThoughtInChatTrigger
|
|
189
285
|
# trigger_id is derived from: smart_follow_up_id
|
|
@@ -303,7 +399,8 @@ class EscalateAIAgentInChatEventData(BaseModel):
|
|
|
303
399
|
"""Data for escalating an AI agent (requiring human intervention)"""
|
|
304
400
|
chat_id: StrObjectId
|
|
305
401
|
company_id: StrObjectId
|
|
306
|
-
reason:
|
|
402
|
+
reason: HumanInterventionReason = Field(description="Reason for escalation", default=HumanInterventionReason.SOMETHING_WENT_WRONG)
|
|
403
|
+
message: Optional[str] = Field(default="El agente de IA requiere de tu intervención", description="The message to display to the user if any")
|
|
307
404
|
|
|
308
405
|
|
|
309
406
|
class EscalateAIAgentInChatEvent(LambdaAiEvent):
|
|
@@ -335,6 +432,24 @@ class UnescalateAIAgentInChatEvent(LambdaAiEvent):
|
|
|
335
432
|
data: UnescalateAIAgentInChatEventData
|
|
336
433
|
|
|
337
434
|
|
|
435
|
+
|
|
436
|
+
class GetChainOfThoughtsByChatIdEventData(BaseModel):
|
|
437
|
+
"""Data for getting chain of thoughts by chat ID"""
|
|
438
|
+
chat_id: StrObjectId
|
|
439
|
+
company_id: StrObjectId
|
|
440
|
+
skip: int = Field(default=0, description="Number of results to skip for pagination")
|
|
441
|
+
limit: int = Field(default=10, description="Number of results to return")
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
class GetChainOfThoughtsByChatIdEvent(LambdaAiEvent):
|
|
445
|
+
"""
|
|
446
|
+
Event to get chain of thoughts for a chat.
|
|
447
|
+
|
|
448
|
+
Returns a list of chain of thoughts associated with the given chat ID,
|
|
449
|
+
sorted by created_at (newest first), with pagination support via skip.
|
|
450
|
+
"""
|
|
451
|
+
type: InvokationType = InvokationType.GET_CHAIN_OF_THOUGHTS_BY_CHAT_ID
|
|
452
|
+
data: GetChainOfThoughtsByChatIdEventData
|
|
338
453
|
# Launch Events
|
|
339
454
|
|
|
340
455
|
class LaunchCommunicationEventData(BaseModel):
|
|
@@ -11,13 +11,14 @@ class InvokationType(StrEnum):
|
|
|
11
11
|
SMART_TAGGING_PROMPT = "smart_tagging_prompt"
|
|
12
12
|
QUALITY_TEST_INTERACTION = "quality_test_interaction"
|
|
13
13
|
# Callback-specific types
|
|
14
|
-
INCOMING_MESSAGE_CALLBACK = "incoming_message_callback"
|
|
15
14
|
SINGLE_QUALITY_TEST_CALLBACK = "single_quality_test_callback"
|
|
16
15
|
SMART_TAGGING_CALLBACK = "smart_tagging_callback"
|
|
17
16
|
QUALITY_TESTS_FOR_UPDATED_AI_COMPONENT = "quality_tests_for_updated_ai_component"
|
|
18
17
|
FIX_BUGGED_AI_AGENTS_CALLS_IN_CHATS = "fix_bugged_ai_agents_calls_in_chats"
|
|
19
18
|
DOUBLE_CHECKER_FOR_INCOMING_MESSAGES_ANSWER = "double_checker_for_incoming_messages_answer"
|
|
20
19
|
DOUBLE_CHECKER_FOR_INCOMING_MESSAGES_ANSWER_CALLBACK = "double_checker_for_incoming_messages_answer_callback"
|
|
20
|
+
# Decision output events
|
|
21
|
+
SMART_FOLLOW_UP_DECISION_OUTPUT = "smart_follow_up_decision_output"
|
|
21
22
|
# AI Agent context building events (new architecture)
|
|
22
23
|
GET_CHAT_WITH_PROMPT_INCOMING_MESSAGE = "get_chat_with_prompt_incoming_message"
|
|
23
24
|
GET_CHAT_WITH_PROMPT_FOLLOW_UP = "get_chat_with_prompt_follow_up"
|
|
@@ -30,6 +31,7 @@ class InvokationType(StrEnum):
|
|
|
30
31
|
UPDATE_AI_AGENT_MODE_IN_CHAT = "update_ai_agent_mode_in_chat"
|
|
31
32
|
ESCALATE_AI_AGENT_IN_CHAT = "escalate_ai_agent_in_chat"
|
|
32
33
|
UNESCALATE_AI_AGENT_IN_CHAT = "unescalate_ai_agent_in_chat"
|
|
34
|
+
GET_CHAIN_OF_THOUGHTS_BY_CHAT_ID = "get_chain_of_thoughts_by_chat_id"
|
|
33
35
|
# Launch events
|
|
34
36
|
LAUNCH_COMMUNICATION = "launch_communication"
|
|
35
37
|
LAUNCH_WELCOME_KIT = "launch_welcome_kit"
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from letschatty.models.company.assets.chat_assets import ChainOfThoughtInChatTrigger
|
|
1
2
|
from pydantic import BaseModel, Field
|
|
2
3
|
from letschatty.models import StrObjectId
|
|
3
4
|
from letschatty.models.company.assets.ai_agents_v2.chatty_ai_agent import N8NWorkspaceAgentType
|
|
@@ -10,4 +11,5 @@ class SmartFollowUpN8NPayload(BaseModel):
|
|
|
10
11
|
class ManualTriggerN8NPayload(BaseModel):
|
|
11
12
|
chat_id: StrObjectId = Field(description="The id of the chat")
|
|
12
13
|
company_id: StrObjectId = Field(description="The id of the company")
|
|
13
|
-
n8n_agent_type: N8NWorkspaceAgentType = Field(description="The type of agent to redirect the message to")
|
|
14
|
+
n8n_agent_type: N8NWorkspaceAgentType = Field(description="The type of agent to redirect the message to")
|
|
15
|
+
trigger: ChainOfThoughtInChatTrigger = Field(default=ChainOfThoughtInChatTrigger.MANUAL_TRIGGER)
|
|
@@ -28,4 +28,5 @@ from ...messages.chatty_messages import ChattyMessage
|
|
|
28
28
|
from ...company.CRM.funnel import Funnel, FunnelStage
|
|
29
29
|
from ...utils.types import Status
|
|
30
30
|
from .chat_based_events.chat_based_event import CustomerEventData
|
|
31
|
-
from .chat_based_events.ai_agent_chat import ChattyAIChatEvent, ChattyAIChatData
|
|
31
|
+
from .chat_based_events.ai_agent_chat import ChattyAIChatEvent, ChattyAIChatData
|
|
32
|
+
from .chat_based_events.ai_agent_execution_event import AIAgentExecutionEvent, AIAgentExecutionEventData
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""AI Agent Execution Events - Track AI agent lifecycle and decision-making"""
|
|
2
|
+
|
|
3
|
+
from ..base import Event, EventData
|
|
4
|
+
from ..event_types import EventType
|
|
5
|
+
from .chat_based_event import CustomerEventData
|
|
6
|
+
from typing import ClassVar, Optional, Dict, Any
|
|
7
|
+
from ....utils.types.identifier import StrObjectId
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AIAgentExecutionEventData(CustomerEventData):
|
|
11
|
+
"""Data for AI agent execution events"""
|
|
12
|
+
ai_agent_id: StrObjectId
|
|
13
|
+
chain_of_thought_id: StrObjectId
|
|
14
|
+
trigger: str # USER_MESSAGE, FOLLOW_UP, MANUAL_TRIGGER, RETRY
|
|
15
|
+
decision_type: Optional[str] = None # send, suggest, escalate, skip
|
|
16
|
+
error_message: Optional[str] = None
|
|
17
|
+
duration_ms: Optional[int] = None
|
|
18
|
+
user_rating: Optional[int] = None # 1-5 stars
|
|
19
|
+
metadata: Optional[Dict[str, Any]] = None
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class AIAgentExecutionEvent(Event):
|
|
23
|
+
"""
|
|
24
|
+
Events for AI agent execution lifecycle.
|
|
25
|
+
|
|
26
|
+
This event type covers the entire AI agent decision-making process,
|
|
27
|
+
from trigger to final decision, including all intermediate steps.
|
|
28
|
+
"""
|
|
29
|
+
data: AIAgentExecutionEventData
|
|
30
|
+
|
|
31
|
+
VALID_TYPES: ClassVar[set] = {
|
|
32
|
+
# Trigger events
|
|
33
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_TRIGGER_USER_MESSAGE,
|
|
34
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_TRIGGER_FOLLOW_UP,
|
|
35
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_TRIGGER_MANUAL,
|
|
36
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_TRIGGER_RETRY,
|
|
37
|
+
|
|
38
|
+
# State events
|
|
39
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_STATE_PROCESSING_STARTED,
|
|
40
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_STATE_CALL_STARTED,
|
|
41
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_STATE_ESCALATED,
|
|
42
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_STATE_UNESCALATED,
|
|
43
|
+
|
|
44
|
+
# Call events
|
|
45
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_CALL_GET_CHAT_WITH_PROMPT,
|
|
46
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_CALL_TAGGER,
|
|
47
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_CALL_DOUBLE_CHECKER,
|
|
48
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_CALL_DEBUGGER,
|
|
49
|
+
|
|
50
|
+
# Callback events
|
|
51
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_CALLBACK_GET_CHAT_WITH_PROMPT,
|
|
52
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_CALLBACK_TAGGER,
|
|
53
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_CALLBACK_DOUBLE_CHECKER,
|
|
54
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_CALLBACK_OUTPUT_RECEIVED,
|
|
55
|
+
|
|
56
|
+
# Decision events
|
|
57
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_DECISION_SEND,
|
|
58
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_DECISION_SUGGEST,
|
|
59
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_DECISION_ESCALATE,
|
|
60
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_DECISION_SKIP,
|
|
61
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_DECISION_SENT_TO_API,
|
|
62
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_DECISION_COMPLETED,
|
|
63
|
+
|
|
64
|
+
# Error events
|
|
65
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_ERROR_CALL_FAILED,
|
|
66
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_ERROR_CALL_CANCELLED,
|
|
67
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_ERROR_VALIDATION_FAILED,
|
|
68
|
+
|
|
69
|
+
# Rating events
|
|
70
|
+
EventType.CHATTY_AI_AGENT_IN_CHAT_RATING_RECEIVED,
|
|
71
|
+
}
|
|
@@ -70,9 +70,6 @@ class AssetEvent(Event):
|
|
|
70
70
|
EventType.FILTER_CRITERIA_CREATED,
|
|
71
71
|
EventType.FILTER_CRITERIA_UPDATED,
|
|
72
72
|
EventType.FILTER_CRITERIA_DELETED,
|
|
73
|
-
EventType.FORM_FIELD_CREATED,
|
|
74
|
-
EventType.FORM_FIELD_UPDATED,
|
|
75
|
-
EventType.FORM_FIELD_DELETED,
|
|
76
73
|
EventType.COMPANY_CREATED,
|
|
77
74
|
EventType.COMPANY_UPDATED,
|
|
78
75
|
EventType.COMPANY_DELETED
|
|
@@ -86,10 +86,6 @@ EVENT_TO_TYPE_CLASSES = {
|
|
|
86
86
|
EventType.WORKFLOW_CREATED : AssetEvent,
|
|
87
87
|
EventType.WORKFLOW_UPDATED : AssetEvent,
|
|
88
88
|
EventType.WORKFLOW_DELETED : AssetEvent,
|
|
89
|
-
#FORM FIELDS
|
|
90
|
-
EventType.FORM_FIELD_CREATED : AssetEvent,
|
|
91
|
-
EventType.FORM_FIELD_UPDATED : AssetEvent,
|
|
92
|
-
EventType.FORM_FIELD_DELETED : AssetEvent,
|
|
93
89
|
#AGENTS
|
|
94
90
|
EventType.USER_CREATED : UserEvent,
|
|
95
91
|
EventType.USER_UPDATED : UserEvent,
|
|
@@ -12,6 +12,51 @@ class EventType(StrEnum):
|
|
|
12
12
|
AI_AGENT_ASSIGNED_TO_CHAT = "chat.chatty_ai_agent.assigned_to_chat"
|
|
13
13
|
AI_AGENT_REMOVED_FROM_CHAT = "chat.chatty_ai_agent.removed_from_chat"
|
|
14
14
|
AI_AGENT_UPDATED_ON_CHAT = "chat.chatty_ai_agent.updated_on_chat"
|
|
15
|
+
|
|
16
|
+
#CHATTY AI AGENT EXECUTION EVENTS - 3-level hierarchy for execution tracking
|
|
17
|
+
# Pattern: chatty_ai_agent_in_chat.{operation}.{detail}
|
|
18
|
+
# Note: Execution events are already chat-scoped via CustomerEventData
|
|
19
|
+
|
|
20
|
+
# TRIGGER EVENTS - What initiates AI agent processing
|
|
21
|
+
CHATTY_AI_AGENT_IN_CHAT_TRIGGER_USER_MESSAGE = "chatty_ai_agent_in_chat.trigger.user_message"
|
|
22
|
+
CHATTY_AI_AGENT_IN_CHAT_TRIGGER_FOLLOW_UP = "chatty_ai_agent_in_chat.trigger.follow_up"
|
|
23
|
+
CHATTY_AI_AGENT_IN_CHAT_TRIGGER_MANUAL = "chatty_ai_agent_in_chat.trigger.manual"
|
|
24
|
+
CHATTY_AI_AGENT_IN_CHAT_TRIGGER_RETRY = "chatty_ai_agent_in_chat.trigger.retry"
|
|
25
|
+
|
|
26
|
+
# STATE EVENTS - AI agent state changes
|
|
27
|
+
CHATTY_AI_AGENT_IN_CHAT_STATE_PROCESSING_STARTED = "chatty_ai_agent_in_chat.state.processing_started"
|
|
28
|
+
CHATTY_AI_AGENT_IN_CHAT_STATE_CALL_STARTED = "chatty_ai_agent_in_chat.state.call_started"
|
|
29
|
+
CHATTY_AI_AGENT_IN_CHAT_STATE_ESCALATED = "chatty_ai_agent_in_chat.state.escalated"
|
|
30
|
+
CHATTY_AI_AGENT_IN_CHAT_STATE_UNESCALATED = "chatty_ai_agent_in_chat.state.unescalated"
|
|
31
|
+
|
|
32
|
+
# CALL EVENTS - Outbound calls to services
|
|
33
|
+
CHATTY_AI_AGENT_IN_CHAT_CALL_GET_CHAT_WITH_PROMPT = "chatty_ai_agent_in_chat.call.get_chat_with_prompt"
|
|
34
|
+
CHATTY_AI_AGENT_IN_CHAT_CALL_TAGGER = "chatty_ai_agent_in_chat.call.tagger"
|
|
35
|
+
CHATTY_AI_AGENT_IN_CHAT_CALL_DOUBLE_CHECKER = "chatty_ai_agent_in_chat.call.double_checker"
|
|
36
|
+
CHATTY_AI_AGENT_IN_CHAT_CALL_DEBUGGER = "chatty_ai_agent_in_chat.call.debugger"
|
|
37
|
+
|
|
38
|
+
# CALLBACK EVENTS - Responses received from services
|
|
39
|
+
CHATTY_AI_AGENT_IN_CHAT_CALLBACK_GET_CHAT_WITH_PROMPT = "chatty_ai_agent_in_chat.callback.get_chat_with_prompt"
|
|
40
|
+
CHATTY_AI_AGENT_IN_CHAT_CALLBACK_TAGGER = "chatty_ai_agent_in_chat.callback.tagger"
|
|
41
|
+
CHATTY_AI_AGENT_IN_CHAT_CALLBACK_DOUBLE_CHECKER = "chatty_ai_agent_in_chat.callback.double_checker"
|
|
42
|
+
CHATTY_AI_AGENT_IN_CHAT_CALLBACK_OUTPUT_RECEIVED = "chatty_ai_agent_in_chat.callback.output_received"
|
|
43
|
+
|
|
44
|
+
# DECISION EVENTS - AI agent decisions and actions
|
|
45
|
+
CHATTY_AI_AGENT_IN_CHAT_DECISION_SEND = "chatty_ai_agent_in_chat.decision.send"
|
|
46
|
+
CHATTY_AI_AGENT_IN_CHAT_DECISION_SUGGEST = "chatty_ai_agent_in_chat.decision.suggest"
|
|
47
|
+
CHATTY_AI_AGENT_IN_CHAT_DECISION_ESCALATE = "chatty_ai_agent_in_chat.decision.escalate"
|
|
48
|
+
CHATTY_AI_AGENT_IN_CHAT_DECISION_SKIP = "chatty_ai_agent_in_chat.decision.skip"
|
|
49
|
+
CHATTY_AI_AGENT_IN_CHAT_DECISION_SENT_TO_API = "chatty_ai_agent_in_chat.decision.sent_to_api"
|
|
50
|
+
CHATTY_AI_AGENT_IN_CHAT_DECISION_COMPLETED = "chatty_ai_agent_in_chat.decision.completed"
|
|
51
|
+
|
|
52
|
+
# ERROR EVENTS - Failures and cancellations
|
|
53
|
+
CHATTY_AI_AGENT_IN_CHAT_ERROR_CALL_FAILED = "chatty_ai_agent_in_chat.error.call_failed"
|
|
54
|
+
CHATTY_AI_AGENT_IN_CHAT_ERROR_CALL_CANCELLED = "chatty_ai_agent_in_chat.error.call_cancelled"
|
|
55
|
+
CHATTY_AI_AGENT_IN_CHAT_ERROR_VALIDATION_FAILED = "chatty_ai_agent_in_chat.error.validation_failed"
|
|
56
|
+
|
|
57
|
+
# RATING EVENTS - User feedback
|
|
58
|
+
CHATTY_AI_AGENT_IN_CHAT_RATING_RECEIVED = "chatty_ai_agent_in_chat.rating.received"
|
|
59
|
+
|
|
15
60
|
#PRODUCTS
|
|
16
61
|
PRODUCT_ASSIGNED = "chat.product.assigned"
|
|
17
62
|
PRODUCT_REMOVED = "chat.product.removed"
|
|
@@ -30,7 +30,7 @@ class ContinuousConversation(ChattyAssetModel):
|
|
|
30
30
|
template_message_waid: Optional[str] = None
|
|
31
31
|
status: Optional[ContinuousConversationStatus] = Field(default=ContinuousConversationStatus.CREATED)
|
|
32
32
|
active: bool = Field(default=True)
|
|
33
|
-
expires_at: datetime = Field(
|
|
33
|
+
expires_at: datetime = Field(default=datetime.now(ZoneInfo("UTC")) + timedelta(days=10))
|
|
34
34
|
messages: List[MessageDraft]
|
|
35
35
|
creator_id: StrObjectId
|
|
36
36
|
forced_send: bool = Field(default=False)
|
|
@@ -55,7 +55,7 @@ class SmartFollowUpDecision(BaseModel):
|
|
|
55
55
|
SmartFollowUpDecisionAction.POSTPONE_DELTA_TIME]:
|
|
56
56
|
# Postpone actions don't require messages
|
|
57
57
|
if self.messages is not None and len(self.messages) > 0:
|
|
58
|
-
raise ValueError("Messages are not allowed when action is postpone
|
|
58
|
+
raise ValueError("Messages are not allowed when action is postpone")
|
|
59
59
|
else:
|
|
60
60
|
raise ValueError(f"Invalid action: {self.action}")
|
|
61
61
|
|
|
@@ -110,6 +110,12 @@ class ChattyAIAgent(CompanyAssetModel):
|
|
|
110
110
|
examples: List[StrObjectId] = Field(default_factory=list, description="Training examples")
|
|
111
111
|
double_checker_enabled: bool = Field(default=False, description="Whether the double checker is enabled")
|
|
112
112
|
double_checker_instructions: Optional[str] = Field(default=None, description="Instructions for the double checker")
|
|
113
|
+
copilot_confidence_threshold: Optional[int] = Field(
|
|
114
|
+
default=None,
|
|
115
|
+
ge=0,
|
|
116
|
+
le=100,
|
|
117
|
+
description="Confidence threshold 0-100 para modo COPILOT (fallback a env si no está)"
|
|
118
|
+
)
|
|
113
119
|
|
|
114
120
|
# Pre-qualification configuration
|
|
115
121
|
pre_qualify: Optional["PreQualifyConfig"] = Field(
|
|
@@ -165,4 +171,4 @@ class ChattyAIAgent(CompanyAssetModel):
|
|
|
165
171
|
|
|
166
172
|
# Import and rebuild for forward reference resolution
|
|
167
173
|
from .pre_qualify_config import PreQualifyConfig
|
|
168
|
-
ChattyAIAgent.model_rebuild()
|
|
174
|
+
ChattyAIAgent.model_rebuild()
|
|
@@ -123,6 +123,10 @@ class ChattyAIAgentInChat(CompanyAssetModel):
|
|
|
123
123
|
default=None,
|
|
124
124
|
description="If the trigger is a user message, this will be the id of the incoming message"
|
|
125
125
|
)
|
|
126
|
+
last_reset_message_id: Optional[str] = Field(
|
|
127
|
+
default=None,
|
|
128
|
+
description="Last reset control trigger message id handled for this chat"
|
|
129
|
+
)
|
|
126
130
|
|
|
127
131
|
# Assignment metadata
|
|
128
132
|
assigned_at: datetime = Field(default_factory=lambda: datetime.now(ZoneInfo("UTC")))
|
|
@@ -352,4 +356,3 @@ class ChattyAIAgentInChat(CompanyAssetModel):
|
|
|
352
356
|
"""Cancel data collection"""
|
|
353
357
|
self.data_collection_status = DataCollectionStatus.CANCELLED
|
|
354
358
|
self.updated_at = datetime.now(ZoneInfo("UTC"))
|
|
355
|
-
|
|
@@ -16,7 +16,7 @@ class ChattyAIMode(StrEnum):
|
|
|
16
16
|
return {
|
|
17
17
|
cls.AUTONOMOUS: "El agente de IA tendrá la autonomía de conversar en tiempo real con el usuario, respetando sus instrucciones y las reglas establecidas.",
|
|
18
18
|
cls.SUGGESTIONS: "El agente de IA sugerirá sólo hará sugerencias de respuestas y seguimientos, pero no enviará mensajes ni interactuará de forma directa con el usuario.",
|
|
19
|
-
cls.COPILOT: "El agente de IA
|
|
19
|
+
cls.COPILOT: "El agente de IA responderá automáticamente cuando tenga alta confianza y la consulta esté dentro del alcance; si no, sugerirá o escalará para revisión humana.",
|
|
20
20
|
cls.OFF: "El agente de IA estará inactivo. No responderá al usuario ni hará sugerencias."
|
|
21
21
|
}[mode]
|
|
22
22
|
|
|
@@ -26,7 +26,7 @@ class ChattyAIMode(StrEnum):
|
|
|
26
26
|
mode_description = {
|
|
27
27
|
cls.AUTONOMOUS: "Only answer based on the context and rules provided. Do not improvise or make up information. If you can't handle the question, escalate to a human.",
|
|
28
28
|
cls.SUGGESTIONS: "You're only going to be making suggestions, all your messages will be reviewd by a human and you should add the reasoning to your chain of thought. If the user message is not worth answering, you can use the 'skip' action in your output. If the user message is worth answering, you NEED to use the 'suggest' action in your output. ",
|
|
29
|
-
cls.COPILOT: "You're in
|
|
29
|
+
cls.COPILOT: "You're in COPILOT mode. Use your confidence to decide the action: send when the request is within scope and you are confident, suggest when you're unsure or a human touch is needed (complex negotiation, frustration, high-value, or missing info), and escalate if it's required by control triggers. Always include a confidence score (0-100).",
|
|
30
30
|
cls.OFF: ""
|
|
31
31
|
}[mode]
|
|
32
32
|
return intro + "\n\n" + mode_description
|
|
@@ -25,6 +25,7 @@ class GetChatWithPromptResponse(BaseModel):
|
|
|
25
25
|
"messages": self.messages,
|
|
26
26
|
"n8n_agent_type": self.chatty_ai_agent.n8n_workspace_agent_type.value if self.chatty_ai_agent else None,
|
|
27
27
|
"n8n_agent_type_parameters": self.chatty_ai_agent.n8n_workspace_agent_type_parameteres.model_dump() if self.chatty_ai_agent else None,
|
|
28
|
+
"ai_agent_id": self.chatty_ai_agent.id if self.chatty_ai_agent else None,
|
|
28
29
|
"phone_number": self.chat.client.get_waid() if self.chat else None,
|
|
29
30
|
"chain_of_thought_id": self.chain_of_thought_id,
|
|
30
31
|
"trigger_id": self.trigger_id
|
|
@@ -5,11 +5,17 @@ Defines the data collection, acceptance criteria, and destination actions
|
|
|
5
5
|
for qualifying/disqualifying users.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
+
from letschatty.models.company.assets.automation import Automation
|
|
8
9
|
from pydantic import BaseModel, Field
|
|
9
10
|
from typing import Optional, List
|
|
10
11
|
from enum import StrEnum
|
|
11
12
|
from letschatty.models.utils.types.identifier import StrObjectId
|
|
12
13
|
|
|
14
|
+
class PostToExternalApiConfig(BaseModel):
|
|
15
|
+
"""Placeholder provisorio"""
|
|
16
|
+
url: str = Field(description="The URL to post to")
|
|
17
|
+
method: str = Field(description="The HTTP method to use")
|
|
18
|
+
api_key: str
|
|
13
19
|
|
|
14
20
|
class PreQualifyDestination(StrEnum):
|
|
15
21
|
"""
|
|
@@ -19,8 +25,11 @@ class PreQualifyDestination(StrEnum):
|
|
|
19
25
|
CALENDAR_SCHEDULER = "calendar_scheduler" # Allow AI agent to schedule meetings
|
|
20
26
|
ESCALATE = "escalate" # Escalate to human
|
|
21
27
|
CUSTOM_MESSAGE = "custom_message" # Send a custom message
|
|
28
|
+
AUTO_ASSIGN_HUMAN_AGENT = "auto_assign_human_agent" #
|
|
22
29
|
CONTINUE = "continue" # Continue normal AI agent flow
|
|
23
|
-
NONE = "none" # Do nothing
|
|
30
|
+
NONE = "none" # Do nothing (no-op)
|
|
31
|
+
ARCHIVE = "archive"
|
|
32
|
+
POST_TO_EXTERNAL_API = "post_to_external_api"
|
|
24
33
|
|
|
25
34
|
|
|
26
35
|
class PreQualifyFormField(BaseModel):
|
|
@@ -68,6 +77,10 @@ class PreQualifyConfig(BaseModel):
|
|
|
68
77
|
default=None,
|
|
69
78
|
description="Custom message to send when user does NOT qualify (if destination is custom_message or escalate)"
|
|
70
79
|
)
|
|
80
|
+
post_to_external_api : Optional[PostToExternalApiConfig] = Field(
|
|
81
|
+
default=None,
|
|
82
|
+
description="Configuration for posting to an external API"
|
|
83
|
+
)
|
|
71
84
|
|
|
72
85
|
@property
|
|
73
86
|
def has_form_fields(self) -> bool:
|
|
@@ -108,4 +121,3 @@ class PreQualifyConfig(BaseModel):
|
|
|
108
121
|
original_len = len(self.form_fields)
|
|
109
122
|
self.form_fields = [f for f in self.form_fields if f.field_key != field_key]
|
|
110
123
|
return len(self.form_fields) < original_len
|
|
111
|
-
|