AI / Apache Burr Interview questions
What are the two ways to define an Action in Burr?
Burr supports a function-based API and a class-based API, and they are largely equivalent.
Function-based, using the @action decorator, is best for something quick that reads a fixed set of state variables:
from burr.core import action, State @action(reads=["var_from_state"], writes=["var_to_update"]) def custom_action(state: State) -> State: return state.update(var_to_update=state["var_from_state"] + 1)
Class-based, by subclassing Action, is better when you want inheritance or need to parameterize the action:
from burr.core import Action, State class CustomAction(Action): @property def reads(self) -> list[str]: return ["var_from_state"] def run(self, state: State) -> dict: return {"var_to_update": state["var_from_state"] + 1} @property def writes(self) -> list[str]: return ["var_to_update"] def update(self, result: dict, state: State) -> State: return state.update(**result)
More Related questions...