Skip to content

armgit / burr

Public Imported from GitHub
0

Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.

Adds inputs and changes API for run & iterate

Stefan Krawczyk93cf54853205
diff --git a/burr/core/application.py b/burr/core/application.py
index a4147550..da82f76e 100644
--- a/burr/core/application.py
+++ b/burr/core/application.py
@@ -303,98 +303,98 @@ class Application:
def iterate(
self,
*,
- until: list[str],
- gate: TerminationCondition = "any_complete",
+ halt_before: list[str] = None,
+ halt_after: list[str] = None,
inputs: Optional[Dict[str, Any]] = None,
- ) -> Generator[Tuple[Action, dict, State], None, Tuple[State, List[dict]]]:
+ ) -> Generator[Tuple[Action, dict, State], None, Tuple[Action, Optional[dict], State]]:
"""Returns a generator that calls step() in a row, enabling you to see the state
of the system as it updates. Note this returns a generator, and also the final result
(for convenience).
- :param until: The list of actions to run until -- these must be strings
- that match the names of the actions.
- :param gate: The gate to run until. This can be "any_complete" or "all_complete"
+ :param halt_before: The list of actions to halt before execution of. It will halt on the first one.
+ :param halt_after: The list of actions to halt after execution of. It will halt on the first one.
:param inputs: Inputs to the action -- this is if this action requires an input that is passed in from the outside world.
Note that this is only used for the first iteration -- subsequent iterations will not use this.
:return: Each iteration returns the result of running `step`
- The final result is the current state + results in the order that they were specified.
+ The final result is the action, result, current state,
"""
+ if not halt_before and not halt_after:
+ logger.warning("No halt termination specified -- running forever!")
if inputs is None:
inputs = {}
-
- if gate != "any_complete":
- raise NotImplementedError(
- "Only any_complete is supported for now -- "
- "please reach out to the developers to unblock other gate types!"
- )
-
- results: List[Optional[dict]] = [None for _ in until]
- index_by_name = {name: index for index, name in enumerate(until)}
- seen_results = set()
-
- condition = (
- lambda: any(item in seen_results for item in until)
- if gate == "any_complete"
- else lambda: len(seen_results) == len(until)
- )
-
- while not condition():
+ result = None
+ action: Optional[Action] = None
+ while True:
state_output = self.step(inputs=inputs)
inputs = {} # only pass inputs in the first time
if state_output is None:
break
action, result, state = state_output
- if action.name in until:
- seen_results.add(action.name)
- results[index_by_name[action.name]] = result
yield action, result, state
- return self._state, results
+ if (
+ halt_before
+ and self.get_next_action()
+ and self.get_next_action().name in halt_before
+ ):
+ break
+ elif halt_after and action and action.name in halt_after:
+ break
+
+ if action and halt_after and action.name in halt_after:
+ return action, result, self._state
+ elif self.get_next_action() and halt_before and self.get_next_action().name in halt_before:
+ return self.get_next_action(), None, self._state
+ return action, result, self._state
async def aiterate(
self,
*,
- until: list[str],
- gate: TerminationCondition = "any_complete",
+ halt_before: list[str] = None,
+ halt_after: list[str] = None,
inputs: Optional[Dict[str, Any]] = None,
- ) -> AsyncGenerator[Tuple[Action, dict, State], Tuple[State, List[dict]]]:
+ ) -> AsyncGenerator[Tuple[Action, dict, State], Tuple[Action, Optional[dict], State]]:
"""Returns a generator that calls step() in a row, enabling you to see the state
of the system as it updates. This is the asynchronous version so it has no capability of t
- :param until: The list of actions to run until -- these must be strings
- that match the names of the action.
- :param gate: The gate to run until. This can be "any_complete" or "all_complete"
+ :param halt_before: The list of actions to halt before execution of. It will halt on the first one.
+ :param halt_after: The list of actions to halt after execution of. It will halt on the first one.
:param inputs: Inputs to the action -- this is if this action requires an input that is passed in from the outside world.
Note that this is only used for the first iteration -- subsequent iterations will not use this.
:return: Each iteration returns the result of running `step`
- The final result is the current state + results in the order that they were specified.
+ The final result is the action, result, current state,
"""
-
- seen_results = set()
- condition = (
- lambda: any(item in seen_results for item in until)
- if gate == "any_complete"
- else lambda: len(seen_results) == len(until)
- )
+ if not halt_before and not halt_after:
+ logger.warning("No halt termination specified -- running forever!")
if inputs is None:
inputs = {}
- while not condition():
- result = await self.astep(inputs=inputs)
+ while True:
+ step_result = await self.astep(inputs=inputs)
inputs = {} # only pass inputs in the first time
- if result is None:
+ if step_result is None:
break
- action, result, state = result
- if action.name in until:
- seen_results.add(action.name)
+ action, result, state = step_result
yield action, result, state
+ if (
+ halt_before
+ and self.get_next_action()
+ and self.get_next_action().name in halt_before
+ ):
+ yield self.get_next_action(), None, self._state
+ # we don't need to go around the loop again.
+ break
+ elif halt_after and action and action.name in halt_after:
+ # we've already yielded where we want to stop
+ # and we don't want to yield the same thing twice -- and there's no return in async generators
+ break
def run(
self,
*,
- until: list[str],
- gate: TerminationCondition = "any_complete",
+ halt_before: list[str] = None,
+ halt_after: list[str] = None,
inputs: Optional[Dict[str, Any]] = None,
- ) -> Tuple[State, List[dict]]:
+ ) -> Tuple[Action, Optional[dict], State]:
"""Runs your application through until completion. Does
not give access to the state along the way -- if you want that, use iterate().
@@ -403,7 +403,7 @@ class Application:
:param gate: Gate to run until -- only accepts "any_complete" for now
:return: The final state, and the results of running the actions in the order that they were specified.
"""
- gen = self.iterate(until=until, gate=gate, inputs=inputs)
+ gen = self.iterate(halt_before=halt_before, halt_after=halt_after, inputs=inputs)
while True:
try:
next(gen)
@@ -413,25 +413,26 @@ class Application:
async def arun(
self,
*,
- until: list[str],
- gate: TerminationCondition = "any_complete",
+ halt_before: list[str] = None,
+ halt_after: list[str] = None,
inputs: Optional[Dict[str, Any]] = None,
- ):
+ ) -> Tuple[Action, Optional[dict], State]:
"""Runs your application through until completion, using async. Does
not give access to the state along the way -- if you want that, use iterate().
- :param until: The list of actions to run until -- these must be strings
+ :param halt_before: The list of actions to halt before execution of. It will halt on the first one.
+ :param halt_after: The list of actions to halt after execution of. It will halt on the first one.
:param inputs: Inputs to the action -- this is if this action requires an input that is passed in from the outside world
- :param gate: Gate to run until -- only accepts "any_complete" for now
:return: The final state, and the results of running the actions in the order that they were specified.
"""
state = self._state
- results: List[Optional[dict]] = [None for _ in until]
- index_by_name = {name: index for index, name in enumerate(until)}
- async for action, result, state in self.aiterate(until=until, gate=gate, inputs=inputs):
- if action.name in until:
- results[index_by_name[action.name]] = result
- return state, results
+ action = None
+ result = None
+ async for action, result, state in self.aiterate(
+ halt_before=halt_before, halt_after=halt_after, inputs=inputs
+ ):
+ pass
+ return action, result, state
def visualize(
self,
diff --git a/docs/concepts/state-machine.rst b/docs/concepts/state-machine.rst
index 1afa033b..a7484d60 100644
--- a/docs/concepts/state-machine.rst
+++ b/docs/concepts/state-machine.rst
@@ -67,7 +67,7 @@ Iterate just runs ``step`` in a row, functioning as a generator:
.. code-block:: python
- for action, result, state in application.iterate(until=["final_action_1", "final_action_2"]):
+ for action, result, state in application.iterate(halt_after=["final_action_1", "final_action_2"]):
print(action.name, result)
You can also run ``aiterate`` in an async context:
@@ -78,8 +78,10 @@ You can also run ``aiterate`` in an async context:
print(action.name, result)
In the synchronous context this also has a return value of a tuple of:
-1. the final state
-2. A list of the actions that were run, one for each result
+1. the action that was specified in `halt_after` or `halt_before`. In the `after` case the action will have already run.
+In the `before` case the action will not have run.
+2. The result of the action, in the `halt_after` case, else None in the `halt_before` case.
+3. The state of the application at the time of halting.
You can access this by looking at the ``value`` variable of the ``StopIteration`` exception that is thrown
at the end of the loop, as is standard for python.
@@ -98,19 +100,20 @@ In the async context, this does not return anything
Run just calls out to ``iterate`` and returns the final state.
-The ``until`` variable is a ``or`` gate (E.G. ``any_complete``), although we will be adding an ``and`` gate (E.G. ``all_complete``),
-and the ability to run until the state machine naturally executes (``until=None``).
+The ``halt_after`` and ``halt_before`` keyword arguments specify when to break out of running the state machine
+and return control back. ``halt_after`` will stop after the specified action(s) has run, and ``halt_before`` will stop before the specified action(s) has run.
+If multiple are specified, it will stop after the first one encountered, and the return values will be for that action.
.. code-block:: python
- final_state, results = application.run(until=["final_action_1", "final_action_2"])
+ final_state, results = application.run(halt_after=["final_action_1", "final_action_2"])
In the async context, you can run ``arun``:
.. code-block:: python
- final_state = await application.arun(until=["final_action_1", "final_action_2"])
+ final_state = await application.arun(halt_after=["final_action_1", "final_action_2"])
.. note::
You can add inputs to ``run``/``arun`` in the same way as you can with ``iterate`` -- it will only apply to the first action.
diff --git a/docs/getting_started/simple-example.rst b/docs/getting_started/simple-example.rst
index 98b93dd7..af2b091e 100644
--- a/docs/getting_started/simple-example.rst
+++ b/docs/getting_started/simple-example.rst
@@ -79,7 +79,7 @@ Finally, we can run the application:
.. code-block:: python
- app.run(until=["printer"])
+ app.run(halt_after=["printer"])
If you want to copy/paste, you can open up the following code block and add to a file called ``run.py``:
@@ -126,7 +126,7 @@ If you want to copy/paste, you can open up the following code block and add to a
.build()
)
app.visualize("./graph", format="png", include_conditions=True, include_state=True)
- app.run(until=["printer"])
+ app.run(halt_after=["printer"])
And the output looks exactly as we expect!
diff --git a/examples/conversational-rag/application.py b/examples/conversational-rag/application.py
index 0c302607..b051c445 100644
--- a/examples/conversational-rag/application.py
+++ b/examples/conversational-rag/application.py
@@ -1,5 +1,6 @@
from typing import Tuple
+import burr.core
from burr.core import Action, ApplicationBuilder, State, default, expr
from burr.core.action import action
from burr.lifecycle import PostRunStepHook
@@ -16,6 +17,8 @@ converasation_rag_dr = (
class PrintStepHook(PostRunStepHook):
+ """Custom hook to print the state and action after each step."""
+
def post_run_step(self, *, state: "State", action: "Action", **future_kwargs):
print("action=====\n", action)
print("state======\n", state)
@@ -35,36 +38,35 @@ def ai_converse(state: State) -> Tuple[dict, State]:
"chat_history": state["chat_history"],
},
)
- new_history = f"Human: {state['question']}\nAI: {result['conversational_rag_response']}"
+ new_history = f"AI: {result['conversational_rag_response']}"
return result, state.append(chat_history=new_history)
-# procedural way to do this
@action(
- reads=["chat_history"],
- writes=["question"],
+ reads=[],
+ writes=["question", "chat_history"],
)
-def human_converse(state: State) -> Tuple[dict, State]:
- user_question = input("What is your next question: ")
- return {"question": user_question}, state.update(question=user_question)
+def human_converse(state: State, user_question: str) -> Tuple[dict, State]:
+ state = state.update(question=user_question).append(chat_history=f"Human: {user_question}")
+ return {"question": user_question}, state
@action(
- reads=["question"],
- writes=["question"],
+ reads=[],
+ writes=["question", "chat_history"],
)
-def human_converse_placeholder(state: State) -> Tuple[dict, State]:
- user_question = state["question"]
+def human_converse_input(state: State) -> Tuple[dict, State]:
+ user_question = input("What is your question?: ")
+ state = state.update(question=user_question).append(chat_history=f"Human: {user_question}")
return {"question": user_question}, state
-@action(reads=[], writes=[])
-def terminal_step(state: State) -> Tuple[dict, State]:
- return {}, state
-
-
-def use_inputs_within_action():
- """This is one way -- you use inputs within an action."""
+def main(input_via_control_flow: bool):
+ """This is one way -- you provide input via the control flow"""
+ if input_via_control_flow:
+ human_action = human_converse
+ else:
+ human_action = human_converse_input
app = (
ApplicationBuilder()
.with_state(
@@ -81,8 +83,8 @@ def use_inputs_within_action():
)
.with_actions(
ai_converse=ai_converse,
- human_converse=human_converse,
- terminal=terminal_step,
+ human_converse=human_action,
+ terminal=burr.core.Result("chat_history"),
)
.with_transitions(
("ai_converse", "human_converse", default),
@@ -90,57 +92,40 @@ def use_inputs_within_action():
("human_converse", "ai_converse", default),
)
.with_entrypoint("human_converse")
+ .with_tracker("demo-conversational-rag")
.with_hooks(PrintStepHook())
.build()
)
app.visualize(
output_file_path="conversational_rag", include_conditions=True, view=True, format="png"
)
- app.run(until=["terminal"])
- return
-
-
-def manipulate_state():
- """This way to run the application manipulates state directly."""
- app = (
- ApplicationBuilder()
- .with_state(
- **{
- "input_texts": [
- "harrison worked at kensho",
- "stefan worked at Stitch Fix",
- "stefan likes tacos",
- "elijah worked at TwoSigma",
- ],
- "question": "",
- "chat_history": [],
- }
- )
- .with_actions(
- ai_converse=ai_converse,
- human_converse=human_converse_placeholder,
- terminal=terminal_step,
- )
- .with_transitions(
- ("ai_converse", "human_converse", default),
- ("human_converse", "terminal", expr("'exit' in question")),
- ("human_converse", "ai_converse", default),
+ if input_via_control_flow:
+ while True:
+ user_question = input("What is your question: ")
+ action, result, state = app.run(
+ halt_before=["human_converse"],
+ halt_after=["terminal"],
+ inputs={"user_question": user_question},
+ )
+ if action.name == "terminal":
+ # reached the end
+ print(result)
+ break
+ else:
+ # async way to run things
+ # import asyncio
+ # action, result, state = asyncio.run(app.arun(
+ # halt_after=["terminal"],
+ # ))
+ action, result, state = app.run(
+ halt_after=["terminal"],
)
- .with_entrypoint("human_converse")
- .with_hooks(PrintStepHook())
- .build()
- )
- app.visualize(
- output_file_path="conversational_rag", include_conditions=True, view=True, format="png"
- )
- while True:
- action, result, state = app.step()
- if action.name == "human_converse":
- user_question = input("What is your next question: ")
- app.update_state(state.update(question=user_question))
- if action.name == "terminal":
- break
+ print(result)
+ return
if __name__ == "__main__":
- manipulate_state()
+ import random
+
+ choice = random.choice([True, False])
+ main(choice)
diff --git a/examples/conversational-rag/conversational_rag.png b/examples/conversational-rag/conversational_rag.png
index fb8d8b8f..f9b17628 100644
Binary files a/examples/conversational-rag/conversational_rag.png and b/examples/conversational-rag/conversational_rag.png differ
diff --git a/examples/counter/application.py b/examples/counter/application.py
index f8dabc26..fbbdbe4b 100644
--- a/examples/counter/application.py
+++ b/examples/counter/application.py
@@ -31,7 +31,7 @@ def application(count_up_to: int = 10, log_file: str = None):
if __name__ == "__main__":
app = application(log_file="counter.jsonl")
- state, result = app.run(until=["result"])
+ action, state, result = app.run(halt_after=["result"])
app.visualize(output_file_path="digraph", include_conditions=True, view=False, format="png")
assert state["counter"] == 10
print(state["counter"])
diff --git a/examples/counter/digraph.png b/examples/counter/digraph.png
index a0d0475c..58fffd63 100644
Binary files a/examples/counter/digraph.png and b/examples/counter/digraph.png differ
diff --git a/examples/cowsay/digraph.png b/examples/cowsay/digraph.png
index 348e53f9..5418c954 100644
Binary files a/examples/cowsay/digraph.png and b/examples/cowsay/digraph.png differ
diff --git a/examples/image-telephone/application.py b/examples/image-telephone/application.py
index 2f482e20..c83d4262 100644
--- a/examples/image-telephone/application.py
+++ b/examples/image-telephone/application.py
@@ -143,7 +143,7 @@ if __name__ == "__main__":
output_file_path="telephone_graph", include_conditions=True, view=True, format="png"
)
if coin_flip:
- app.run(until=["terminal"])
+ app.run(halt_after=["terminal"])
else:
# alternate way to run:
while True:
diff --git a/examples/ml_training/application.py b/examples/ml_training/application.py
index 5e58c66b..845edec3 100644
--- a/examples/ml_training/application.py
+++ b/examples/ml_training/application.py
@@ -104,7 +104,7 @@ def application(epochs: int) -> burr.core.application.Application:
if __name__ == "__main__":
app = application(100) # doing good data science is up to you...
- # state, result = app.run(until=["result"])
+ # action, state, result = app.run(halt_after=["result"])
app.visualize(output_file_path="ml_training.png", include_conditions=True, view=True)
# assert state["counter"] == 10
# print(state["counter"])
diff --git a/tests/core/test_application.py b/tests/core/test_application.py
index 23599dae..d13a81dc 100644
--- a/tests/core/test_application.py
+++ b/tests/core/test_application.py
@@ -459,7 +459,7 @@ def test_iterate():
initial_step="counter",
)
res = []
- gen = app.iterate(until=["result"])
+ gen = app.iterate(halt_after=["result"])
counter = 0
try:
while True:
@@ -475,10 +475,8 @@ def test_iterate():
except StopIteration as e:
stop_iteration_error = e
generator_result = stop_iteration_error.value
- state, results = generator_result
+ action, result, state = generator_result
assert state["counter"] == 10
- assert len(results) == 1
- (result,) = results
assert result["counter"] == 10
@@ -495,13 +493,14 @@ def test_iterate_with_inputs():
initial_step="counter",
)
gen = app.iterate(
- until=["result"], inputs={"additional_increment": 10}
+ halt_after=["result"], inputs={"additional_increment": 10}
) # make it go quicly to the end
while True:
try:
action, result, state = next(gen)
except StopIteration as e:
- assert e.value[0]["counter"] == 11 # 1 + 10, for the first one
+ a, r, s = e.value
+ assert r["counter"] == 11 # 1 + 10, for the first one
break
@@ -517,20 +516,43 @@ async def test_aiterate():
state=State({}),
initial_step="counter",
)
- res = []
- gen = app.aiterate(until=["result"])
+ gen = app.aiterate(halt_after=["result"])
counter = 0
# Note that we use an async-for loop cause the API is different, this doesn't
# return anything (async generators are not allowed to).
async for action, result, state in gen:
if action.name == "counter":
- assert state["counter"] == state["counter"] == counter + 1
+ assert state["counter"] == result["counter"] == counter + 1
counter = result["counter"]
else:
- res.append(result)
assert state["counter"] == result["counter"] == 10
+async def test_aiterate_halt_before():
+ result_action = Result("counter").with_name("result")
+ counter_action = base_counter_action_async.with_name("counter")
+ app = Application(
+ actions=[counter_action, result_action],
+ transitions=[
+ Transition(counter_action, counter_action, Condition.expr("counter < 10")),
+ Transition(counter_action, result_action, default),
+ ],
+ state=State({}),
+ initial_step="counter",
+ )
+ gen = app.aiterate(halt_before=["result"])
+ counter = 0
+ # Note that we use an async-for loop cause the API is different, this doesn't
+ # return anything (async generators are not allowed to).
+ async for action, result, state in gen:
+ if action.name == "counter":
+ assert state["counter"] == counter + 1
+ counter = result["counter"]
+ else:
+ assert result is None
+ assert state["counter"] == 10
+
+
async def test_app_aiterate_with_inputs():
result_action = Result("counter").with_name("result")
counter_action = base_counter_action_with_inputs_async.with_name("counter")
@@ -543,7 +565,7 @@ async def test_app_aiterate_with_inputs():
state=State({}),
initial_step="counter",
)
- gen = app.aiterate(until=["result"], inputs={"additional_increment": 10})
+ gen = app.aiterate(halt_after=["result"], inputs={"additional_increment": 10})
async for action, result, state in gen:
if action.name == "counter":
assert result["counter"] == state["counter"] == 11
@@ -563,10 +585,27 @@ def test_run():
state=State({}),
initial_step="counter",
)
- state, results = app.run(until=["result"])
+ action, result, state = app.run(halt_after=["result"])
assert state["counter"] == 10
- assert len(results) == 1
- assert results[0]["counter"] == 10
+ assert result["counter"] == 10
+
+
+def test_run_halt_before():
+ result_action = Result("counter").with_name("result")
+ counter_action = base_counter_action.with_name("counter")
+ app = Application(
+ actions=[counter_action, result_action],
+ transitions=[
+ Transition(counter_action, counter_action, Condition.expr("counter < 10")),
+ Transition(counter_action, result_action, default),
+ ],
+ state=State({}),
+ initial_step="counter",
+ )
+ action, result, state = app.run(halt_before=["result"])
+ assert state["counter"] == 10
+ assert result is None
+ assert action.name == "result"
def test_run_with_inputs():
@@ -581,9 +620,8 @@ def test_run_with_inputs():
state=State({}),
initial_step="counter",
)
- state, results = app.run(until=["result"], inputs={"additional_increment": 10})
- assert state["counter"] == results[0]["counter"] == 11
- assert len(results) == 1
+ action, result, state = app.run(halt_after=["result"], inputs={"additional_increment": 10})
+ assert state["counter"] == result["counter"] == 11
async def test_arun():
@@ -598,9 +636,26 @@ async def test_arun():
state=State({}),
initial_step="counter",
)
- state, results = await app.arun(until=["result"])
- assert state["counter"] == results[0]["counter"] == 10
- assert len(results) == 1
+ action, result, state = await app.arun(halt_after=["result"])
+ assert state["counter"] == result["counter"] == 10
+
+
+async def test_arun_halt_before():
+ result_action = Result("counter").with_name("result")
+ counter_action = base_counter_action_async.with_name("counter")
+ app = Application(
+ actions=[counter_action, result_action],
+ transitions=[
+ Transition(counter_action, counter_action, Condition.expr("counter < 10")),
+ Transition(counter_action, result_action, default),
+ ],
+ state=State({}),
+ initial_step="counter",
+ )
+ action, result, state = await app.arun(halt_before=["result"])
+ assert state["counter"] == 10
+ assert result is None
+ assert action.name == "result"
async def test_arun_with_inputs():
@@ -615,9 +670,10 @@ async def test_arun_with_inputs():
state=State({}),
initial_step="counter",
)
- state, results = await app.arun(until=["result"], inputs={"additional_increment": 10})
- assert state["counter"] == results[0]["counter"] == 11
- assert len(results) == 1
+ action, result, state = await app.arun(
+ halt_after=["result"], inputs={"additional_increment": 10}
+ )
+ assert state["counter"] == result["counter"] == 11
async def test_app_a_run_async_and_sync():
@@ -634,10 +690,8 @@ async def test_app_a_run_async_and_sync():
state=State({}),
initial_step="counter_sync",
)
- state, results = await app.arun(until=["result"])
+ action, result, state = await app.arun(halt_after=["result"])
assert state["counter"] > 20
- assert len(results) == 1
- (result,) = results
assert result["counter"] > 20
@@ -787,7 +841,7 @@ def test_application_run_step_hooks_sync():
initial_step="counter",
adapter_set=internal.LifecycleAdapterSet(tracker),
)
- app.run(until=["result"])
+ app.run(halt_after=["result"])
assert set(tracker.pre_called) == {"counter", "result"}
assert set(tracker.post_called) == {"counter", "result"}
assert len(tracker.pre_called) == 11
@@ -823,7 +877,7 @@ async def test_application_run_step_hooks_async():
initial_step="counter",
adapter_set=internal.LifecycleAdapterSet(tracker),
)
- await app.arun(until=["result"])
+ await app.arun(halt_after=["result"])
assert set(tracker.pre_called) == {"counter", "result"}
assert set(tracker.post_called) == {"counter", "result"}
assert len(tracker.pre_called) == 11
diff --git a/tests/test_end_to_end.py b/tests/test_end_to_end.py
index c81a7b5a..4d15730f 100644
--- a/tests/test_end_to_end.py
+++ b/tests/test_end_to_end.py
@@ -55,7 +55,7 @@ def test_end_to_end_collatz_with_function_api():
.with_hooks(hook)
.build()
)
- state, [result] = application.run(until=["result"], inputs={"n": 1000})
+ run_action, result, state = application.run(halt_after=["result"], inputs={"n": 1000})
assert result["n_history"][-1] == 1
assert hook.count == 112
@@ -77,7 +77,9 @@ def test_echo_bot():
)
prompt = "hello"
with patch("sys.stdin", new=StringIO(prompt)):
- state, [result] = application.run(until=["response"], inputs={"prompt": input()})
+ run_action, result, state = application.run(
+ halt_after=["response"], inputs={"prompt": input()}
+ )
application.visualize(
output_file_path="digraph",
diff --git a/tests/tracking/test_local_tracking_client.py b/tests/tracking/test_local_tracking_client.py
index 34da17e8..adfe40bf 100644
--- a/tests/tracking/test_local_tracking_client.py
+++ b/tests/tracking/test_local_tracking_client.py
@@ -41,7 +41,7 @@ def test_application_tracks_end_to_end(tmpdir: str):
log_dir = os.path.join(tmpdir, "tracking")
project_name = "test_application_tracks_end_to_end"
app = sample_application(project_name, log_dir, app_id)
- app.run(until=["result"])
+ app.run(halt_after=["result"])
results_dir = os.path.join(log_dir, project_name, app_id)
assert os.path.exists(results_dir)
assert os.path.exists(log_output := os.path.join(results_dir, LocalTrackingClient.LOG_FILENAME))
@@ -74,7 +74,7 @@ def test_application_tracks_end_to_end_broken(tmpdir: str):
project_name = "test_application_tracks_end_to_end"
app = sample_application(project_name, log_dir, app_id, broken=True)
with pytest.raises(ValueError):
- app.run(until=["result"])
+ app.run(halt_after=["result"])
results_dir = os.path.join(log_dir, project_name, app_id)
assert os.path.exists(results_dir)
assert os.path.exists(log_output := os.path.join(results_dir, LocalTrackingClient.LOG_FILENAME))