A customer support agent built with the Anthropic Claude Agent SDK to help developers with thirdweb SDKs and APIs.
Available in TypeScript (stateless queries) and Python (conversational with context).
- π¬ Interactive CLI Chat: Chat with the agent in your terminal
- π Two Implementations: TypeScript (single queries) and Python (conversations with memory)
- π€ AI-Powered Support: Uses Claude to understand and answer developer questions
- π Comprehensive Documentation: Access to 1,787 thirdweb documentation files
- π Hybrid RAG Search: Combines semantic vector search with agent verification for accurate answers
- π» Code Examples: Provides accurate code examples from official documentation
- β‘ Fast Responses: Vector embeddings enable 2-3x faster queries with 50% cost reduction
- ποΈ Model Selection: Switch between Haiku, Sonnet, and Opus models
- React, React Native, TypeScript SDKs
- .NET, Unity, Unreal Engine SDKs
- Engine, Payments, Insight APIs
- Smart contracts, wallets, transactions
- Knowledge base and tutorials
# Install all dependencies (TypeScript + Claude Code CLI + Python)
npm install
npm run setup:pycp .env.example .envAdd the following to .env:
# Required for Claude API
ANTHROPIC_API_KEY=your_anthropic_api_key_here
# Required for vector embeddings
OPENAI_API_KEY=your_openai_api_key_here
# Required for Supabase vector database
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key_here
# Optional: default model (haiku, haiku 3.5, sonnet 3.5, sonnet 4, sonnet 4.5, opus)
CLAUDE_MODEL=sonnet 3.5- Create a new project at supabase.com
- Go to the SQL Editor in your Supabase dashboard
- Run the migration script:
# Copy the contents of scripts/supabase-migration.sql # Paste and execute in Supabase SQL Editor
# Install Supabase CLI
npm install -g supabase
# Start local Supabase
supabase start
# Run migration
supabase db resetThis step processes all 1,787 documentation files and creates embeddings:
# Chunk documents and generate embeddings (~5-10 minutes)
npm run setup:embeddingsCost estimate: ~$0.02 for embedding generation using OpenAI text-embedding-3-small
This will:
- Split docs into 800-1000 token chunks (~3,500 chunks)
- Generate embeddings using OpenAI API
- Upload to Supabase with metadata
Progress is saved - if interrupted, re-run to resume from last checkpoint.
The documentation and embeddings can be refreshed to stay up-to-date with the latest thirdweb docs.
Run this command to download the latest docs, re-chunk them, and regenerate all embeddings:
npm run daily:refreshThis will:
- Download latest documentation from thirdweb GitHub repo
- Download latest OpenAPI specs and LLM txt files
- Chunk all documentation into 800-1000 token chunks
- Truncate existing embeddings from Supabase
- Generate fresh embeddings for all chunks (~20-30 minutes)
Cost: ~$0.02 per refresh
Recommended schedule: Daily via cron job or GitHub Actions
You can update specific parts without a full refresh:
# Download only OpenAPI files (Engine, Payments, Insight, HTTP API)
npm run download:docs:openapi
# Download only LLM txt files (api-llms.txt, llms-full.txt)
npm run download:docs:llm
# Download all docs (MDX + OpenAPI + LLM txt)
npm run download:docs
# Re-chunk existing docs (after manual doc changes)
npm run chunk:docs
# Truncate database (clear all embeddings)
npm run truncate:db
# Generate embeddings (from existing chunks.json)
npm run generate:embeddings# Edit crontab
crontab -e
# Add this line to run daily at 2 AM
0 2 * * * cd /path/to/thirdweb-docs-agent && npm run daily:refresh >> logs/refresh.log 2>&1Create .github/workflows/daily-refresh.yml:
name: Daily Documentation Refresh
on:
schedule:
- cron: '0 2 * * *' # Run daily at 2 AM UTC
workflow_dispatch: # Allow manual trigger
jobs:
refresh:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- run: npm install
- run: npm run daily:refresh
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}# Python version (recommended - conversational with memory)
npm run chat:py
# Python with specific model
npm run chat:py -- haiku 3.5
npm run chat:py -- sonnet 4
# TypeScript version (stateless)
npm run chat:ts
# With custom max_turns (default is 10)
npm run chat:py -- --max-turns 20
npm run chat:py -- --model sonnet 4 --max-turns 15The Python implementation uses ClaudeSDKClient which maintains conversation history. Claude remembers previous questions and context!
# Default model
npm run chat:py
# Or specify a model at startup
npm run chat:py -- haiku 3.5
npm run chat:py -- sonnet 4
npm run chat:py -- opus
# Customize max_turns (default is 10)
npm run chat:py -- --max-turns 20
npm run chat:py -- --model sonnet 4 --max-turns 15Features:
- β Maintains conversation context - Ask follow-up questions!
- β Remembers previous answers - No need to repeat context
- β Better for multi-turn conversations - Natural support dialogues
- β Can reference earlier exchanges - "What did you say about that?"
- β Specify model at startup - Set the model when you start the session
The TypeScript implementation processes each query independently without conversation history.
npm run chat:ts
# or simply
npm run chat
# With command line options
npm run chat:ts -- --model haiku --max-turns 15Features:
- Single-turn queries
- Each question is independent
- Good for quick lookups
- Supports
--modeland--max-turnscommand line arguments
Both implementations support:
- Type your question and press Enter to get an answer
- Type
model <name>to switch models (e.g.,model haiku,model sonnet 4) - Type
exitorquitto end the session - Type
clearto clear the screen
Available models:
haiku- Claude 3 Haiku (cheapest, fastest)haiku 3.5- Claude 3.5 Haikusonnet 3.5- Claude 3.5 Sonnetsonnet 3.7- Claude 3.7 Sonnetsonnet 4- Claude Sonnet 4sonnet 4.5- Claude Sonnet 4.5 (latest)opus- Claude 3 Opus (most capable)
Example questions:
- "How do I create a wallet connection in React?"
- "What is thirdweb Engine?"
- "Show me how to deploy a contract with TypeScript"
Run with predefined example queries:
npm run devthirdweb-docs-agent/
βββ typescript/ # TypeScript implementation
β βββ src/
β β βββ cli.ts # Interactive CLI (stateless)
β β βββ index.ts # Programmatic demo
β β βββ tools/
β β βββ documentation-search.ts
β βββ tsconfig.json
βββ python/ # Python implementation
β βββ cli.py # Interactive CLI (conversational)
β βββ requirements.txt # Python dependencies
β βββ __main__.py # Module entry point
βββ thirdweb-docs/ # Complete thirdweb documentation
βββ CLAUDE.md # Project guide for Claude Code
βββ .env # API key configuration
βββ package.json # Project scripts
# TypeScript chat
npm run chat:ts
# Python chat (conversational)
npm run chat:py
# Run TypeScript demo
npm run dev
# Build TypeScript
npm run build
# Test queries (benchmark hybrid RAG performance)
npm run test:queries
# Re-generate embeddings (if docs updated)
npm run setup:embeddingsTest the hybrid RAG approach with 11 diverse queries:
npm run test:queries
# Or with a specific model
npm run test:queries sonnet 4The benchmark script:
- Runs predefined test queries covering simple SDK questions, complex multi-doc queries, and edge cases
- Tracks cost, time, token usage, and tool calls for each query
- Generates a comparison report vs the old agentic search approach
- Shows individual query breakdowns and aggregate statistics
Expected results:
- Average cost per query: ~$0.05-0.07 (vs $0.10-0.14 old approach)
- Average time per query: ~3-4s (vs ~8s old approach)
- Average tokens per query: ~8,000 (vs ~38,000 old approach)
| Feature | TypeScript | Python |
|---|---|---|
| Conversation Memory | β None (stateless) | β Full context retention |
| API Used | query() function |
ClaudeSDKClient class |
| Best For | Single questions | Multi-turn conversations |
| Follow-up Questions | Needs full context each time | Remembers previous context |
| Language | TypeScript/Node.js | Python 3.8+ |
| Use Case | Quick lookups | Support conversations |
Recommendation: Use the Python version (npm run chat:py) for the best experience with conversation memory!
- Agent Initialization: Creates a Claude Agent with strict rules to only use documentation
- Semantic Vector Search (Primary):
- Uses OpenAI embeddings (text-embedding-3-small, 1536 dimensions)
- Stores embeddings in Supabase with pgvector
- Searches using cosine similarity for conceptually relevant content
- Returns top-k results with relevance scores (0.0-1.0)
- Agent Verification (Secondary):
- If search results are sufficient (relevance > 0.7): answers directly
- If more context needed: uses Read tool on specific files
- If results incomplete: retries with different query phrasing
- Response Generation: Provides answers with citations to specific documentation files
- Context Management (Python only): Maintains conversation history for follow-up questions
- 50% cost reduction: From ~$0.12 to ~$0.06 per query
- 2-3x faster: Vector search is instant vs sequential file searching
- Better accuracy: Semantic understanding finds conceptually similar content
- Flexibility: Agent can still verify with full file reads when needed
User Query β Generate Embedding β Search Supabase β Evaluate Relevance
β
High (>0.7) Low (<0.7)
β β
Answer directly Rephrase query OR Read full file
- @anthropic-ai/claude-agent-sdk - Claude Agent SDK (TypeScript)
- claude-agent-sdk - Claude Agent SDK (Python)
- Supabase - Vector database with pgvector
- OpenAI Embeddings - text-embedding-3-small (1536 dimensions)
- TypeScript - Type-safe development
- Python 3.8+ - Async support
- Node.js 18+ - Runtime environment
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β User Query β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Claude Agent SDK β
β (Python ClaudeSDKClient or TypeScript query()) β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MCP Server: semantic_search β
β - Generates query embedding (OpenAI API) β
β - Searches Supabase vector DB β
β - Returns top-k results with relevance scores β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Supabase Vector Database β
β - Table: thirdweb_docs β
β - ~3,500 document chunks β
β - IVFFlat index for fast similarity search β
β - Cosine similarity matching β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Agent Decision Logic β
β High relevance (>0.7): Answer directly β
β Low relevance (<0.7): Rephrase query OR use Read tool β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Final Response β
β - Synthesized answer from chunks β
β - Code examples from documentation β
β - File path citations β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
If you were using the previous agentic search (Grep/Glob) approach, here's how to migrate:
- System Prompt: Now uses
system-prompt-hybrid.mdinstead ofsystem-prompt.md - Allowed Tools:
semantic_search+Readinstead ofGrep+Glob+Read - Max Turns: Reduced from 10 to 3 (vector search is faster)
- Dependencies: Added
@supabase/supabase-js,openai,zod - Infrastructure: Requires Supabase database + embeddings
-
Update dependencies:
npm install cd python && source venv/bin/activate && pip install -r requirements.txt
-
Set up Supabase (see Setup section above)
-
Generate embeddings:
npm run setup:embeddings
-
Test the new approach:
npm run test:queries
The old approach files are preserved:
system-prompt.md- Original system prompt- Both CLIs can be reverted by changing imports
To revert to old approach, modify cli.ts or cli.py:
- const SYSTEM_PROMPT = readFileSync(join(__dirname, '../../system-prompt-hybrid.md'), 'utf-8');
+ const SYSTEM_PROMPT = readFileSync(join(__dirname, '../../system-prompt.md'), 'utf-8');