rasa-pro 3.14.0rc2__py3-none-any.whl → 3.14.0rc3__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.
Potentially problematic release.
This version of rasa-pro might be problematic. Click here for more details.
- rasa/agents/protocol/a2a/a2a_agent.py +50 -42
- rasa/agents/utils.py +27 -5
- rasa/agents/validation.py +7 -9
- rasa/api.py +1 -2
- rasa/builder/copilot/copilot.py +37 -1
- rasa/builder/copilot/models.py +43 -49
- rasa/builder/copilot/prompts/copilot_system_prompt.jinja2 +33 -12
- rasa/builder/copilot/prompts/latest_user_message_context_prompt.jinja2 +59 -29
- rasa/builder/copilot/telemetry.py +8 -0
- rasa/builder/service.py +1 -0
- rasa/cli/dialogue_understanding_test.py +1 -0
- rasa/cli/e2e_test.py +1 -0
- rasa/cli/inspect.py +1 -0
- rasa/cli/project_templates/basic/tests/e2e_test_cases/without_stub/general/feedback.yml +46 -0
- rasa/cli/project_templates/basic/tests/e2e_test_cases/without_stub/general/goodbye.yml +9 -0
- rasa/cli/project_templates/basic/tests/e2e_test_cases/without_stub/general/help.yml +8 -0
- rasa/cli/project_templates/basic/tests/e2e_test_cases/without_stub/general/human_handoff.yml +41 -0
- rasa/cli/project_templates/basic/tests/e2e_test_cases/without_stub/general/patterns.yml +32 -0
- rasa/cli/project_templates/basic/tests/e2e_test_cases/without_stub/general/show_faqs.yml +8 -0
- rasa/cli/project_templates/telco/data/network/flow_solve_internet_issue.yml +2 -2
- rasa/cli/project_templates/telco/domain/network/solve_internet_issue.yml +1 -2
- rasa/cli/project_templates/telco/tests/e2e_test_cases/with_stub/network/solve_internet_not_slow.yml +33 -0
- rasa/cli/project_templates/telco/tests/e2e_test_cases/with_stub/network/solve_internet_slow.yml +47 -0
- rasa/cli/project_templates/telco/tests/e2e_test_cases/without_stub/general/hello.yml +8 -0
- rasa/cli/run.py +1 -5
- rasa/cli/shell.py +1 -0
- rasa/cli/train.py +1 -0
- rasa/cli/validation/bot_config.py +7 -2
- rasa/core/available_agents.py +65 -55
- rasa/core/config/available_endpoints.py +0 -3
- rasa/core/config/configuration.py +36 -1
- rasa/core/policies/flows/agent_executor.py +16 -8
- rasa/dialogue_understanding/commands/start_flow_command.py +10 -3
- rasa/dialogue_understanding/commands/utils.py +15 -4
- rasa/dialogue_understanding/generator/llm_based_command_generator.py +4 -2
- rasa/dialogue_understanding/generator/single_step/compact_llm_command_generator.py +4 -4
- rasa/dialogue_understanding/generator/single_step/search_ready_llm_command_generator.py +4 -4
- rasa/dialogue_understanding/generator/single_step/single_step_based_llm_command_generator.py +2 -2
- rasa/dialogue_understanding_test/du_test_runner.py +2 -2
- rasa/e2e_test/e2e_test_runner.py +2 -2
- rasa/shared/agents/auth/auth_strategy/oauth2_auth_strategy.py +10 -4
- rasa/shared/agents/auth/constants.py +1 -0
- rasa/shared/core/flows/steps/call.py +2 -2
- rasa/telemetry.py +3 -3
- rasa/validator.py +37 -0
- rasa/version.py +1 -1
- {rasa_pro-3.14.0rc2.dist-info → rasa_pro-3.14.0rc3.dist-info}/METADATA +13 -2
- {rasa_pro-3.14.0rc2.dist-info → rasa_pro-3.14.0rc3.dist-info}/RECORD +68 -60
- rasa/cli/project_templates/telco/tests/e2e_test_cases/network/solve_internet_issue.yml +0 -57
- /rasa/cli/project_templates/{finance/tests/e2e_test_cases → basic/tests/e2e_test_cases/without_stub}/general/hello.yml +0 -0
- /rasa/cli/project_templates/finance/tests/e2e_test_cases/{accounts → without_stub/accounts}/check_balance.yml +0 -0
- /rasa/cli/project_templates/finance/tests/e2e_test_cases/{accounts → without_stub/accounts}/download_statements.yml +0 -0
- /rasa/cli/project_templates/finance/tests/e2e_test_cases/{cards → without_stub/cards}/block_card.yml +0 -0
- /rasa/cli/project_templates/finance/tests/e2e_test_cases/{general → without_stub/general}/bot_challenge.yml +0 -0
- /rasa/cli/project_templates/finance/tests/e2e_test_cases/{general → without_stub/general}/feedback.yml +0 -0
- /rasa/cli/project_templates/finance/tests/e2e_test_cases/{general → without_stub/general}/goodbye.yml +0 -0
- /rasa/cli/project_templates/{telco/tests/e2e_test_cases → finance/tests/e2e_test_cases/without_stub}/general/hello.yml +0 -0
- /rasa/cli/project_templates/finance/tests/e2e_test_cases/{general → without_stub/general}/human_handoff.yml +0 -0
- /rasa/cli/project_templates/finance/tests/e2e_test_cases/{general → without_stub/general}/patterns.yml +0 -0
- /rasa/cli/project_templates/finance/tests/e2e_test_cases/{transfers → without_stub/transfers}/transfer_money.yml +0 -0
- /rasa/cli/project_templates/telco/tests/e2e_test_cases/{billing → without_stub/billing}/understand_bill.yml +0 -0
- /rasa/cli/project_templates/telco/tests/e2e_test_cases/{general → without_stub/general}/bot_challenge.yml +0 -0
- /rasa/cli/project_templates/telco/tests/e2e_test_cases/{general → without_stub/general}/feedback.yml +0 -0
- /rasa/cli/project_templates/telco/tests/e2e_test_cases/{general → without_stub/general}/goodbye.yml +0 -0
- /rasa/cli/project_templates/telco/tests/e2e_test_cases/{general → without_stub/general}/human_handoff.yml +0 -0
- /rasa/cli/project_templates/telco/tests/e2e_test_cases/{general → without_stub/general}/patterns.yml +0 -0
- {rasa_pro-3.14.0rc2.dist-info → rasa_pro-3.14.0rc3.dist-info}/NOTICE +0 -0
- {rasa_pro-3.14.0rc2.dist-info → rasa_pro-3.14.0rc3.dist-info}/WHEEL +0 -0
- {rasa_pro-3.14.0rc2.dist-info → rasa_pro-3.14.0rc3.dist-info}/entry_points.txt +0 -0
rasa/core/available_agents.py
CHANGED
|
@@ -9,7 +9,7 @@ from pydantic import BaseModel, Field, model_validator
|
|
|
9
9
|
from ruamel import yaml as yaml
|
|
10
10
|
|
|
11
11
|
from rasa.exceptions import ValidationError
|
|
12
|
-
from rasa.utils.
|
|
12
|
+
from rasa.shared.utils.yaml import read_config_file
|
|
13
13
|
|
|
14
14
|
DEFAULT_AGENTS_CONFIG_FOLDER = "sub_agents"
|
|
15
15
|
|
|
@@ -89,48 +89,68 @@ class AgentConfig(BaseModel):
|
|
|
89
89
|
connections: Optional[AgentConnections] = None
|
|
90
90
|
|
|
91
91
|
|
|
92
|
-
class AvailableAgents
|
|
92
|
+
class AvailableAgents:
|
|
93
93
|
"""Collection of configured agents."""
|
|
94
94
|
|
|
95
|
-
_instance = None
|
|
96
|
-
|
|
97
95
|
def __init__(self, agents: Optional[Dict[str, AgentConfig]] = None) -> None:
|
|
98
96
|
"""Create an `AvailableAgents` object."""
|
|
99
|
-
self.agents = agents or {}
|
|
97
|
+
self.agents: Dict[str, AgentConfig] = agents or {}
|
|
100
98
|
|
|
101
99
|
@classmethod
|
|
102
|
-
def
|
|
100
|
+
def read_from_folder(cls, sub_agents_folder: str) -> AvailableAgents:
|
|
103
101
|
"""Read the different agents from the given folder."""
|
|
104
102
|
agents: Dict[str, AgentConfig] = {}
|
|
105
103
|
|
|
106
|
-
if not os.path.isdir(
|
|
107
|
-
if
|
|
104
|
+
if not os.path.isdir(sub_agents_folder):
|
|
105
|
+
if sub_agents_folder != DEFAULT_AGENTS_CONFIG_FOLDER:
|
|
108
106
|
# User explicitly specified a folder, it should exist
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
f"
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
f"exist or is not a directory."
|
|
107
|
+
raise ValidationError(
|
|
108
|
+
code="agent.sub_agents_folder_not_found",
|
|
109
|
+
event_info=f"The specified agents config folder "
|
|
110
|
+
f"'{sub_agents_folder}' does not exist or is not a "
|
|
111
|
+
f"directory.",
|
|
112
|
+
details={"folder": sub_agents_folder},
|
|
116
113
|
)
|
|
117
114
|
else:
|
|
118
115
|
# We are using the default folder, it may not be created yet
|
|
119
116
|
# Init with an empty agents in this case
|
|
120
117
|
structlogger.info(
|
|
121
|
-
f"Default agents config folder '{
|
|
122
|
-
f"Agent configurations won't be loaded."
|
|
118
|
+
f"Default agents config folder '{sub_agents_folder}' does not "
|
|
119
|
+
f"exist. Agent configurations won't be loaded."
|
|
123
120
|
)
|
|
124
121
|
return cls(agents)
|
|
125
122
|
|
|
126
123
|
# First, load all agent configs into a temporary list for validation
|
|
127
124
|
agent_configs: List[AgentConfig] = []
|
|
128
|
-
for agent_name in os.listdir(
|
|
129
|
-
|
|
125
|
+
for agent_name in os.listdir(sub_agents_folder):
|
|
126
|
+
agent_folder = os.path.join(sub_agents_folder, agent_name)
|
|
127
|
+
if not os.path.isdir(agent_folder):
|
|
128
|
+
raise ValidationError(
|
|
129
|
+
code="agent.invalid_directory_structure",
|
|
130
|
+
event_info=f"Invalid structure: '{agent_folder}' is not a folder. "
|
|
131
|
+
f"Each agent must be stored in its own folder inside "
|
|
132
|
+
f"'{sub_agents_folder}'. Expected structure: "
|
|
133
|
+
f"{sub_agents_folder}/<agent_name>/config.yml",
|
|
134
|
+
details={
|
|
135
|
+
"agent_name": agent_name,
|
|
136
|
+
"sub_agents_folder": sub_agents_folder,
|
|
137
|
+
},
|
|
138
|
+
)
|
|
139
|
+
config_path = os.path.join(agent_folder, "config.yml")
|
|
130
140
|
if not os.path.isfile(config_path):
|
|
131
|
-
|
|
141
|
+
raise ValidationError(
|
|
142
|
+
code="agent.missing_config_file",
|
|
143
|
+
event_info=f"Missing config file for agent '{agent_name}'. "
|
|
144
|
+
f"Expected file: '{config_path}'. "
|
|
145
|
+
f"Each agent folder must contain a 'config.yml' file.",
|
|
146
|
+
details={
|
|
147
|
+
"agent_name": agent_name,
|
|
148
|
+
"expected_config_file": config_path,
|
|
149
|
+
"sub_agents_folder": sub_agents_folder,
|
|
150
|
+
},
|
|
151
|
+
)
|
|
132
152
|
try:
|
|
133
|
-
agent_config = cls.
|
|
153
|
+
agent_config = cls._read_agent_config_file(config_path)
|
|
134
154
|
if not isinstance(agent_config, AgentConfig):
|
|
135
155
|
raise ValueError(f"Invalid agent config type for {agent_name}")
|
|
136
156
|
agent_configs.append(agent_config)
|
|
@@ -140,7 +160,7 @@ class AvailableAgents(metaclass=Singleton):
|
|
|
140
160
|
event_info=f"Failed to load agent '{agent_name}': {e}",
|
|
141
161
|
details={
|
|
142
162
|
"agent_name": agent_name,
|
|
143
|
-
"
|
|
163
|
+
"sub_agents_folder": sub_agents_folder,
|
|
144
164
|
"error": str(e),
|
|
145
165
|
},
|
|
146
166
|
)
|
|
@@ -153,27 +173,23 @@ class AvailableAgents(metaclass=Singleton):
|
|
|
153
173
|
for agent_config in agent_configs:
|
|
154
174
|
agents[agent_config.agent.name] = agent_config
|
|
155
175
|
|
|
176
|
+
structlogger.info(f"Loaded agent configs: {[k for k in agents.keys()]}")
|
|
156
177
|
return cls(agents)
|
|
157
178
|
|
|
158
179
|
@staticmethod
|
|
159
|
-
def
|
|
160
|
-
"""
|
|
180
|
+
def from_dict(data: Dict[str, Any]) -> AgentConfig:
|
|
181
|
+
"""Parse the agent config from raw data into Pydantic models.
|
|
161
182
|
|
|
162
183
|
Args:
|
|
163
|
-
|
|
184
|
+
data: Raw data from the config file as a dictionary.
|
|
164
185
|
|
|
165
186
|
Returns:
|
|
166
|
-
The parsed AgentConfig.
|
|
187
|
+
The parsed AgentConfig as a Pydantic model.
|
|
167
188
|
|
|
168
189
|
Raises:
|
|
169
|
-
yaml.YAMLError: If the YAML file is invalid.
|
|
170
190
|
ValueError: If the data structure is invalid for Pydantic models.
|
|
171
191
|
"""
|
|
172
|
-
|
|
173
|
-
data = yaml.safe_load(f)
|
|
174
|
-
|
|
175
|
-
# Create the agent config (this will trigger Pydantic validation)
|
|
176
|
-
agent_config = AgentConfig(
|
|
192
|
+
return AgentConfig(
|
|
177
193
|
agent=AgentInfo(**data.get("agent", {})),
|
|
178
194
|
configuration=AgentConfiguration(**data.get("configuration", {}))
|
|
179
195
|
if data.get("configuration")
|
|
@@ -183,24 +199,22 @@ class AvailableAgents(metaclass=Singleton):
|
|
|
183
199
|
else None,
|
|
184
200
|
)
|
|
185
201
|
|
|
186
|
-
return agent_config
|
|
187
|
-
|
|
188
202
|
@classmethod
|
|
189
|
-
def
|
|
190
|
-
|
|
191
|
-
) -> AvailableAgents:
|
|
192
|
-
"""Get the singleton instance of `AvailableAgents`."""
|
|
193
|
-
if cls._instance is None:
|
|
194
|
-
cls._instance = cls._read_agent_folder(agent_folder)
|
|
203
|
+
def _read_agent_config_file(cls, config_path: str) -> AgentConfig:
|
|
204
|
+
"""Read the agent config from a yaml file into Pydantic models.
|
|
195
205
|
|
|
196
|
-
|
|
206
|
+
Args:
|
|
207
|
+
config_path: Path to the config file.
|
|
197
208
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
209
|
+
Returns:
|
|
210
|
+
The parsed AgentConfig.
|
|
211
|
+
|
|
212
|
+
Raises:
|
|
213
|
+
yaml.YAMLError: If the YAML file is invalid.
|
|
214
|
+
ValidationError: If the data structure is invalid for Pydantic models.
|
|
215
|
+
"""
|
|
216
|
+
data = read_config_file(config_path)
|
|
217
|
+
return cls.from_dict(data)
|
|
204
218
|
|
|
205
219
|
def as_json_list(self) -> List[Dict[str, Any]]:
|
|
206
220
|
"""Convert the available agents to a JSON-serializable list."""
|
|
@@ -218,12 +232,8 @@ class AvailableAgents(metaclass=Singleton):
|
|
|
218
232
|
for agent_name, agent_config in self.agents.items()
|
|
219
233
|
]
|
|
220
234
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
instance = cls.get_instance()
|
|
224
|
-
return instance.agents.get(agent_id)
|
|
235
|
+
def get_agent_config(self, agent_id: str) -> Optional[AgentConfig]:
|
|
236
|
+
return self.agents.get(agent_id)
|
|
225
237
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
instance = cls.get_instance()
|
|
229
|
-
return len(instance.agents) > 0
|
|
238
|
+
def has_agents(self) -> bool:
|
|
239
|
+
return len(self.agents) > 0
|
|
@@ -94,12 +94,9 @@ class MCPServerConfig(BaseModel):
|
|
|
94
94
|
class AvailableEndpoints:
|
|
95
95
|
"""Collection of configured endpoints."""
|
|
96
96
|
|
|
97
|
-
_instance = None
|
|
98
|
-
|
|
99
97
|
@classmethod
|
|
100
98
|
def read_endpoints(cls, endpoint_file: Path) -> AvailableEndpoints:
|
|
101
99
|
"""Read the different endpoints from a yaml file."""
|
|
102
|
-
|
|
103
100
|
nlg = read_endpoint_config(endpoint_file, endpoint_type="nlg")
|
|
104
101
|
nlu = read_endpoint_config(endpoint_file, endpoint_type="nlu")
|
|
105
102
|
action = read_endpoint_config(endpoint_file, endpoint_type="action_endpoint")
|
|
@@ -7,6 +7,7 @@ from typing import Literal, Optional
|
|
|
7
7
|
import structlog
|
|
8
8
|
|
|
9
9
|
from rasa.cli.validation.config_path_validation import get_validated_path
|
|
10
|
+
from rasa.core.available_agents import DEFAULT_AGENTS_CONFIG_FOLDER, AvailableAgents
|
|
10
11
|
from rasa.core.config.available_endpoints import AvailableEndpoints
|
|
11
12
|
from rasa.core.config.credentials import CredentialsConfig
|
|
12
13
|
from rasa.core.config.message_procesing_config import MessageProcessingConfig
|
|
@@ -146,10 +147,12 @@ class Configuration:
|
|
|
146
147
|
def __init__(
|
|
147
148
|
self,
|
|
148
149
|
endpoints: AvailableEndpoints,
|
|
150
|
+
available_agents: AvailableAgents,
|
|
149
151
|
credentials: Optional[CredentialsConfig] = None,
|
|
150
152
|
message_processing_config: Optional[MessageProcessingConfig] = None,
|
|
151
153
|
):
|
|
152
154
|
self.credentials = credentials
|
|
155
|
+
self.available_agents = available_agents
|
|
153
156
|
self.endpoints = endpoints
|
|
154
157
|
self.message_processing_config = message_processing_config
|
|
155
158
|
|
|
@@ -159,6 +162,7 @@ class Configuration:
|
|
|
159
162
|
cls._instance = Configuration(
|
|
160
163
|
credentials=None,
|
|
161
164
|
endpoints=AvailableEndpoints(),
|
|
165
|
+
available_agents=AvailableAgents(),
|
|
162
166
|
message_processing_config=None,
|
|
163
167
|
)
|
|
164
168
|
return cls._instance
|
|
@@ -177,7 +181,10 @@ class Configuration:
|
|
|
177
181
|
)
|
|
178
182
|
if cls._instance is None:
|
|
179
183
|
cls._instance = Configuration(
|
|
180
|
-
endpoints=endpoints,
|
|
184
|
+
endpoints=endpoints,
|
|
185
|
+
available_agents=AvailableAgents(),
|
|
186
|
+
credentials=None,
|
|
187
|
+
message_processing_config=None,
|
|
181
188
|
)
|
|
182
189
|
else:
|
|
183
190
|
cls._instance.endpoints = endpoints
|
|
@@ -189,6 +196,7 @@ class Configuration:
|
|
|
189
196
|
if cls._instance is None:
|
|
190
197
|
cls._instance = Configuration(
|
|
191
198
|
endpoints=AvailableEndpoints(),
|
|
199
|
+
available_agents=AvailableAgents(),
|
|
192
200
|
credentials=None,
|
|
193
201
|
message_processing_config=None,
|
|
194
202
|
)
|
|
@@ -217,6 +225,7 @@ class Configuration:
|
|
|
217
225
|
message_processing_config=message_processing_config,
|
|
218
226
|
credentials=None,
|
|
219
227
|
endpoints=AvailableEndpoints(),
|
|
228
|
+
available_agents=AvailableAgents(),
|
|
220
229
|
)
|
|
221
230
|
else:
|
|
222
231
|
cls._instance.message_processing_config = message_processing_config
|
|
@@ -240,12 +249,37 @@ class Configuration:
|
|
|
240
249
|
cls._instance = Configuration(
|
|
241
250
|
credentials=credentials,
|
|
242
251
|
endpoints=AvailableEndpoints(),
|
|
252
|
+
available_agents=AvailableAgents(),
|
|
243
253
|
message_processing_config=None,
|
|
244
254
|
)
|
|
245
255
|
else:
|
|
246
256
|
cls._instance.credentials = credentials
|
|
247
257
|
return cls._instance
|
|
248
258
|
|
|
259
|
+
@classmethod
|
|
260
|
+
def initialise_sub_agents(cls, sub_agents_path: Optional[Path]) -> Configuration:
|
|
261
|
+
sub_agents_folder = (
|
|
262
|
+
str(sub_agents_path)
|
|
263
|
+
if sub_agents_path is not None
|
|
264
|
+
else DEFAULT_AGENTS_CONFIG_FOLDER
|
|
265
|
+
)
|
|
266
|
+
logger.debug(
|
|
267
|
+
"configuration.initialise_sub_agents.start",
|
|
268
|
+
sub_agents_folder=sub_agents_folder,
|
|
269
|
+
)
|
|
270
|
+
available_agents = AvailableAgents.read_from_folder(sub_agents_folder)
|
|
271
|
+
|
|
272
|
+
if cls._instance is None:
|
|
273
|
+
cls._instance = Configuration(
|
|
274
|
+
endpoints=AvailableEndpoints(),
|
|
275
|
+
available_agents=available_agents,
|
|
276
|
+
credentials=None,
|
|
277
|
+
message_processing_config=None,
|
|
278
|
+
)
|
|
279
|
+
else:
|
|
280
|
+
cls._instance.available_agents = available_agents
|
|
281
|
+
return cls._instance
|
|
282
|
+
|
|
249
283
|
@classmethod
|
|
250
284
|
def get_instance(cls) -> Configuration:
|
|
251
285
|
if cls._instance is None:
|
|
@@ -254,6 +288,7 @@ class Configuration:
|
|
|
254
288
|
"Call appropriate 'initialise' methods to "
|
|
255
289
|
"load the config when Rasa Pro starts: "
|
|
256
290
|
"initialise_endpoints(), "
|
|
291
|
+
"initialise_sub_agents(), "
|
|
257
292
|
"initialise_credentials(), "
|
|
258
293
|
"initialise_message_processing()"
|
|
259
294
|
)
|
|
@@ -16,7 +16,7 @@ from rasa.agents.constants import (
|
|
|
16
16
|
from rasa.agents.core.types import AgentStatus, ProtocolType
|
|
17
17
|
from rasa.agents.schemas import AgentInput, AgentOutput
|
|
18
18
|
from rasa.agents.schemas.agent_input import AgentInputSlot
|
|
19
|
-
from rasa.core.
|
|
19
|
+
from rasa.core.config.configuration import Configuration
|
|
20
20
|
from rasa.core.policies.flows.flow_step_result import (
|
|
21
21
|
ContinueFlowWithNextStep,
|
|
22
22
|
FlowActionPrediction,
|
|
@@ -47,12 +47,13 @@ from rasa.shared.core.events import (
|
|
|
47
47
|
AgentStarted,
|
|
48
48
|
Event,
|
|
49
49
|
SlotSet,
|
|
50
|
+
deserialise_events,
|
|
50
51
|
)
|
|
51
52
|
from rasa.shared.core.flows.steps import (
|
|
52
53
|
CallFlowStep,
|
|
53
54
|
)
|
|
54
55
|
from rasa.shared.core.slots import CategoricalSlot, Slot
|
|
55
|
-
from rasa.shared.core.trackers import DialogueStateTracker
|
|
56
|
+
from rasa.shared.core.trackers import DialogueStateTracker, EventVerbosity
|
|
56
57
|
from rasa.shared.utils.llm import tracker_as_readable_transcript
|
|
57
58
|
|
|
58
59
|
structlogger = structlog.get_logger()
|
|
@@ -61,8 +62,9 @@ MAX_AGENT_RETRIES = 3
|
|
|
61
62
|
|
|
62
63
|
|
|
63
64
|
def remove_agent_stack_frame(stack: DialogueStack, agent_id: str) -> None:
|
|
64
|
-
"""Finishes the agentic loop by popping the agent stack frame from
|
|
65
|
-
|
|
65
|
+
"""Finishes the agentic loop by popping the agent stack frame from provided `stack`.
|
|
66
|
+
|
|
67
|
+
The `tracker.stack` is NOT modified.
|
|
66
68
|
"""
|
|
67
69
|
agent_stack_frame = stack.find_agent_stack_frame_by_agent(agent_id)
|
|
68
70
|
if not agent_stack_frame:
|
|
@@ -136,7 +138,9 @@ async def run_agent(
|
|
|
136
138
|
final_events.append(AgentStarted(step.call, step.flow_id))
|
|
137
139
|
|
|
138
140
|
# send the input to the agent and wait for a response
|
|
139
|
-
protocol_type = get_protocol_type(
|
|
141
|
+
protocol_type = get_protocol_type(
|
|
142
|
+
step, Configuration.get_instance().available_agents.get_agent_config(step.call)
|
|
143
|
+
)
|
|
140
144
|
output: AgentOutput = await _call_agent_with_retry(
|
|
141
145
|
agent_name=step.call,
|
|
142
146
|
protocol_type=protocol_type,
|
|
@@ -471,8 +475,9 @@ def _create_action_prediction(
|
|
|
471
475
|
def _create_agent_request_user_input_prediction(
|
|
472
476
|
message: Optional[str], events: Optional[List[Event]]
|
|
473
477
|
) -> FlowActionPrediction:
|
|
474
|
-
"""Create a prediction for requesting user input from the agent
|
|
475
|
-
|
|
478
|
+
"""Create a prediction for requesting user input from the agent and waiting for it.
|
|
479
|
+
|
|
480
|
+
This function creates a prediction that will pause the flow and wait for user input.
|
|
476
481
|
"""
|
|
477
482
|
return _create_action_prediction(
|
|
478
483
|
ACTION_AGENT_REQUEST_USER_INPUT_NAME, message, events
|
|
@@ -529,7 +534,9 @@ def _prepare_agent_input(
|
|
|
529
534
|
tracker.current_slot_values(), slots, step.exit_if
|
|
530
535
|
),
|
|
531
536
|
conversation_history=tracker_as_readable_transcript(tracker),
|
|
532
|
-
events=
|
|
537
|
+
events=deserialise_events(
|
|
538
|
+
tracker.current_state(EventVerbosity.ALL).get("events") or []
|
|
539
|
+
),
|
|
533
540
|
metadata=agent_input_metadata,
|
|
534
541
|
)
|
|
535
542
|
|
|
@@ -550,6 +557,7 @@ def _prepare_slots_for_agent(
|
|
|
550
557
|
Args:
|
|
551
558
|
slot_values: The full slot dictionary from the tracker.
|
|
552
559
|
slot_definitions: The slot definitions from the domain.
|
|
560
|
+
exit_if: Optional list of exit conditions that determine which slots to keep.
|
|
553
561
|
|
|
554
562
|
Returns:
|
|
555
563
|
A list of slots containing the name, current value, type, and allowed values.
|
|
@@ -104,7 +104,10 @@ class StartFlowCommand(Command):
|
|
|
104
104
|
# predicted a start flow command for the flow which is on top of the stack,
|
|
105
105
|
# we just need to remove the pattern_continue_interrupted frame(s) from the
|
|
106
106
|
# stack
|
|
107
|
-
stack = remove_pattern_continue_interrupted_frames(
|
|
107
|
+
stack, flow_completed_events = remove_pattern_continue_interrupted_frames(
|
|
108
|
+
stack
|
|
109
|
+
)
|
|
110
|
+
applied_events.extend(flow_completed_events)
|
|
108
111
|
return applied_events + tracker.create_stack_updated_events(stack)
|
|
109
112
|
|
|
110
113
|
# if the flow is already on the stack, resume it
|
|
@@ -114,7 +117,10 @@ class StartFlowCommand(Command):
|
|
|
114
117
|
):
|
|
115
118
|
# if pattern_continue_interrupted is active, we need to remove it
|
|
116
119
|
# from the stack before resuming the flow
|
|
117
|
-
stack = remove_pattern_continue_interrupted_frames(
|
|
120
|
+
stack, flow_completed_events = remove_pattern_continue_interrupted_frames(
|
|
121
|
+
stack
|
|
122
|
+
)
|
|
123
|
+
applied_events.extend(flow_completed_events)
|
|
118
124
|
applied_events.extend(resume_flow(self.flow, tracker, stack))
|
|
119
125
|
# the current active flow is interrupted
|
|
120
126
|
applied_events.append(
|
|
@@ -128,7 +134,8 @@ class StartFlowCommand(Command):
|
|
|
128
134
|
|
|
129
135
|
# remove the pattern_continue_interrupted frames from the stack
|
|
130
136
|
# if it is currently active but the user digressed from the pattern
|
|
131
|
-
stack = remove_pattern_continue_interrupted_frames(stack)
|
|
137
|
+
stack, flow_completed_events = remove_pattern_continue_interrupted_frames(stack)
|
|
138
|
+
applied_events.extend(flow_completed_events)
|
|
132
139
|
|
|
133
140
|
if original_top_flow:
|
|
134
141
|
# if the original top flow is not the same as the flow to start,
|
|
@@ -19,6 +19,7 @@ from rasa.shared.constants import ACTION_ASK_PREFIX, UTTER_ASK_PREFIX
|
|
|
19
19
|
from rasa.shared.core.events import (
|
|
20
20
|
AgentResumed,
|
|
21
21
|
Event,
|
|
22
|
+
FlowCompleted,
|
|
22
23
|
FlowResumed,
|
|
23
24
|
SlotSet,
|
|
24
25
|
)
|
|
@@ -250,18 +251,28 @@ def collect_frames_to_resume(
|
|
|
250
251
|
return list(frames_to_resume), frame_to_resume
|
|
251
252
|
|
|
252
253
|
|
|
253
|
-
def remove_pattern_continue_interrupted_frames(
|
|
254
|
-
|
|
254
|
+
def remove_pattern_continue_interrupted_frames(
|
|
255
|
+
stack: DialogueStack,
|
|
256
|
+
) -> Tuple[DialogueStack, List[FlowCompleted]]:
|
|
257
|
+
"""Remove pattern_continue_interrupted frames from the stack and return events.
|
|
258
|
+
|
|
259
|
+
Returns:
|
|
260
|
+
A tuple containing (updated_stack, flow_completed_events)
|
|
261
|
+
"""
|
|
255
262
|
from rasa.dialogue_understanding.stack.utils import (
|
|
256
263
|
is_continue_interrupted_flow_active,
|
|
257
264
|
)
|
|
258
265
|
|
|
259
266
|
if not is_continue_interrupted_flow_active(stack):
|
|
260
|
-
return stack
|
|
267
|
+
return stack, []
|
|
261
268
|
|
|
269
|
+
events = []
|
|
262
270
|
# remove pattern_continue_interrupted from the stack
|
|
263
271
|
top_frame = stack.top()
|
|
264
272
|
while isinstance(top_frame, PatternFlowStackFrame):
|
|
273
|
+
# Create FlowCompleted event for the pattern frame being removed
|
|
274
|
+
events.append(FlowCompleted(top_frame.flow_id, top_frame.step_id))
|
|
275
|
+
|
|
265
276
|
# If the top frame is a pattern frame, we need to remove it
|
|
266
277
|
# before continuing with the active user flow frame.
|
|
267
278
|
# This prevents the pattern frame
|
|
@@ -271,4 +282,4 @@ def remove_pattern_continue_interrupted_frames(stack: DialogueStack) -> Dialogue
|
|
|
271
282
|
stack.pop()
|
|
272
283
|
top_frame = stack.top()
|
|
273
284
|
|
|
274
|
-
return stack
|
|
285
|
+
return stack, events
|
|
@@ -7,7 +7,7 @@ from jinja2 import Environment, Template, select_autoescape
|
|
|
7
7
|
|
|
8
8
|
import rasa.dialogue_understanding.generator.utils
|
|
9
9
|
import rasa.shared.utils.io
|
|
10
|
-
from rasa.core.
|
|
10
|
+
from rasa.core.config.configuration import Configuration
|
|
11
11
|
from rasa.dialogue_understanding.commands import (
|
|
12
12
|
Command,
|
|
13
13
|
SetSlotCommand,
|
|
@@ -398,7 +398,9 @@ class LLMBasedCommandGenerator(
|
|
|
398
398
|
if isinstance(event, AgentStarted) and event.flow_id == flow.id
|
|
399
399
|
]
|
|
400
400
|
available_agents = [
|
|
401
|
-
|
|
401
|
+
Configuration.get_instance().available_agents.get_agent_config(
|
|
402
|
+
event.agent_id
|
|
403
|
+
)
|
|
402
404
|
for event in agent_events
|
|
403
405
|
]
|
|
404
406
|
if available_agents:
|
|
@@ -2,7 +2,7 @@ from typing import Any, Dict, Literal, Optional, Text
|
|
|
2
2
|
|
|
3
3
|
import structlog
|
|
4
4
|
|
|
5
|
-
from rasa.core.
|
|
5
|
+
from rasa.core.config.configuration import Configuration
|
|
6
6
|
from rasa.dialogue_understanding.commands.command_syntax_manager import (
|
|
7
7
|
CommandSyntaxVersion,
|
|
8
8
|
)
|
|
@@ -125,7 +125,7 @@ class CompactLLMCommandGenerator(SingleStepBasedLLMCommandGenerator):
|
|
|
125
125
|
"""Get the default prompt template file name for the command generator."""
|
|
126
126
|
return (
|
|
127
127
|
AGENT_DEFAULT_COMMAND_PROMPT_TEMPLATE_FILE_NAME
|
|
128
|
-
if
|
|
128
|
+
if Configuration.get_instance().available_agents.has_agents()
|
|
129
129
|
else DEFAULT_COMMAND_PROMPT_TEMPLATE_FILE_NAME
|
|
130
130
|
)
|
|
131
131
|
|
|
@@ -134,7 +134,7 @@ class CompactLLMCommandGenerator(SingleStepBasedLLMCommandGenerator):
|
|
|
134
134
|
"""Get the fallback prompt template file name for the command generator."""
|
|
135
135
|
return (
|
|
136
136
|
AGENT_FALLBACK_COMMAND_PROMPT_TEMPLATE_FILE_NAME
|
|
137
|
-
if
|
|
137
|
+
if Configuration.get_instance().available_agents.has_agents()
|
|
138
138
|
else FALLBACK_COMMAND_PROMPT_TEMPLATE_FILE_NAME
|
|
139
139
|
)
|
|
140
140
|
|
|
@@ -143,7 +143,7 @@ class CompactLLMCommandGenerator(SingleStepBasedLLMCommandGenerator):
|
|
|
143
143
|
"""Get the model prompt mapper for the command generator."""
|
|
144
144
|
return (
|
|
145
145
|
AGENT_MODEL_PROMPT_MAPPER
|
|
146
|
-
if
|
|
146
|
+
if Configuration.get_instance().available_agents.has_agents()
|
|
147
147
|
else MODEL_PROMPT_MAPPER
|
|
148
148
|
)
|
|
149
149
|
|
|
@@ -2,7 +2,7 @@ from typing import Any, Dict, Literal, Optional, Text
|
|
|
2
2
|
|
|
3
3
|
import structlog
|
|
4
4
|
|
|
5
|
-
from rasa.core.
|
|
5
|
+
from rasa.core.config.configuration import Configuration
|
|
6
6
|
from rasa.dialogue_understanding.commands.command_syntax_manager import (
|
|
7
7
|
CommandSyntaxVersion,
|
|
8
8
|
)
|
|
@@ -127,7 +127,7 @@ class SearchReadyLLMCommandGenerator(SingleStepBasedLLMCommandGenerator):
|
|
|
127
127
|
"""Get the default prompt template file name for the command generator."""
|
|
128
128
|
return (
|
|
129
129
|
AGENT_DEFAULT_COMMAND_PROMPT_TEMPLATE_FILE_NAME
|
|
130
|
-
if
|
|
130
|
+
if Configuration.get_instance().available_agents.has_agents()
|
|
131
131
|
else DEFAULT_COMMAND_PROMPT_TEMPLATE_FILE_NAME
|
|
132
132
|
)
|
|
133
133
|
|
|
@@ -136,7 +136,7 @@ class SearchReadyLLMCommandGenerator(SingleStepBasedLLMCommandGenerator):
|
|
|
136
136
|
"""Get the fallback prompt template file name for the command generator."""
|
|
137
137
|
return (
|
|
138
138
|
AGENT_FALLBACK_COMMAND_PROMPT_TEMPLATE_FILE_NAME
|
|
139
|
-
if
|
|
139
|
+
if Configuration.get_instance().available_agents.has_agents()
|
|
140
140
|
else FALLBACK_COMMAND_PROMPT_TEMPLATE_FILE_NAME
|
|
141
141
|
)
|
|
142
142
|
|
|
@@ -145,7 +145,7 @@ class SearchReadyLLMCommandGenerator(SingleStepBasedLLMCommandGenerator):
|
|
|
145
145
|
"""Get the model prompt mapper for the command generator."""
|
|
146
146
|
return (
|
|
147
147
|
AGENT_MODEL_PROMPT_MAPPER
|
|
148
|
-
if
|
|
148
|
+
if Configuration.get_instance().available_agents.has_agents()
|
|
149
149
|
else MODEL_PROMPT_MAPPER
|
|
150
150
|
)
|
|
151
151
|
|
rasa/dialogue_understanding/generator/single_step/single_step_based_llm_command_generator.py
CHANGED
|
@@ -9,7 +9,7 @@ from rasa.agents.utils import (
|
|
|
9
9
|
get_active_agent_info,
|
|
10
10
|
get_completed_agents_info,
|
|
11
11
|
)
|
|
12
|
-
from rasa.core.
|
|
12
|
+
from rasa.core.config.configuration import Configuration
|
|
13
13
|
from rasa.dialogue_understanding.commands import (
|
|
14
14
|
CannotHandleCommand,
|
|
15
15
|
Command,
|
|
@@ -403,7 +403,7 @@ class SingleStepBasedLLMCommandGenerator(LLMBasedCommandGenerator, ABC):
|
|
|
403
403
|
current_slot_allowed_values = allowed_values_for_slot(
|
|
404
404
|
tracker.slots.get(current_slot)
|
|
405
405
|
)
|
|
406
|
-
has_agents =
|
|
406
|
+
has_agents = Configuration.get_instance().available_agents.has_agents()
|
|
407
407
|
current_conversation = tracker_as_readable_transcript(
|
|
408
408
|
tracker, highlight_agent_turns=has_agents
|
|
409
409
|
)
|
|
@@ -6,9 +6,9 @@ from typing import Any, Dict, List, Optional, Union
|
|
|
6
6
|
import structlog
|
|
7
7
|
from tqdm import tqdm
|
|
8
8
|
|
|
9
|
-
from rasa.core.available_agents import AvailableAgents
|
|
10
9
|
from rasa.core.channels import CollectingOutputChannel, UserMessage
|
|
11
10
|
from rasa.core.config.available_endpoints import AvailableEndpoints
|
|
11
|
+
from rasa.core.config.configuration import Configuration
|
|
12
12
|
from rasa.core.exceptions import AgentNotReady
|
|
13
13
|
from rasa.core.persistor import StorageType
|
|
14
14
|
from rasa.dialogue_understanding.commands import Command
|
|
@@ -71,7 +71,7 @@ class DialogueUnderstandingTestRunner:
|
|
|
71
71
|
import rasa.core.agent
|
|
72
72
|
|
|
73
73
|
self._check_action_server(endpoints)
|
|
74
|
-
sub_agents =
|
|
74
|
+
sub_agents = Configuration.get_instance().available_agents
|
|
75
75
|
|
|
76
76
|
self.agent = asyncio.run(
|
|
77
77
|
rasa.core.agent.load_agent(
|
rasa/e2e_test/e2e_test_runner.py
CHANGED
|
@@ -13,9 +13,9 @@ import structlog
|
|
|
13
13
|
from tqdm import tqdm
|
|
14
14
|
|
|
15
15
|
import rasa.shared.utils.io
|
|
16
|
-
from rasa.core.available_agents import AvailableAgents
|
|
17
16
|
from rasa.core.channels import CollectingOutputChannel, UserMessage
|
|
18
17
|
from rasa.core.config.available_endpoints import AvailableEndpoints
|
|
18
|
+
from rasa.core.config.configuration import Configuration
|
|
19
19
|
from rasa.core.constants import ACTIVE_FLOW_METADATA_KEY, STEP_ID_METADATA_KEY
|
|
20
20
|
from rasa.core.exceptions import AgentNotReady
|
|
21
21
|
from rasa.core.persistor import StorageType
|
|
@@ -96,7 +96,7 @@ class E2ETestRunner:
|
|
|
96
96
|
if endpoints and not are_custom_actions_stubbed:
|
|
97
97
|
self._action_server_is_reachable(endpoints)
|
|
98
98
|
|
|
99
|
-
sub_agents =
|
|
99
|
+
sub_agents = Configuration.get_instance().available_agents
|
|
100
100
|
|
|
101
101
|
self.agent = asyncio.run(
|
|
102
102
|
rasa.core.agent.load_agent(
|