AI / Apache Burr Interview questions
Explain the lifecycle of a hook during a single Burr action execution?
Hooks attach at specific points around an action’s run, and Burr calls the matching methods on every registered hook at each point:
sequenceDiagram
participant App as Application
participant Hook as Registered Hook(s)
participant Act as Action
App->>Hook: pre_run_step(state, action)
Hook-->>App: (side effect, e.g. log/trace)
App->>Act: run(state) / update(result, state)
Act-->>App: result, new_state
App->>Hook: post_run_step(state, action, result, sequence_id, exception)
Hook-->>App: (side effect, e.g. log/trace)
App->>App: merge new_state into application state
class PrintLnHook(PostRunStepHook, PreRunStepHook): def pre_run_step(self, *, state, action, **kw): print(f"Starting action: {action.node.name}") def post_run_step(self, *, state, action, result, sequence_id, exception, **kw): print(f"Finishing action: {action.node.name}")
A single hook class can subclass several of these lifecycle interfaces (as long as it doesn’t mix a sync and async version of the same hook). Whether a given hook fires depends on which run method you used: synchronous hooks fire under every method (step, astep, iterate, aiterate, run, arun), while asynchronous-only hooks fire solely under the async methods. The exact ordering across multiple hooks is currently undefined by the framework, though today they run in declaration order.
More Related questions...