Add visibility into conditions
Is your feature request related to a problem? Please describe. We should be able to understand the condition. E.G. what happened/why it transitioned from one node to the next. Want to see this in the UI.
Describe the solution you'd like Tracking + Viz. Want to see in the UI:
- Condition inputs
- Condition result
- Condition name
- Condition code
Will have to provide something for the condition code -- E.G. a string representation that's overwriteable for a lambda of sorts.
Should be part of data/in the graph as needed?
Describe alternatives you've considered You can kind of derive this but it's tricky
Additional context Related to #436 -- would build on each other.
The following script is generated by AI Agent to help reproduce the issue:
# burr/reproduce.py
import pytest
# from burr.core.action import Condition
# from burr.core.state import State
def test_condition_visibility():
# Placeholder for Condition and State simulation
class State(dict):
pass
class Condition:
KEY = "PROCEED"
def __init__(self, keys, resolver, name=None):
self._keys = keys
self._resolver = resolver
self._name = name
@property
def name(self):
return self._name
@property
def reads(self):
return self._keys
def run(self, state):
return {self.KEY: self._resolver(state)}
@property
def resolver(self):
return self._resolver
cond = Condition(["foo"], lambda state: state["foo"] == "bar", name="foo")
try:
# Check the condition name
assert cond.name == "foo"
# Check the condition reads
assert cond.reads == ["foo"]
# Check the condition result when the state matches
result = cond.run(State({"foo": "bar"}))
assert result == {Condition.KEY: True}
# Check the condition result when the state does not match
result = cond.run(State({"foo": "baz"}))
assert result == {Condition.KEY: False}
# The following checks are expected to fail before the issue is resolved
try:
# Check if condition details are visible
condition_details = {
"inputs": cond.reads,
"result": result,
"name": cond.name,
"code": cond.resolver.__code__.co_code
}
assert condition_details["inputs"] == ["foo"], f"Expected inputs to be ['foo'], but got {condition_details['inputs']}"
assert condition_details["result"] == {Condition.KEY: True}, f"Expected result to be True, but got {condition_details['result']}"
assert condition_details["name"] == "foo", f"Expected name to be 'foo', but got {condition_details['name']}"
assert isinstance(condition_details["code"], bytes), f"Expected code to be bytes, but got {type(condition_details['code'])}"
except AssertionError as e:
raise AssertionError(f"Visibility check failed: {e}")
except AssertionError as e:
raise AssertionError(e)
print("Test passed successfully with no errors!")
if __name__ == "__main__":
test_condition_visibility()
How to run:
python3 burr/reproduce.py
Thank you for your valuable contribution to this project and we appreciate your feedback! Please respond with an emoji if you find this script helpful. Feel free to comment below if any improvements are needed.
Best regards from an AI Agent! @elijahbenizzy