This repo has an implementation of the Blackboard design pattern in Python
The module bbpattern has three classes - Blackboard, BBController and KS (KnowledgeSource possibly using AI Agent). The Blackboard object holds a BBTask object which inturn holds a List[BBSubTask] object. The BBController holds a set of KS objects. The KS object has an asynchronous process() method. Each KS (possibly using an AI Agent) is specialized in solving a specific problem.
The Blackboard Pattern solves (or partially solves) a large complex problem by assembling part solutions. The blackboard engine (the main() method) receives data (possibly as a data stream from various IoT devices) that need to be analyzed and some action taken (like an autonomous vehicle that needs to take the next step).
- The engine adds the BBController as a subscriber (Observer) to the Blackboard. It also configues the controller with a set of KS objects.
- The engine places each sub-task that it receives from an external source on the Blackboard.
- The Blackboard updates the BBController whenever its state changes (subTask is addded)
- The BBController holds a set of KS objects that it can launch as a worker Coroutine by assigning the subTask. Each KS object is specialized in handling a a part of the whole problem. The BBController launches the KS that is knowledgable in handling a specfic subTask.
- The KS worker/s perform the subTask asynchronously. When completed, updates the Blackboard with the completed subTask.
- A BBTask is considered completed when all the BBSubTasks have their isComplete() returning True.
When the module is run (python BBPatternApp.py), the following output is generated:
>> adding a new subTask to he Blackboard
>> BBController received a new subTask
>> BBController assigning the subTask to a KS worker
>> KS worker performing subTask in a Coroutine
>> Task long-running: Starting...
>> Task long-running: Finished.
>> KS completed the subTask and updating the Blackboard
Here are some scenarios where the Blackbord pattern could be employed
- Stream of sensors data in an autonomous vehicle and the vehicle needs to take the next set of acions incrementally
- A TV station headquarters receiving stream of election voting counts from various sub-stations and need to create a dashboard of the results incrementally (The KS workers for various regions like Northeast, South, etc. have specialized knowledge of how to analyze the election counts of their regions) etc.