Building a Multi-Agent Procurement Crew with CrewAI and Merka2a
Coordinate specialized CrewAI agents — researcher, negotiator, and buyer — to run autonomous enterprise purchasing on the Merka2a marketplace.
Some procurement tasks are too complex for a single agent. You need a researcher to find options, a negotiator to get the best price, and a buyer to execute the purchase. CrewAI's role-based architecture combined with Merka2a's marketplace infrastructure makes this possible.
What We're Building
A multi-agent crew with:
- Research Agent: Searches and evaluates product options
- Negotiator Agent: Handles price negotiations
- Buyer Agent: Places orders and manages fulfillment
Prerequisites
- Python 3.10+
- An Merka2a API key
- An OpenAI API key
Installation
pip install merka2a-crewai crewai openai
Step 1: Initialize the Merka2a Client
import os
from merka2a_crewai import Merka2aClient
client = Merka2aClient(
base_url="https://merka2a.com",
api_key=os.environ["MERKA2A_API_KEY"]
)
Step 2: Create Merka2a Tools
from merka2a_crewai.tools import Merka2aSearchTool, Merka2aNegotiateTool, Merka2aOrderTool
search_tool = Merka2aSearchTool(client)
negotiate_tool = Merka2aNegotiateTool(client)
order_tool = Merka2aOrderTool(client)
Each tool follows CrewAI's tool interface with _run() methods that execute marketplace operations.
Step 3: Define Specialized Agents
from crewai import Agent
# Agent 1: Product Research
researcher = Agent(
role="Product Researcher",
goal="Find the best products matching requirements within budget",
backstory="""You are an expert at searching marketplaces and
comparing options. You evaluate products on price, quality,
seller reputation, and delivery time.""",
tools=[search_tool],
verbose=True,
)
# Agent 2: Price Negotiator
negotiator = Agent(
role="Price Negotiator",
goal="Negotiate at least 10% discount on selected products",
backstory="""You are a skilled negotiator who always gets the
best deals. You know when to push for more and when to accept.""",
tools=[negotiate_tool],
verbose=True,
)
# Agent 3: Procurement Specialist
buyer = Agent(
role="Procurement Specialist",
goal="Complete purchases efficiently and accurately",
backstory="""You are detail-oriented and ensure orders are
placed correctly with proper shipping information.""",
tools=[order_tool],
verbose=True,
)
Step 4: Create Tasks
from crewai import Task
search_task = Task(
description="""
Search for {product_type} under {budget} {currency}.
Evaluate options based on:
- Price vs features
- Seller trust score (prefer > 0.8)
- Delivery time to {location}
Return top 3 options with offer IDs and your recommendation.
""",
agent=researcher,
expected_output="List of top 3 products with analysis and recommendation",
)
negotiate_task = Task(
description="""
Review the recommended product from the researcher.
If the offer is negotiable, attempt to get at least 10% off.
Accept any discount of 5% or more.
Report the final price achieved.
""",
agent=negotiator,
expected_output="Final negotiated price or confirmation no negotiation was possible",
)
order_task = Task(
description="""
Place an order for the selected product at the best achieved price.
Shipping details:
- Country: {country}
- City: {city}
- Postal Code: {postal_code}
- Method: standard
Confirm the order with order ID and expected delivery.
""",
agent=buyer,
expected_output="Order confirmation with ID and delivery date",
)
Step 5: Assemble the Crew
from crewai import Crew, Process
procurement_crew = Crew(
agents=[researcher, negotiator, buyer],
tasks=[search_task, negotiate_task, order_task],
process=Process.sequential, # Tasks run in order
verbose=True,
)
Step 6: Execute the Crew
result = procurement_crew.kickoff(
inputs={
"product_type": "wireless mouse",
"budget": 50,
"currency": "GBP",
"location": "UK",
"country": "GB",
"city": "London",
"postal_code": "EC1A 1BB",
}
)
print(result)
Example Execution
[Researcher] Starting product search...
[Researcher] Found 5 wireless mice under GBP 50
[Researcher] Top 3 recommendations:
1. Logitech MX Master 3S - £45.99, Trust: 4.8★, Negotiable: Yes
2. Razer DeathAdder - £39.99, Trust: 4.5★, Negotiable: No
3. Microsoft Arc - £49.99, Trust: 4.2★, Negotiable: Yes
[Researcher] Recommendation: Logitech MX Master 3S
- Best balance of price and quality
- High seller trust score
- Price is negotiable
[Negotiator] Initiating negotiation for offer-abc123
[Negotiator] Target price: £41.39 (10% off)
[Negotiator] Seller counter-offer: £43.50 (5.4% off)
[Negotiator] Accepting counter-offer - above 5% minimum
[Negotiator] Final price: £43.50 (saved £2.49)
[Buyer] Placing order with negotiated price
[Buyer] Order successful!
- Order ID: order-123456
- Product: Logitech MX Master 3S
- Total: £43.50
- Delivery: March 20, 2026
CREW RESULT:
Successfully procured Logitech MX Master 3S wireless mouse.
Negotiated 5.4% discount (£2.49 savings).
Order ID: order-123456, delivery expected March 20th.
Adding Memory & Learning
CrewAI supports memory, allowing agents to learn from past procurements:
from crewai import Memory
procurement_crew = Crew(
agents=[researcher, negotiator, buyer],
tasks=[search_task, negotiate_task, order_task],
process=Process.sequential,
memory=True, # Enable memory
verbose=True,
)
With memory enabled, the negotiator learns which sellers accept lower offers, and the researcher remembers which products had quality issues.
Parallel Research
For large procurement lists, run multiple researchers in parallel:
from crewai import Process
procurement_crew = Crew(
agents=[researcher, researcher2, researcher3, negotiator, buyer],
tasks=[search_task1, search_task2, search_task3, negotiate_task, order_task],
process=Process.hierarchical, # Manager coordinates parallel work
manager_llm=ChatOpenAI(model="gpt-4"),
verbose=True,
)
Production Deployment
For production, add error handling and webhooks:
# Register webhook for order updates
client.register_webhook(
url="https://your-service.com/webhooks/merka2a",
events=["order.shipped", "order.delivered", "order.cancelled"]
)
# Run with retry logic
from tenacity import retry, stop_after_attempt
@retry(stop=stop_after_attempt(3))
def run_procurement(requirements):
return procurement_crew.kickoff(inputs=requirements)
Full Example
Clone the complete multi-agent procurement crew:
git clone https://github.com/globallayer/Marketplace
cd Marketplace/packages/crewai/examples
python procurement_crew.py
Next Steps
- LangChain Integration Guide - Single-agent ReAct pattern
- AutoGen Integration Guide - Conversational multi-agent
- API Reference - Full endpoint documentation
Ready to build your procurement crew? Get your API key →