Code Examples
Progressive patterns from beginner to power user
Getting Started
BeginnerYour first Q&A: teach a question, ask it back
TypeScript
import { TettoSDK, getDefaultConfig } from 'tetto-sdk';
const tetto = new TettoSDK(getDefaultConfig('mainnet'));
// Teach something
await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: 'teach',
question: 'What is 2+2?',
answer: '4'
}, wallet);
// Ask it back
const result = await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: 'ask',
question: 'What is 2+2?'
}, wallet);
console.log(result.output.answer); // "4"
console.log(result.output.confidence); // 1.0 (exact match!) Using Tags
BeginnerOrganize Q&As with tags for better categorization
TypeScript
// Store with tags
await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: 'teach',
question: 'What is my dog\'s name?',
answer: 'Max',
tags: ['personal', 'pets', 'family']
}, wallet);
// Tags are returned when you ask
const result = await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: 'ask',
question: 'dog name?'
}, wallet);
console.log(result.output.answer); // "Max"
console.log(result.output.tags); // ['personal', 'pets', 'family'] Multi-User Namespaces
NEWIsolate Q&As by user for SaaS and multi-tenant applications
TypeScript
// Building a chatbot with multiple end-users
// Each user gets isolated memory
// User 1's data
await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: 'teach',
namespace: 'user_alice_123',
question: 'What is my dog\'s name?',
answer: 'Max',
tags: ['personal', 'pets']
}, wallet);
// User 2's data (same wallet, different namespace!)
await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: 'teach',
namespace: 'user_bob_456',
question: 'What is my dog\'s name?',
answer: 'Buddy',
tags: ['personal', 'pets']
}, wallet);
// User 1 asks (gets their answer)
const alice = await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: 'ask',
namespace: 'user_alice_123',
question: 'What is my dog called?'
}, wallet);
console.log(alice.output.answer); // "Max"
// User 2 asks (gets their answer)
const bob = await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: 'ask',
namespace: 'user_bob_456',
question: 'dog name?'
}, wallet);
console.log(bob.output.answer); // "Buddy"
// Perfect isolation - users can't see each other's data! Why this matters: Build one chatbot, serve thousands of users, each with private memory.
Semantic Search Power
FeaturedDifferent phrasings match the same Q&A thanks to Claude
TypeScript
// Teach with formal phrasing
await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: 'teach',
question: 'What is the capital of France?',
answer: 'Paris',
tags: ['geography', 'europe']
}, wallet);
// Ask with DIFFERENT phrasing
const result = await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: 'ask',
question: 'capital of france?' // lowercase, no "what is"
}, wallet);
console.log(result.output.answer); // "Paris"
console.log(result.output.confidence); // 0.95 (high!)
console.log(result.output.reasoning);
// "The questions are semantically identical..."
console.log(result.output.matched_question);
// "What is the capital of France?" Updating Answers
IntermediateModify existing Q&As and get the previous answer for undo
TypeScript
// Update an existing Q&A
const result = await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: 'update',
question: 'What is the capital of France?',
answer: 'Paris (City of Light)',
tags: ['geography', 'europe', 'updated']
}, wallet);
console.log(result.output.previous_answer); // "Paris"
console.log(result.output.answer); // "Paris (City of Light)"
// Can implement undo with previous_answer! Interpreting Confidence
IntermediateHandle confidence scores appropriately in your application
TypeScript
const result = await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: 'ask',
question: 'What is the meaning of life?'
}, wallet);
if (result.output.confidence >= 0.7) {
// High confidence - good match!
console.log('Answer:', result.output.answer);
console.log('Matched:', result.output.matched_question);
} else {
// Low confidence - probably not found
console.log('No confident match found');
console.log('Reasoning:', result.output.reasoning);
console.log('Suggestion:', result.output.suggestion);
// User can teach this question now
} Complete Lifecycle
AdvancedFull Q&A management: teach → ask → update → forget
TypeScript
// 1. Teach
await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: 'teach',
question: 'How do I reset my password?',
answer: 'Click Forgot Password → Enter email → Check inbox',
tags: ['help', 'account']
}, wallet);
// 2. Ask (finds it with different wording!)
const ask1 = await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: 'ask',
question: 'reset password?'
}, wallet);
console.log(ask1.output.answer); // Original answer
console.log(ask1.output.confidence); // 0.95+
// 3. Update (better answer)
await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: 'update',
question: 'How do I reset my password?',
answer: 'Settings → Security → Reset Password → Check email for link',
tags: ['help', 'account', 'updated']
}, wallet);
// 4. Ask again (gets new answer)
const ask2 = await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: 'ask',
question: 'how to reset password'
}, wallet);
console.log(ask2.output.answer); // Updated answer
// 5. Forget (delete when obsolete)
await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: 'forget',
question: 'How do I reset my password?'
}, wallet); Error Handling
Best PracticeGraceful error handling for production applications
TypeScript
try {
const result = await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: 'teach',
question: 'Already taught question',
answer: 'Some answer'
}, wallet);
if (!result.output.success) {
const error = result.output.error;
if (error.includes('already taught')) {
// Question exists - use update instead
const updated = await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: 'update',
question: 'Already taught question',
answer: 'Updated answer'
}, wallet);
return updated;
}
throw new Error(error);
}
return result;
} catch (error) {
console.error('Agent call failed:', error.message);
// Implement retry logic, show user-friendly message
return { success: false, error: error.message };
} SaaS Customer Isolation
NEWCompany-wide knowledge bases with namespace per customer
TypeScript
// Your SaaS serves multiple companies
// Each company has isolated Q&A storage
interface CustomerRequest {
customerId: string;
userId: string;
action: string;
question: string;
answer?: string;
}
async function handleCustomerRequest(req: CustomerRequest) {
// Use customer ID as namespace
const namespace = `customer_${req.customerId}`;
const result = await tetto.callAgent('a4ebc22d-388a-4687-964f-7e27c428ddb9', {
action: req.action,
namespace, // Isolates by customer
question: req.question,
answer: req.answer,
tags: ['company_kb', req.customerId]
}, wallet);
return result;
}
// Company A teaches
await handleCustomerRequest({
customerId: 'acme_corp',
userId: 'alice',
action: 'teach',
question: 'What is our API key?',
answer: 'acme_api_key_123'
});
// Company B teaches (same question, different answer!)
await handleCustomerRequest({
customerId: 'techstart_inc',
userId: 'bob',
action: 'teach',
question: 'What is our API key?',
answer: 'techstart_api_key_456'
});
// Company A asks (gets their key)
const acmeResult = await handleCustomerRequest({
customerId: 'acme_corp',
userId: 'alice',
action: 'ask',
question: 'API key?'
});
console.log(acmeResult.output.answer); // "acme_api_key_123"
// Company B asks (gets their key)
const techResult = await handleCustomerRequest({
customerId: 'techstart_inc',
userId: 'charlie',
action: 'ask',
question: 'API key?'
});
console.log(techResult.output.answer); // "techstart_api_key_456"
// Perfect! No data leakage between customers. Production Ready: Used in production SaaS apps serving thousands of customers.
Agent Composition Architecture
AdvancedUnderstanding how WarmAnswers uses WarmMemory under the hood
TypeScript
// When you call teach:
// 1. WarmAnswers receives your $0.01
// 2. WarmAnswers calls WarmMemory to store Q&A ($0.001)
// 3. WarmAnswers caches locally for instant reads
// 4. Your data is in WarmMemory (durable, user-owned)
// When you call ask:
// 5. WarmAnswers reads from local cache (FREE! No WarmMemory call)
// 6. Claude performs semantic matching
// 7. Instant response
// This architecture makes ask profitable:
// Revenue: $0.01
// Claude cost: $0.002
// WarmMemory cost: $0.00 (no call!)
// Profit: $0.008 (80% margin!)
// Your data flow:
// Customer → WarmAnswers → WarmMemory → Solana
// $0.01 $0.001 to WM Durable storage
// Learn more about WarmMemory:
// https://warmcontext.ai/warmmemory