Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed utterrence for multiflow, slot initialization for numerical,list and boolean slot #1790

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions kairon/shared/chat/agent/agent_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ class AgenticFlow:
'constructor': TextSlot,
'args': ['name', 'initial_value', 'value_reset_delay', 'influence_conversation', 'mappings']
},
"boolean": {
"bool": {
'constructor': BooleanSlot,
'args': ['name', 'initial_value', 'value_reset_delay', 'influence_conversation']
'args': ['name', 'initial_value', 'value_reset_delay', 'influence_conversation', 'mappings']
},
"categorical": {
'constructor': CategoricalSlot,
'args': ['name', 'initial_value', 'value_reset_delay', 'influence_conversation', 'mappings']
},
"float": {
'constructor': FloatSlot,
'args': ['name', 'initial_value', 'value_reset_delay', 'influence_conversation', 'max_value', 'min_value']
'args': ['name', 'initial_value', 'value_reset_delay', 'influence_conversation', 'max_value', 'min_value', 'mappings']
},
"list": {
'constructor': ListSlot,
'args': ['name', 'initial_value', 'value_reset_delay', 'influence_conversation']
'args': ['name', 'initial_value', 'value_reset_delay', 'influence_conversation', 'mappings']
},
"any": {
'constructor': AnySlot,
Expand Down Expand Up @@ -223,6 +223,9 @@ async def execute_event(self, event: dict):
except Exception as e:
logger.error(f"Error in executing action [{event['name']}]: {e}")
raise AppException(f"Error in executing action [{event['name']}]")
elif event['type'] == 'BOT' and event['name'].startswith("utter_"):
self.responses.append(self.get_utterance_response(event['name']))
self.executed_actions.append(event['name'])

def process_tracker_events(self, events:list):
for event in events:
Expand Down
35 changes: 25 additions & 10 deletions tests/unit_test/agentic_flow_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@ def setup_class(cls):
"node_id": "61d7459c-5a34-464a-b9e5-25e7808f1f24",
"component_id": "676a9ceb097f6a9872bc49db"
},
"connections": [{
"name": "utter_greet",
"type": "BOT",
"node_id": "7c58bd84-48ab-45e3-aa50-bef52c50c4b6",
"component_id": "67a5a302956678b8f9106ee6"
}]
},
{
"step": {
"name": "utter_greet",
"type": "BOT",
"node_id": "7c58bd84-48ab-45e3-aa50-bef52c50c4b6",
"component_id": "67a5a302956678b8f9106ee6"
},
"connections": []
},
{
Expand Down Expand Up @@ -329,10 +343,10 @@ async def test_execute__rule_with_multiflow(self, patch_log_chat_history):
with patch('kairon.chat.actions.KRemoteAction.run') as mock_action:
mock_action.return_value = [BotUttered("Action Executed")]
res, err = await flow.execute_rule("py_multiflow")
assert len(res) == 2
assert len(res) == 3
assert res[0] == {'text': 'Action Executed'}
assert not err
assert flow.executed_actions == ['py_multi', 'py_ans_a']
assert flow.executed_actions == ['py_multi', 'py_ans_a', 'utter_greet']
mock_action.assert_called()
patch_log_chat_history.assert_called_once()

Expand Down Expand Up @@ -370,10 +384,10 @@ async def test_execute__rule_with_multiflow_slot_influence2(self, patch_log_chat
with patch('kairon.chat.actions.KRemoteAction.run') as mock_action:
mock_action.return_value = [BotUttered("Action Executed")]
res, err = await flow.execute_rule("py_multiflow")
assert len(res) == 2
assert len(res) == 3
mock_action.assert_called()
print(flow.executed_actions)
assert flow.executed_actions == ['py_multi', 'py_ans_a']
assert flow.executed_actions == ['py_multi', 'py_ans_a', 'utter_greet']

patch_log_chat_history.assert_called()

Expand Down Expand Up @@ -411,16 +425,17 @@ def test_sanitize_multiflow_events(self):
multiflow = MultiflowStories.objects(bot=pytest.af_test_bot, block_name='py_multiflow').first()
events = multiflow.events
event_map, start = AgenticFlow.sanitize_multiflow_events(events)
expected = {'5691320b-6007-4609-8386-bee3afdd9490': {
'node_id': '5691320b-6007-4609-8386-bee3afdd9490', 'type': 'INTENT', 'name': 'i_multiflow', 'connections': {
'type': 'jump', 'node_id': '715f57e6-90df-42b1-b0de-daa14b22d72f'}},
'715f57e6-90df-42b1-b0de-daa14b22d72f': { 'node_id': '715f57e6-90df-42b1-b0de-daa14b22d72f', 'type': 'action', 'name': 'py_multi', 'connections': {'type': 'branch', 'criteria': 'SLOT', 'name': 'trigger_conditional', '1': 'fe210aa4-4885-4454-9acf-607621228ffd', '2': '589cebb9-7a93-4e76-98f8-342b123f32b8'}}
, 'fe210aa4-4885-4454-9acf-607621228ffd': {'node_id': 'fe210aa4-4885-4454-9acf-607621228ffd', 'type': 'SLOT', 'name': 'trigger_conditional', 'connections': {'type': 'jump', 'node_id': '61d7459c-5a34-464a-b9e5-25e7808f1f24'}},
'61d7459c-5a34-464a-b9e5-25e7808f1f24': {'node_id': '61d7459c-5a34-464a-b9e5-25e7808f1f24', 'type': 'action', 'name': 'py_ans_a', 'connections': None},
expected = {
'5691320b-6007-4609-8386-bee3afdd9490': {'node_id': '5691320b-6007-4609-8386-bee3afdd9490', 'type': 'INTENT', 'name': 'i_multiflow', 'connections': {'type': 'jump', 'node_id': '715f57e6-90df-42b1-b0de-daa14b22d72f'}},
'715f57e6-90df-42b1-b0de-daa14b22d72f': {'node_id': '715f57e6-90df-42b1-b0de-daa14b22d72f', 'type': 'action', 'name': 'py_multi', 'connections': {'type': 'branch', 'criteria': 'SLOT', 'name': 'trigger_conditional', '1': 'fe210aa4-4885-4454-9acf-607621228ffd', '2': '589cebb9-7a93-4e76-98f8-342b123f32b8'}},
'fe210aa4-4885-4454-9acf-607621228ffd': {'node_id': 'fe210aa4-4885-4454-9acf-607621228ffd', 'type': 'SLOT', 'name': 'trigger_conditional', 'connections': {'type': 'jump', 'node_id': '61d7459c-5a34-464a-b9e5-25e7808f1f24'}},
'61d7459c-5a34-464a-b9e5-25e7808f1f24': {'node_id': '61d7459c-5a34-464a-b9e5-25e7808f1f24', 'type': 'action', 'name': 'py_ans_a', 'connections': {'type': 'jump', 'node_id': '7c58bd84-48ab-45e3-aa50-bef52c50c4b6'}},
'7c58bd84-48ab-45e3-aa50-bef52c50c4b6': {'node_id': '7c58bd84-48ab-45e3-aa50-bef52c50c4b6', 'type': 'BOT', 'name': 'utter_greet', 'connections': None},
'589cebb9-7a93-4e76-98f8-342b123f32b8': {'node_id': '589cebb9-7a93-4e76-98f8-342b123f32b8', 'type': 'SLOT', 'name': 'trigger_conditional', 'connections': {'type': 'jump', 'node_id': '4f331af0-870e-40f3-883e-51c2a86f98eb'}},
'4f331af0-870e-40f3-883e-51c2a86f98eb': {'node_id': '4f331af0-870e-40f3-883e-51c2a86f98eb', 'type': 'action', 'name': 'fetch_poke_details', 'connections': {'type': 'jump', 'node_id': '1019cbaa-68fe-40c6-bcb9-c3e08e58e7ef'}},
'1019cbaa-68fe-40c6-bcb9-c3e08e58e7ef': {'node_id': '1019cbaa-68fe-40c6-bcb9-c3e08e58e7ef', 'type': 'action', 'name': 'py_ans_b', 'connections': None}}

print(event_map)
assert event_map == expected
assert start == '715f57e6-90df-42b1-b0de-daa14b22d72f'

Expand Down
Loading