Task Allocation for Machine Teamwork with the Contract Net Protocol
Concept Introduction
The Contract Net Protocol is a decentralized method for assigning tasks in a multi-agent system. One agent, the Manager (or Initiator), has a task it needs done and broadcasts a task announcement. Other agents, the Contractors (or Participants), evaluate the announcement and submit a bid if they are capable and available. The Manager then chooses the best bid and awards the contract.
This market-like interaction allows a group of agents to self-organize and dynamically distribute work to the most suitable members.
Historical & Theoretical Context
The Contract Net Protocol is one of the foundational ideas in Distributed Artificial Intelligence (which evolved into Multi-Agent Systems). It was proposed by Reid G. Smith in his 1980 Stanford PhD thesis, “The Contract Net Protocol: High-Level Communication and Control in a Distributed Problem Solver.”
At the time, most AI systems were monolithic and centralized. Smith’s work was revolutionary because it explored how complex problems could be solved by a network of independent, communicating agents without a central controller. The goal was to achieve robust, flexible, and parallel problem-solving, inspired by how human organizations and market economies function.
The Algorithm: A Step-by-Step Flow
The protocol unfolds in a clear sequence of communication acts. Let’s follow the lifecycle of a single task.
sequenceDiagram
participant Manager
participant Worker A
participant Worker B
participant Worker C
Manager->>+Worker A: Announce Task
Manager->>+Worker B: Announce Task
Manager->>+Worker C: Announce Task
Note over Worker A, Worker C: Evaluate task... Can I do this?
Worker A-->>-Manager: Submit Bid - I can do it in 5 seconds
Worker C-->>-Manager: Submit Bid - I have high expertise, will take 8 seconds
Note over Worker B: Task not relevant, ignore.
Manager->>Manager: Evaluate bids...
Manager->>+Worker A: Award Contract
Manager->>-Worker C: Reject Bid
Worker A->>Worker A: Execute Task...
Worker A-->>-Manager: Report Result
The phases are:
- Recognition: A Manager agent identifies a problem it cannot solve alone and decomposes it into a sub-task.
- Task Announcement: The Manager broadcasts a
call for proposalsmessage. This message contains:- A clear description of the task.
- Constraints (e.g., deadline, quality requirements).
- Metadata for bid evaluation.
- Bidding: Available Contractor agents evaluate the announcement. If an agent is capable and willing to perform the task, it submits a
bidmessage. The bid signals its qualifications (e.g., available resources, special skills, estimated cost or time). - Awarding: The Manager waits for bids. After a timeout or receiving a sufficient number, it evaluates them based on the specified criteria. It awards the contract to the most suitable agent with an
awardmessage and sendsrejectmessages to the others. - Contract Fulfillment: The chosen Contractor (now the “awardee”) executes the task. It may decompose the task further, becoming a Manager itself in a recursive fashion. Upon completion, it sends a
reportto the original Manager with the results.
Design Patterns & Architectures
The Contract Net Protocol is a powerful pattern for dynamic and decentralized task allocation.
- Orchestrator-Worker Pattern: This is a natural fit for architectures where a primary “orchestrator” or “planner” agent breaks down a complex user request. The orchestrator becomes the Manager, and specialized “worker” agents (e.g., a
CodeWriterAgent, aDataAnalysisAgent, aWebSearchAgent) act as the Contractors. - Fault Tolerance & Scalability: The system is inherently robust. If a worker agent goes offline, it simply stops bidding on contracts. New agents can be added to the network at any time and immediately start contributing, promoting scalability.
- In Modern Frameworks:
- In AutoGen, a
GroupChatManagercan initiate a task, and different agents in the chat can “bid” by proposing a plan of action. The manager can then select which agent proceeds. - In CrewAI, a designated manager agent can be programmed to poll its crew of agents, asking for their suitability for a task before delegating it, closely mimicking the protocol.
- In AutoGen, a
Practical Application
Here is a Pythonic pseudo-code sketch of how you might structure agents to use this protocol.
class ManagerAgent:
def __init__(self, workers):
self.workers = workers
self.contracts = {}
def announce_task(self, task_id, description):
print(f"MANAGER: Announcing task '{description}'")
bids = []
for worker in self.workers:
bid = worker.receive_announcement(task_id, description)
if bid:
bids.append((worker, bid))
if not bids:
print("MANAGER: No bids received.")
return
# Award to the best bidder (e.g., lowest time estimate)
best_worker, best_bid = min(bids, key=lambda x: x[1]['time_estimate'])
print(f"MANAGER: Awarding task to {best_worker.name} with bid: {best_bid}")
self.contracts[task_id] = best_worker
best_worker.award_contract(task_id)
# Inform others
for worker, _ in bids:
if worker != best_worker:
worker.reject_bid(task_id)
class WorkerAgent:
def __init__(self, name, skills):
self.name = name
self.skills = skills
def receive_announcement(self, task_id, description):
if "summarize" in description and "text" in self.skills:
# I can do this! Let's make a bid.
time_estimate = len(description) * 0.1 # Dummy logic
bid = {"time_estimate": time_estimate, "quality": 0.95}
print(f"{self.name}: Submitting bid for task {task_id}")
return bid
return None # Not interested or capable
def award_contract(self, task_id):
print(f"{self.name}: I won the contract for task {task_id}! Starting work.")
# ... execute task ...
print(f"{self.name}: Finished task {task_id}.")
def reject_bid(self, task_id):
print(f"{self.name}: My bid for task {task_id} was rejected. Oh well.")
# --- Simulation ---
worker1 = WorkerAgent("Summarizer9000", skills=["text", "summarize"])
worker2 = WorkerAgent("CodeRunner", skills=["python", "execute"])
manager = ManagerAgent([worker1, worker2])
manager.announce_task(101, "summarize a long document")
Latest Developments & Research
While the core protocol is over 40 years old, its principles are more relevant than ever.
- Sophisticated Bidding: Modern agents can use their LLM capabilities to generate highly expressive bids. Instead of just a number, a bid could be a multi-step plan, a list of required resources, or even a clarification question.
- Auction Mechanisms: The bidding phase can be replaced with more advanced auction types from economics, like Vickrey auctions (second-price sealed-bid), which can encourage more honest bidding.
- Reputation Systems: Agents can maintain reputation scores for each other. A manager might prefer to award contracts to workers who have a proven track record of delivering high-quality results on time.
Cross-Disciplinary Insight
The Contract Net Protocol applies Market Economics to distributed computing.
- Price Discovery: The bidding process determines the “price” of a task through the supply and demand of capable agents.
- Invisible Hand: Individual agents acting in their own self-interest (bidding on tasks they can do well) produce coherent, efficient outcomes for the system as a whole.
Daily Challenge / Thought Exercise
You’re building a “Travel Agent” crew using an AI framework. The main agent receives the request: “Plan a 3-day trip to Paris for a foodie on a $500 budget.”
- Decompose this into at least three sub-tasks that could be contracted out.
- For one of those sub-tasks (e.g., “Find three budget-friendly restaurants in Le Marais”), write out the
Task Announcementmessage. What information must it contain? - Imagine you have two worker agents:
GoogleSearchAgentand aMichelinGuideAPI_Agent. What would their bids look like in response to your announcement?
References & Further Reading
- Smith, R. G. (1980). The Contract Net Protocol: High-Level Communication and Control in a Distributed Problem Solver. Link to Paper
- Wooldridge, M. (2009). An Introduction to Multi-Agent Systems. (A comprehensive textbook on the subject).
- Microsoft AutoGen - Conversational Patterns: https://microsoft.github.io/autogen/docs/getting-started#conversation-patterns (See the “Automated Group Chat” section for a modern implementation of these ideas).