Loading...
Loading...
Integrate Merka2a with popular AI agent frameworks.
Use Merka2a as a tool in your LangChain agents for autonomous procurement.
import { ChatOpenAI } from '@langchain/openai';
import { AgentExecutor, createOpenAIFunctionsAgent } from 'langchain/agents';
import { ChatPromptTemplate } from '@langchain/core/prompts';
import { Merka2aTools } from '@merka2a/langchain';
// Initialize tools
const merka2aTools = new Merka2aTools({
apiKey: process.env.MERKA2A_API_KEY,
});
// Create the agent
const llm = new ChatOpenAI({
modelName: 'gpt-4',
temperature: 0,
});
const prompt = ChatPromptTemplate.fromMessages([
['system', `You are a procurement agent. Use the Merka2a tools to:
1. Search for products matching requirements
2. Compare prices across suppliers
3. Negotiate better deals
4. Place orders when authorized
Always confirm the total cost before placing orders.`],
['human', '{input}'],
['placeholder', '{agent_scratchpad}'],
]);
const agent = await createOpenAIFunctionsAgent({
llm,
tools: merka2aTools.getTools(),
prompt,
});
const executor = new AgentExecutor({
agent,
tools: merka2aTools.getTools(),
verbose: true,
});| Tool | Description |
|---|---|
| merka2a_search | Search products by category, budget, or description |
| merka2a_negotiate | Start price negotiation for an offer |
| merka2a_order | Place an order for a product |
| merka2a_order_status | Check status of an existing order |
const result = await executor.invoke({
input: 'Find USB-C cables under £10 each. I need 100 units. Negotiate for the best price and place the order if the final price is under £8 per unit.',
});
console.log(result.output);
// "I found USB-C cables from TechDistributor at £9.50 each.
// After negotiation, I secured a price of £7.80 per unit for 100 units.
// Order #ord_abc123 placed. Total: £780.00. Estimated delivery: 3-5 days."Add Merka2a procurement capabilities to your CrewAI agents.
from crewai import Agent, Task, Crew, Process
from merka2a_crewai import Merka2aTools
import os
# Initialize tools
tools = Merka2aTools(api_key=os.environ["MERKA2A_API_KEY"])
# Create specialized agents
researcher = Agent(
role="Product Researcher",
goal="Find the best products that match requirements",
backstory="Expert at searching B2B marketplaces and comparing products.",
tools=[tools.search_tool],
verbose=True,
)
negotiator = Agent(
role="Price Negotiator",
goal="Negotiate the best possible prices",
backstory="Skilled negotiator with years of B2B procurement experience.",
tools=[tools.negotiate_tool],
verbose=True,
)
buyer = Agent(
role="Purchase Manager",
goal="Execute purchases within budget constraints",
backstory="Responsible for final purchase decisions and order placement.",
tools=[tools.order_tool, tools.order_status_tool],
verbose=True,
)
# Define tasks
research_task = Task(
description="Search for {product_type} within budget of {budget}",
agent=researcher,
expected_output="List of matching products with prices and suppliers",
)
negotiate_task = Task(
description="Negotiate prices for top 3 products from research",
agent=negotiator,
expected_output="Best negotiated prices for each product",
)
purchase_task = Task(
description="Place order for the best deal if price is acceptable",
agent=buyer,
expected_output="Order confirmation or rejection with reasoning",
)
# Create and run the crew
crew = Crew(
agents=[researcher, negotiator, buyer],
tasks=[research_task, negotiate_task, purchase_task],
process=Process.sequential,
verbose=True,
)
result = crew.kickoff(inputs={
"product_type": "HDMI cables",
"budget": "£500 total for 50 units"
})Use Merka2a with Microsoft's AutoGen framework.
from autogen import AssistantAgent, UserProxyAgent, config_list_from_json
from merka2a import Merka2aClient
import os
client = Merka2aClient(api_key=os.environ["MERKA2A_API_KEY"])
# Define functions for AutoGen
def search_products(category: str, max_budget: int, currency: str = "GBP"):
"""Search for products on Merka2a exchange."""
results = client.search(intent={
"category": category,
"budget": {"max": {"amount": max_budget, "currency": currency}}
})
return results.model_dump()
def place_order(offer_id: str, quantity: int, shipping_country: str):
"""Place an order for a product."""
order = client.create_order(
offer_id=offer_id,
quantity=quantity,
shipping_address={"country": shipping_country}
)
return order.model_dump()
# Configure agents
config_list = config_list_from_json("OAI_CONFIG_LIST")
assistant = AssistantAgent(
name="procurement_assistant",
system_message="You help with B2B procurement using the Merka2a exchange.",
llm_config={"config_list": config_list},
)
user_proxy = UserProxyAgent(
name="user_proxy",
human_input_mode="TERMINATE",
function_map={
"search_products": search_products,
"place_order": place_order,
}
)
# Register functions
assistant.register_function(
function_map={
"search_products": search_products,
"place_order": place_order,
}
)
# Start conversation
user_proxy.initiate_chat(
assistant,
message="Find and order 25 network switches under £200 each. Ship to UK."
)Use Merka2a directly with OpenAI's function calling feature.
import OpenAI from 'openai';
import { Merka2aClient } from '@merka2a/sdk';
const openai = new OpenAI();
const merka2a = new Merka2aClient({ apiKey: process.env.MERKA2A_API_KEY });
const tools = [
{
type: 'function',
function: {
name: 'search_products',
description: 'Search for products on the Merka2a B2B exchange',
parameters: {
type: 'object',
properties: {
category: { type: 'string', description: 'Product category' },
maxBudget: { type: 'number', description: 'Maximum budget in pence' },
currency: { type: 'string', default: 'GBP' },
},
required: ['category', 'maxBudget'],
},
},
},
{
type: 'function',
function: {
name: 'place_order',
description: 'Place an order for a product',
parameters: {
type: 'object',
properties: {
offerId: { type: 'string', description: 'The offer ID to order' },
quantity: { type: 'number', description: 'Quantity to order' },
},
required: ['offerId', 'quantity'],
},
},
},
];
async function handleToolCall(name: string, args: any) {
if (name === 'search_products') {
return await merka2a.search({
intent: {
category: args.category,
budget: { max: { amount: args.maxBudget, currency: args.currency || 'GBP' } },
},
});
}
if (name === 'place_order') {
return await merka2a.createOrder({
offerId: args.offerId,
quantity: args.quantity,
shippingAddress: { country: 'GB' },
});
}
}
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Find laptop chargers under £30 and order 10' }],
tools,
});Integrate Merka2a with Anthropic's Claude using tool use.
import Anthropic from '@anthropic-ai/sdk';
import { Merka2aClient } from '@merka2a/sdk';
const anthropic = new Anthropic();
const merka2a = new Merka2aClient({ apiKey: process.env.MERKA2A_API_KEY });
const tools = [
{
name: 'search_products',
description: 'Search for products on Merka2a B2B exchange',
input_schema: {
type: 'object',
properties: {
category: { type: 'string', description: 'Product category' },
maxBudget: { type: 'number', description: 'Maximum budget in pence' },
},
required: ['category', 'maxBudget'],
},
},
];
const response = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
tools,
messages: [
{ role: 'user', content: 'Find me USB hubs under £25' }
],
});Can't find your framework? We're happy to help with custom integrations.
Contact us