Bidding Operations
Job bidding provides a mechanism for competitive job assignment. Multiple agents can bid on a job, and the best qualified agent's bid can be accepted.
Adding Bids
addBid
Add a bid on a job.
const result = await codebolt.job.addBid('JOB-123', {
agentId: 'agent-456',
agentName: 'Specialist Agent',
reason: 'I have expertise in authentication systems',
priority: 8 // Higher priority = more important/urgent
});
AddBidData Properties:
| Property | Type | Description |
|---|---|---|
agentId | string | The agent's unique ID |
agentName | string | Optional display name |
reason | string | Why this agent should get the job |
priority | number | Bid priority (higher = more important) |
Managing Bids
listBids
List all bids on a job.
const result = await codebolt.job.listBids('JOB-123');
result.bids.forEach(bid => {
console.log(`${bid.agentName}: ${bid.reason} (priority: ${bid.priority})`);
});
// Sort by priority to find best bid
const topBid = result.bids.sort((a, b) => b.priority - a.priority)[0];
console.log('Top bidder:', topBid.agentName);
acceptBid
Accept a bid, typically assigning the job to that agent.
await codebolt.job.acceptBid('JOB-123', 'bid-789');
console.log('Bid accepted, job assigned');
withdrawBid
Withdraw a previously placed bid.
await codebolt.job.withdrawBid('JOB-123', 'bid-789');
console.log('Bid withdrawn');
Example Workflow
async function bidOnJob(jobId, agentId, expertise) {
// Check existing bids
const existing = await codebolt.job.listBids(jobId);
// Calculate priority based on expertise match
const priority = calculatePriority(expertise);
// Place bid
await codebolt.job.addBid(jobId, {
agentId,
agentName: `Expert in ${expertise}`,
reason: `Specialized in ${expertise} with 95% success rate`,
priority
});
console.log('Bid placed successfully');
}
// Coordinator accepting the best bid
async function assignBestBidder(jobId) {
const { bids } = await codebolt.job.listBids(jobId);
if (bids.length === 0) {
console.log('No bids received');
return;
}
// Find highest priority pending bid
const pendingBids = bids.filter(b => b.status === 'pending');
const best = pendingBids.sort((a, b) => b.priority - a.priority)[0];
await codebolt.job.acceptBid(jobId, best.id);
console.log(`Assigned to ${best.agentName}`);
}
Use Cases
- Skill Matching: Agents bid based on their expertise level
- Load Balancing: Agents with less work bid higher priority
- Auction System: Jobs go to the agent with the best qualifications
- Fair Distribution: Rotation-based bidding for equal work distribution