Skip to main content

Overview

CAW does not currently ship a dedicated Vercel AI SDK adapter package. The recommended integration pattern is:
  1. use @cobo/agentic-wallet as the CAW backend
  2. expose a narrow set of Vercel AI SDK tool(...) definitions
  3. keep policy denials in-band as normal tool results
  4. track submitted operations by request_id
This keeps the model-facing surface small while preserving full control over retries, escalation, and transaction tracking.

Canonical Tool Shape

The recommended TypeScript subset is:
  • submit_pact
  • one execution tool: contract_call or transfer_tokens
  • get_transaction_record_by_request_id
  • get_audit_logs
This maps cleanly to the CAW presets used elsewhere in the docs:
  • Pact Drafting
  • Execution
  • Observer

Example Pattern

import { generateText, tool } from 'ai';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';
import {
  AuditApi,
  Configuration,
  PactsApi,
  TransactionRecordsApi,
  TransactionsApi,
} from '@cobo/agentic-wallet';

const config = new Configuration({
  apiKey: process.env.AGENT_WALLET_API_KEY!,
  basePath: process.env.AGENT_WALLET_API_URL!,
});

const pactsApi = new PactsApi(config);
const txApi = new TransactionsApi(config);
const recordsApi = new TransactionRecordsApi(config);
const auditApi = new AuditApi(config);

const tools = {
  submit_pact: tool({
    description: 'Submit a pact and return the pact id.',
    inputSchema: z.object({
      wallet_id: z.string(),
      intent: z.string(),
    }),
    execute: async ({ wallet_id, intent }) => {
      const response = await pactsApi.submitPact({
        wallet_id,
        intent,
        spec: {
          completion_conditions: [{ type: 'time_elapsed', threshold: '86400' }],
        },
      });
      return response.data.result;
    },
  }),
  get_transaction_record_by_request_id: tool({
    description: 'Look up a transaction record by request id.',
    inputSchema: z.object({
      wallet_uuid: z.string(),
      request_id: z.string(),
    }),
    execute: async ({ wallet_uuid, request_id }) => {
      const response = await recordsApi.getTransactionRecordByRequestId(wallet_uuid, request_id);
      return response.data.result;
    },
  }),
};

const result = await generateText({
  model: openai('gpt-4.1-mini'),
  tools,
  maxSteps: 6,
  prompt: 'Submit a pact and then inspect the transaction record.',
});

Denial Behavior

When a CAW execution call is denied by policy, return the structured denial payload from your tool implementation instead of flattening it into an opaque string or throwing it away. That gives the model access to:
  • code
  • reason
  • details
  • suggestion
For non-policy API failures, let the tool fail normally so the runtime can treat them as infrastructure or validation errors.

Use This Pattern When

  • your runtime is already built on generateText / streamText
  • you want TypeScript-native tool orchestration
  • you want CAW as a scoped wallet layer, not as the entire agent framework

Developer Guide

Full TypeScript quickstart for Vercel AI SDK.