Skip to content

Commit

Permalink
Ability to break while loops (#821)
Browse files Browse the repository at this point in the history
Co-authored-by: Philipp Rudiger <prudiger@anaconda.com>
  • Loading branch information
ahuang11 and philippjfr authored Dec 7, 2024
1 parent 1e74490 commit 24cdf52
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lumen/ai/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ async def respond(
self.interface.send(source_controls, respond=False, user="SourceAgent")
while not source_controls._add_button.clicks > 0:
await asyncio.sleep(0.05)
if source_controls._cancel_button.clicks > 0:
self.interface.undo()
return None
return source_controls


Expand Down
11 changes: 11 additions & 0 deletions lumen/ai/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class SourceControls(Viewer):

add = param.Event(doc="Use table(s)")

cancel = param.Event(doc="Cancel")

memory = param.ClassSelector(class_=_Memory, default=None, doc="""
Local memory which will be used to provide the agent context.
If None the global memory will be used.""")
Expand Down Expand Up @@ -126,9 +128,18 @@ def __init__(self, **params):
visible=False,
button_type="success",
)

self._cancel_button = Button.from_param(
self.param.cancel,
name="Cancel",
icon="circle-x",
visible=True,
)

self.menu = Column(
self._input_tabs if self.select_existing else self._input_tabs[0],
self._add_button,
self._cancel_button,
self.tables_tabs,
sizing_mode="stretch_width",
)
Expand Down
4 changes: 4 additions & 0 deletions lumen/ai/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ async def _compute_execution_graph(self, messages: list[Message], agents: dict[s
unmet_dependencies = set()
schemas = {}
execution_graph = []
attempts = 0
with self.interface.add_step(title="Planning how to solve user query...", user="Assistant") as istep:
while not planned:
try:
Expand All @@ -699,8 +700,11 @@ async def _compute_execution_graph(self, messages: list[Message], agents: dict[s
execution_graph, unmet_dependencies = await self._resolve_plan(plan, agents, messages)
if unmet_dependencies:
istep.stream(f"The plan didn't account for {unmet_dependencies!r}", replace=True)
attempts += 1
else:
planned = True
if attempts > 5:
raise ValueError(f"Could not find a suitable plan for {messages[-1]['content']!r}")
self._memory['plan'] = plan
istep.stream('\n\nHere are the steps:\n\n')
for i, step in enumerate(plan.steps):
Expand Down

0 comments on commit 24cdf52

Please sign in to comment.