Skip to content
Open
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
16 changes: 12 additions & 4 deletions burr/core/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,10 +1296,12 @@ def iterate(

result = None
prior_action: Optional[Action] = None
step_inputs = inputs
while self.has_next_action():
# self.step will only return None if there is no next action, so we can rely on tuple unpacking
prior_action, result, state = self.step(inputs=inputs)
prior_action, result, state = self.step(inputs=step_inputs)
yield prior_action, result, state
step_inputs = {}
if self._should_halt_iterate(halt_before, halt_after, prior_action):
break
return self._return_value_iterate(halt_before, halt_after, prior_action, result)
Expand Down Expand Up @@ -1328,10 +1330,12 @@ async def aiterate(
halt_before, halt_after, inputs
)
self._validate_halt_conditions(halt_before, halt_after)
step_inputs = inputs
while self.has_next_action():
# self.step will only return None if there is no next action, so we can rely on tuple unpacking
prior_action, result, state = await self.astep(inputs=inputs)
prior_action, result, state = await self.astep(inputs=step_inputs)
yield prior_action, result, state
step_inputs = {}
if self._should_halt_iterate(halt_before, halt_after, prior_action):
break

Expand Down Expand Up @@ -1951,14 +1955,16 @@ def stream_iterate(
halt_before, halt_after, inputs
)
self._validate_halt_conditions(halt_before, halt_after)
step_inputs = inputs
while self.has_next_action():
next_action = self.get_next_action()
_, streaming_result = self.stream_result(
halt_after=[next_action.name], halt_before=None, inputs=inputs
halt_after=[next_action.name], halt_before=None, inputs=step_inputs
)
yield next_action, streaming_result
# We need to ensure it's fully exhausted before going to the next action
streaming_result.get()
step_inputs = {}
if self._should_halt_iterate(halt_before, halt_after, next_action):
break

Expand Down Expand Up @@ -1988,14 +1994,16 @@ async def astream_iterate(
halt_before, halt_after, inputs
)
self._validate_halt_conditions(halt_before, halt_after)
step_inputs = inputs
while self.has_next_action():
next_action = self.get_next_action()
_, streaming_result = await self.astream_result( # Use astream_result
halt_after=[next_action.name], halt_before=None, inputs=inputs
halt_after=[next_action.name], halt_before=None, inputs=step_inputs
)
yield next_action, streaming_result
# We need to ensure it's fully exhausted before going to the next action
await streaming_result.get() # await the get call
step_inputs = {}
if self._should_halt_iterate(halt_before, halt_after, next_action):
break

Expand Down
4 changes: 2 additions & 2 deletions docs/concepts/human-in-the-loop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ read from state; they come from the caller:

If both could apply, ``halt_before`` wins. ``run`` always executes at least one action
before it checks halt conditions, then ``inputs`` apply only to that first action. Later
actions in the same ``run`` that also need ``inputs`` are undefined -- halt before those
instead, and pass their values on the next ``run``.
actions in the same ``run`` receive no external inputs -- halt before those instead, and
pass their values on the next ``run``.

You can pass action names or tags (``"@tag:needs_human"``). The same halt arguments work
on ``iterate`` / ``arun`` / ``aiterate``. Details are in :ref:`Applications <applications>`.
Expand Down
Loading