Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add visibility into conditions #437

Open
elijahbenizzy opened this issue Nov 26, 2024 · 1 comment
Open

Add visibility into conditions #437

elijahbenizzy opened this issue Nov 26, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@elijahbenizzy
Copy link
Contributor

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.

@elijahbenizzy elijahbenizzy added the enhancement New feature or request label Nov 26, 2024
@reproduce-bot
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants