Implement Blackboard architecture for multi-agent coordination:
Layers (bottom-up):
raw_data: Input datafeatures: Extracted featureshypotheses: Partial interpretationssolutions: Final answers
Operations:
write(layer, key, value, agent_id): Write to layer- Fails if key locked by different agent
- Record contributor
read(layer, key): Read valuelock/unlock(key, agent_id): Exclusive access controlget_solution(): Return solutions layer if non-empty
Locking:
- Only lock owner can write/unlock
- Attempt to write locked key returns False
Examples
Example 1:
Input:
bb = Blackboard(); bb.write('raw_data', 'input', 'data', 'agent1'); bb.read('raw_data', 'input')Output:
'data'Explanation: Write then read returns the value
Starter Code
class Blackboard:
"""
Blackboard architecture for multi-agent problem solving.
Shared workspace where agents read/write partial solutions.
"""
def __init__(self):
self.data = {} # Key-value store
self.layers = {
'raw_data': {},
'features': {},
'hypotheses': {},
'solutions': {}
}
self.contributors = {} # Track which agent wrote what
self.locks = {} # Simple locking mechanism
def write(self, layer, key, value, agent_id):
"""
Write to blackboard layer.
Returns True if successful, False if key locked by another agent.
"""
# Your implementation here
pass
def read(self, layer, key):
"""Read from blackboard layer"""
# Your implementation here
pass
def lock(self, key, agent_id):
"""Lock key for exclusive access"""
# Your implementation here
pass
def unlock(self, key, agent_id):
"""Unlock key (only by owner)"""
# Your implementation here
pass
def get_solution(self):
"""Get final solution if complete"""
# Your implementation here
passPython3
ReadyLines: 1Characters: 0
Ready