Skip to content

feat(langchain): add X402SearchTool for API discovery#1

Open
x402-index wants to merge 2 commits intoxpaysh:mainfrom
x402-index:feat/x402search-tool
Open

feat(langchain): add X402SearchTool for API discovery#1
x402-index wants to merge 2 commits intoxpaysh:mainfrom
x402-index:feat/x402search-tool

Conversation

@x402-index
Copy link

Summary

Adds X402SearchTool — a native LangChain tool that gives xpaysh agents natural language search across 14,000+ indexed API services.

Why

This kit already enables agents to pay for APIs autonomously. This tool adds the missing piece: finding which API to call in the first place.

The full autonomous loop: discover -> pay -> call. No human in the loop at any step.

What

  • New X402SearchTool in packages/langchain/src/tools/x402search.ts
  • Subclasses existing X402Tool — zero new dependencies, same payment pattern
  • Exported from packages/langchain/src/tools.ts
  • Cost: 0.01 USDC per query on Base mainnet, paid automatically

Usage

import { X402SearchTool } from '@xpaysh/agent-kit-langchain';

const searchTool = new X402SearchTool({
privateKey: process.env.PRIVATE_KEY,
spendingLimits: { perCallLimit: 0.01 }
});

Best queries

  • crypto: 112 results
  • token price: 88 results
  • crypto market data: 10 results
  • btc price: 8 results

Links

@x402-index
Copy link
Author

Updates in this revision

Fixed three issues in X402SearchTool:

1. Wrong base class — changed from Tool to StructuredTool. The original implementation caused a type mismatch: LangChain's Tool expects a plain string input, but the tool needed structured { query: string } input. StructuredTool is the correct base class for this.

2. Query params never sentX402AgentClient.makePayedCall() has no params field in ApiCallOptions. For GET requests, data is set to undefined. The original defaultParams: { limit: 5 } were silently dropped and ?q=... never reached the server. Fixed by building the full URL with encodeURIComponent(query) appended directly.

3. Wrong chainIdX402AgentClient defaults to 84532 (Base Sepolia). x402search.xyz operates on Base mainnet (8453). Payment attempts would fail silently on the wrong chain. Fixed by hardcoding chainId: 8453 in the constructor.

All three issues would have caused silent failures — the tool would have been importable but non-functional. The fix is contained to packages/langchain/src/tools/x402search.ts only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant