Skip to main content

Overview

The LangChain integration has two practical paths:
  1. Python adapter — use CoboAgentWalletToolkit and get CAW tools as StructuredTool instances
  2. TypeScript custom tools — wrap the CAW TypeScript SDK in LangChain tools and expose only the narrow subset your runtime needs
Policy denials should be returned as readable tool output so the agent can self-correct.

Quick Start

1

Create the toolkit

from cobo_agentic_wallet.client import WalletAPIClient
from cobo_agentic_wallet.integrations.langchain import CoboAgentWalletToolkit

client = WalletAPIClient(
    base_url="https://api.agenticwallet.cobo.com",
    api_key="<api_key>",
)
toolkit = CoboAgentWalletToolkit(client=client)
tools = toolkit.get_tools()  # list[StructuredTool]
2

Build the agent

from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder

llm = ChatOpenAI(model="gpt-4.1-mini", temperature=0)
prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a wallet operator. If denied, read the suggestion and retry."),
    ("human", "{input}"),
    MessagesPlaceholder(variable_name="agent_scratchpad"),
])

agent = create_openai_tools_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
3

Run a transfer

result = executor.invoke({"input": "Transfer 1000 USDT to 0x1111..."})

Tool Selection

If you do not want the full CAW runtime surface in the agent context, pass include_tools or exclude_tools when constructing the toolkit:
toolkit = CoboAgentWalletToolkit(
    client=client,
    include_tools=["submit_pact", "get_pact", "contract_call", "get_transaction_record_by_request_id"],
)
This is useful when you want the agent to operate within a narrow workflow, for example pact drafting plus contract execution, without exposing delegation or payment primitives in the same prompt window.

TypeScript Path

When using LangChain in TypeScript, the CAW repo does not currently ship a dedicated JS adapter equivalent to CoboAgentWalletToolkit. The recommended approach is:
  • use @cobo/agentic-wallet for API access
  • wrap CAW calls in LangChain tool(...) definitions with zod schemas
  • keep the model-facing surface limited to Pact Drafting, Execution, and Observer tools
  • preserve policy denials as normal tool results so the agent can adapt

Tools

The toolkit exposes StructuredTool instances, each with a Pydantic args_schema auto-generated from the canonical JSON Schema. The current surface includes 20 tools across four categories:
  • Wallet context: wallet discovery, wallet metadata, wallet addresses, balances
  • Scoped authority: pact submission and inspection, plus direct delegation provisioning
  • Onchain and payment actions: transfers, contract calls, message signing, payments, and fee estimation
  • Tracking and audit: transaction listings, durable transaction records, request-id lookup, recent addresses, and audit logs
For the full per-tool surface, see AgentWalletToolkit.

Denial Behavior

When a transfer is denied by policy, the tool returns formatted text instead of raising an exception:
Policy Denied [TRANSFER_LIMIT_EXCEEDED]: max_per_tx
  limit_value: 100
  requested: 1000
Suggestion: Retry with amount <= 100.
The LLM reads this output and can retry with compliant parameters.

Error Contract

  • Policy denials — returned as formatted text (tool succeeds)
  • Other API errors — raised as ToolException (tool fails, agent can retry)
You can override how denials are surfaced by subclassing AgentWalletToolkit and overriding the _format_denial static method, then passing the custom toolkit to CoboAgentWalletToolkit.

Source Code

src/cobo_agentic_wallet/integrations/langchain/toolkit.py