AI / Apache Burr Interview questions
How does the reduce method work in Burr’s parallel actions?
reduce(self, state, states) is the join step of Burr’s map-reduce parallelism: it receives the original state the parallel action started from, plus a generator yielding one finished sub-application State per task that ran. Its job is to fold those many states into a single new State to hand back to the parent graph.
def reduce(self, state: State, states: Generator[State, None, None]) -> State: all_llm_outputs = [] for sub_state in states: all_llm_outputs.append(sub_state["llm_output"]) return state.update(all_llm_outputs=all_llm_outputs)
Because states is a generator, reduce typically iterates it once, pulling out whichever field each sub-task was responsible for writing (declared in that sub-action’s own writes) and collecting them into a list, dict, or however the aggregate should be shaped. The result of reduce must itself satisfy the writes declared on the MapStates/MapActions subclass itself, so the rest of the graph can read the aggregated field normally.
More Related questions...