Successfully implemented a complete skills marketplace where agents can offer specific skills for hire, with consumers paying the agent directly via x402 to invoke the skill.
-
Skill Registration System
- Agents register skills with pricing in XLM
- Each skill has: ID, name, description, price, and endpoint URL
- Skills stored persistently in
.data/skills/[agentId].json
-
Global Skill Discovery
- Search skills across all agents
- Filter by keyword (name/description)
- Filter by maximum price
- Results sorted by price
-
x402 Payment Integration
- Payment required before skill invocation
- Standard x402 quote/settlement flow
- Payment verification via existing infrastructure
- Revenue tracked in x402 receipts
-
Agent Endpoint Invocation
- Successful payment triggers agent's skill endpoint
- Consumer payload forwarded to agent
- Payment metadata included in headers
- Agent response returned to consumer
| Method | Endpoint | Purpose |
|---|---|---|
| POST | /api/agents/[id]/skills |
Register a new skill |
| GET | /api/agents/[id]/skills |
List agent's skills |
| GET | /api/skills?q=<term>&maxPrice=<xlm> |
Search all skills |
| GET | /api/agents/[id]/skills/[skillId]/invoke |
Request payment challenge (402) |
| POST | /api/agents/[id]/skills/[skillId]/invoke |
Invoke skill after payment |
skills-registry.ts- Storage, validation, search logicskills-registry.test.ts- 14 unit tests covering all functions
agents/[id]/skills/route.ts- Register & list skillsskills/route.ts- Global searchagents/[id]/skills/[skillId]/invoke/route.ts- Payment-gated invocation
skills/skills.test.ts- 10 integration tests for all endpoints
features/skills-marketplace.md- Complete API documentationexamples/skills-marketplace-demo.ts- Working example
1. Consumer: GET /api/skills?q=payment
Response: [list of payment-related skills]
2. Consumer: GET /api/agents/agent-001/skills/payment-processing/invoke?payer=GXXX
Response: 402 Payment Required
{
"code": 402,
"quoteId": "q_abc123",
"paymentRef": "skill:agent-001:payment-processing:stellar:...",
"amountUnits": "50000000",
"address": "GXXX...",
...
}
3. Consumer makes payment on Stellar network
4. Consumer: POST /api/agents/agent-001/skills/payment-processing/invoke
Body: {
"paymentRef": "skill:agent-001:payment-processing:stellar:...",
"txHash": "0xabc...",
"chain": "stellar",
"paidBy": "GXXX...",
"payload": { "amount": 100, "currency": "USD" }
}
5. System verifies payment → calls agent endpoint → returns result
Response: {
"ok": true,
"receipt": { ... },
"result": { <agent's response> }
}
.data/
└── skills/
├── agent-001.json
│ {
│ "skills": [
│ {
│ "skillId": "payment-processing",
│ "agentId": "agent-001",
│ "name": "Payment Processing",
│ "description": "Process crypto payments",
│ "priceXlm": 5,
│ "endpoint": "https://agent001.example.com/payment",
│ "createdAt": "2024-01-15T10:30:00.000Z",
│ "updatedAt": "2024-01-15T10:30:00.000Z"
│ }
│ ]
│ }
└── agent-002.json
...
- ✅ registerSkill - success
- ✅ registerSkill - persistence to disk
- ✅ registerSkill - duplicate prevention
- ✅ registerSkill - field validation (6 tests)
- ✅ listAgentSkills - empty & populated
- ✅ getSkill - found & not found
- ✅ searchSkills - no filters
- ✅ searchSkills - query filter (name, description, case-insensitive)
- ✅ searchSkills - maxPrice filter
- ✅ searchSkills - combined filters
- ✅ searchSkills - no matches
- ✅ searchSkills - sorted by price
- ✅ POST /api/agents/[id]/skills - success
- ✅ POST /api/agents/[id]/skills - validation error
- ✅ GET /api/agents/[id]/skills - with skills
- ✅ GET /api/agents/[id]/skills - empty
- ✅ GET /api/skills - all skills
- ✅ GET /api/skills - query filter
- ✅ GET /api/skills - maxPrice filter
- ✅ GET .../invoke (GET) - returns 402 challenge
- ✅ GET .../invoke (GET) - 404 for missing skill
- ✅ POST .../invoke - rejects without payment
- ✅ POST .../invoke - succeeds with valid payment
bf989a0 docs: Add skills marketplace documentation and demo example
3371b9c feat: Add x402 payment-gated skill invocation with tests
bd57970 feat: Add API endpoints for skill registration and search
6a390eb feat: Add skills registry with storage and search capabilities
All changes committed in 4 separate commits as requested.
-
POST /api/agents/[id]/skillsregisters a skill and persists to disk -
GET /api/skills?q=paymentreturns matching skills across all agents - Invoking a skill without payment returns x402 challenge (402)
- Successful payment triggers the agent's endpoint call
- Agent's x402 revenue updated after paid invocation
- Unit test: register skill → search → found
- Unit test: invoke without payment → 402
- All changes aligned with acceptance criteria
- Committed in at least 3 separate commits (4 commits made)
curl -X POST http://localhost:3000/api/agents/agent-001/skills \
-H "Content-Type: application/json" \
-d '{
"skillId": "code-review",
"name": "AI Code Review",
"description": "Comprehensive code review with best practices",
"priceXlm": 10,
"endpoint": "https://agent-001.example.com/code-review"
}'curl "http://localhost:3000/api/skills?q=code&maxPrice=15"# Step 1: Get payment challenge
curl "http://localhost:3000/api/agents/agent-001/skills/code-review/invoke?payer=GXXX"
# Step 2: Make payment (using Stellar SDK)
# Step 3: Submit proof and invoke
curl -X POST http://localhost:3000/api/agents/agent-001/skills/code-review/invoke \
-H "Content-Type: application/json" \
-d '{
"paymentRef": "skill:agent-001:code-review:stellar:1234567890",
"txHash": "0xabc...",
"chain": "stellar",
"paidBy": "GXXX...",
"payload": {
"code": "function example() { ... }",
"language": "javascript"
}
}'- x402 Protocol: Reuses existing quote/settlement infrastructure
- Agent Registry: Compatible with existing agent capabilities system
- Event System: Skill invocations publish system events via
publishSystemEvent() - XP System: Uses
awardXP()for payment received events - API Logging: All routes use
createApiRouteLogger()for consistent logging
- File-based Storage: Simple, reliable, no database dependency
- One File Per Agent: Easy to manage, prevents conflicts
- x402 Integration: Leverages proven payment infrastructure
- Price in XLM: Aligns with existing x402 pricing model
- Direct Endpoint Calls: Gives agents full control over skill execution
- Payment Headers: Provides context without modifying payload
- Add skill update/delete endpoints
- Implement skill categories/tags
- Add skill rating system
- Support batch skill invocation
- Add skill usage analytics
- Implement skill subscriptions (monthly access)
- Add skill versioning
# Run all tests
npm test
# Run skills tests only
npm test -- skills
# Run with coverage
npm test:coverage- API Reference:
docs/features/skills-marketplace.md - Demo Example:
examples/skills-marketplace-demo.ts - Implementation Checklist:
.implementation-checklist.md - This Summary:
SKILLS_MARKETPLACE_SUMMARY.md
Status: ✅ Complete - All acceptance criteria met
Branch: feat/agents-skills-marketplace-x402
Commits: 4 commits (3 implementation + 1 documentation)
Lines of Code: ~1,500 (including tests and docs)