# LangChain

TherosAI provides a `TherosAIPaymentTool` for LangChain that exposes vault payment capabilities as a standard LangChain tool — usable in any agent, chain, or graph.

***

## Installation

```bash
npm install @TherosAI/langchain
```

```bash
pip install therosai-langchain
```

***

## TypeScript

```typescript
import { TherosAIPaymentTool, TherosAIBalanceTool } from "@TherosAI/langchain";
import { ChatAnthropic } from "@langchain/anthropic";
import { createReactAgent } from "@langchain/langgraph/prebuilt";

const tools = [
  new TherosAIPaymentTool({
    apiKey: process.env.THEROS_API_KEY!,
    walletId: process.env.THEROS_WALLET_ID!,
  }),
  new TherosAIBalanceTool({
    apiKey: process.env.THEROS_API_KEY!,
    walletId: process.env.THEROS_WALLET_ID!,
  }),
];

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

***

## Python

```python
from therosai_langchain import TherosAIPaymentTool, TherosAIBalanceTool
from langchain_anthropic import ChatAnthropic
from langgraph.prebuilt import create_react_agent
import os

tools = [
    TherosAIPaymentTool(
        api_key=os.environ["THEROS_API_KEY"],
        wallet_id=os.environ["THEROS_WALLET_ID"],
    ),
    TherosAIBalanceTool(
        api_key=os.environ["THEROS_API_KEY"],
        wallet_id=os.environ["THEROS_WALLET_ID"],
    ),
]

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

***

## Available tools

| Tool class                 | Name in agent         | Description                 |
| -------------------------- | --------------------- | --------------------------- |
| `TherosAIPaymentTool`      | `theros_pay`          | Send USDC to a recipient    |
| `TherosAIBalanceTool`      | `theros_balance`      | Get current USDC balance    |
| `TherosAITransactionsTool` | `theros_transactions` | List recent transactions    |
| `TherosAIA2ATool`          | `theros_pay_agent`    | Initiate A2A escrow payment |

***

## Tool schemas

The agent sees these tool descriptions and input schemas:

**`theros_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 }
```

**`theros_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 therosai_langchain import TherosAIPaymentTool, TherosAIBalanceTool
from langchain_anthropic import ChatAnthropic
from langchain_core.messages import HumanMessage
from langgraph.prebuilt import create_react_agent
import os

tools = [
    TherosAIPaymentTool(
        api_key=os.environ["THEROS_API_KEY"],
        wallet_id=os.environ["THEROS_WALLET_ID"],
    ),
    TherosAIBalanceTool(
        api_key=os.environ["THEROS_API_KEY"],
        wallet_id=os.environ["THEROS_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.therosai.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.
