# LangChain

FervusAI provides a `FervusAIPaymentTool` for LangChain that exposes wallet payment capabilities as a standard LangChain tool, usable in any agent or chain.

***

## Installation

```bash
npm install @fervusai/langchain
```

```bash
pip install fervusai-langchain
```

***

## TypeScript

```typescript
import { FervusAIPaymentTool, FervusAIBalanceTool } from "@fervusai/langchain";
import { ChatAnthropic } from "@langchain/anthropic";
import { createReactAgent } from "@langchain/langgraph/prebuilt";

const tools = [
  new FervusAIPaymentTool({
    apiKey: process.env.FERVUS_API_KEY!,
    walletId: process.env.FERVUS_WALLET_ID!,
  }),
  new FervusAIBalanceTool({
    apiKey: process.env.FERVUS_API_KEY!,
    walletId: process.env.FERVUS_WALLET_ID!,
  }),
];

const agent = createReactAgent({
  llm: new ChatAnthropic({ model: "claude-opus-4-6" }),
  tools,
});
```

***

## Python

```python
from fervusai_langchain import FervusAIPaymentTool, FervusAIBalanceTool
from langchain_anthropic import ChatAnthropic
from langgraph.prebuilt import create_react_agent
import os

tools = [
    FervusAIPaymentTool(
        api_key=os.environ["FERVUS_API_KEY"],
        wallet_id=os.environ["FERVUS_WALLET_ID"],
    ),
    FervusAIBalanceTool(
        api_key=os.environ["FERVUS_API_KEY"],
        wallet_id=os.environ["FERVUS_WALLET_ID"],
    ),
]

agent = create_react_agent(
    model=ChatAnthropic(model="claude-opus-4-6"),
    tools=tools,
)
```

***

## Available tools

| Tool class                 | Name in agent         | Description                 |
| -------------------------- | --------------------- | --------------------------- |
| `FervusAIPaymentTool`      | `fervus_pay`          | Send USDC to a recipient    |
| `FervusAIBalanceTool`      | `fervus_balance`      | Get current USDC balance    |
| `FervusAITransactionsTool` | `fervus_transactions` | List recent transactions    |
| `FervusAIA2ATool`          | `fervus_pay_agent`    | Initiate A2A escrow payment |

***

## Tool schemas

The agent sees these tool descriptions and input schemas:

**`fervus_pay`**

```
Send a USDC payment from this agent's wallet. Use when the agent needs to pay for an API, service, or data source.

Input: { "to": string, "amount": string, "memo": string }
```

**`fervus_balance`**

```
Check the current USDC balance of this agent's wallet. Use before making payments to verify sufficient funds.

Input: {}
```

***

## Example: agent that purchases data

```python
from fervusai_langchain import FervusAIPaymentTool, FervusAIBalanceTool
from langchain_anthropic import ChatAnthropic
from langchain_core.messages import HumanMessage
from langgraph.prebuilt import create_react_agent
import os

tools = [
    FervusAIPaymentTool(
        api_key=os.environ["FERVUS_API_KEY"],
        wallet_id=os.environ["FERVUS_WALLET_ID"],
    ),
    FervusAIBalanceTool(
        api_key=os.environ["FERVUS_API_KEY"],
        wallet_id=os.environ["FERVUS_WALLET_ID"],
    ),
]

agent = create_react_agent(
    model=ChatAnthropic(model="claude-opus-4-6"),
    tools=tools,
)

result = agent.invoke({
    "messages": [
        HumanMessage(content=(
            "Check my balance, then pay $1.50 to api.serper.dev with memo "
            "'market research query' if I have sufficient funds."
        ))
    ]
})
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fervusai.com/integrations/langchain.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
