Skip to content

Commit 0cc419d

Browse files
authored
Prompt user to click Rerun if empty (#1215)
1 parent db662ff commit 0cc419d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lumen/ai/agents.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,16 @@ class AnalystAgent(ChatAgent):
294294

295295
requires = param.List(default=["source", "pipeline"], readonly=True)
296296

297+
async def respond(
298+
self,
299+
messages: list[Message],
300+
render_output: bool = False,
301+
step_title: str | None = None,
302+
) -> Any:
303+
messages = super().respond(messages, render_output, step_title)
304+
if len(self._memory["data"]) == 0 and self._memory.get("sql"):
305+
self._memory["sql"] = f"{self._memory['sql']}\n-- No data was returned from the query."
306+
return messages
297307

298308
class ListAgent(Agent):
299309
"""

lumen/ai/prompts/AnalystAgent/main.jinja2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ Here was the plan that was executed:
9191
"""
9292

9393
Here is the current dataset:
94+
{% if memory.data|length == 0 %}
95+
The data is empty. Critique the SQL query and suggest what other columns or values should be used instead. Then prompt the user to click the rerun button below if they'd like to try again.
96+
{% else %}
9497
{{ memory.data }}
98+
{% endif %}
9599

96100
{% if 'sql' in memory %}
97101
Here is the current SQL query:

0 commit comments

Comments
 (0)