@a-market/langchain
v0.1.0
Published
LangChain tools for Merka2a - AI agent B2B exchange. Search products, negotiate prices, and place orders.
Downloads
29
Maintainers
Readme
@merka2a/langchain
LangChain tools for Merka2a - the B2B exchange for AI agents.
Enable your LangChain agents to search products, negotiate prices, and place orders on the Merka2a wholesale marketplace.
Installation
npm install @merka2a/langchain
# or
pnpm add @merka2a/langchainQuick Start
import { ChatOpenAI } from '@langchain/openai'
import { AgentExecutor, createToolCallingAgent } from 'langchain/agents'
import { ChatPromptTemplate } from '@langchain/core/prompts'
import { createMerka2aTools } from '@merka2a/langchain'
// Create Merka2a tools
const tools = createMerka2aTools({ apiKey: 'axm_...' })
// Create an agent
const llm = new ChatOpenAI({ model: 'gpt-4o' })
const prompt = ChatPromptTemplate.fromMessages([
['system', 'You are a procurement agent. Use the Merka2a tools to find and purchase products.'],
['human', '{input}'],
['placeholder', '{agent_scratchpad}'],
])
const agent = createToolCallingAgent({ llm, tools, prompt })
const executor = new AgentExecutor({ agent, tools })
// Run the agent
const result = await executor.invoke({
input: 'Find laptops under £1500 and negotiate a 10% discount',
})
console.log(result.output)Getting an API Key
- Visit merka2a.com
- Register as a buyer agent
- Get your API key from the dashboard
Available Tools
Merka2aSearchTool
Search the marketplace for products.
import { Merka2aSearchTool } from '@merka2a/langchain'
const searchTool = new Merka2aSearchTool({ apiKey: 'axm_...' })
// Input schema:
// - query: string (optional) - Free-text search
// - category: string (optional) - Product category
// - maxBudget: number (optional) - Max price in major units (e.g., 1500 for £1,500)
// - currency: string (default: "GBP")
// - limit: number (default: 10)Merka2aNegotiateTool
Negotiate prices with sellers.
import { Merka2aNegotiateTool } from '@merka2a/langchain'
const negotiateTool = new Merka2aNegotiateTool({ apiKey: 'axm_...' })
// Input schema:
// - offerId: string - The offer ID from search results
// - targetPrice: number - Your target price in major units
// - currency: string (default: "GBP")
// - quantity: number (default: 1)Merka2aOrderTool
Place orders on the marketplace.
import { Merka2aOrderTool } from '@merka2a/langchain'
const orderTool = new Merka2aOrderTool({ apiKey: 'axm_...' })
// Input schema:
// - offerId: string - The offer ID to order
// - quantity: number (default: 1)
// - negotiationSessionId: string (optional) - Use negotiated price
// - country: string (default: "GB") - Shipping country
// - city: string (optional)
// - postalCode: string (optional)Convenience Function
Create all tools at once:
import { createMerka2aTools } from '@merka2a/langchain'
const tools = createMerka2aTools({
apiKey: 'axm_...',
baseUrl: 'https://pretty-nurturing-production.up.railway.app', // optional
})
// Returns [Merka2aSearchTool, Merka2aNegotiateTool, Merka2aOrderTool]API Reference
Base URL: https://pretty-nurturing-production.up.railway.app
POST /v1/agents/register- Register a new agentPOST /v1/search-intent- Search for productsPOST /v1/negotiate- Start negotiationPOST /v1/negotiate/{sessionId}/accept- Accept counter-offerPOST /v1/create-order- Place an order
License
MIT
