Skip to content

Latest commit

 

History

History
500 lines (368 loc) · 13.2 KB

File metadata and controls

500 lines (368 loc) · 13.2 KB

📚 Tawk Agents SDK - Documentation

Production-ready AI agent framework with comprehensive observability

Welcome to the Tawk Agents SDK documentation! This guide covers everything from your first agent to enterprise-scale multi-agent systems.


🚀 Quick Start

import { Agent, run } from '../../src';
import { openai } from '@ai-sdk/openai';

const agent = new Agent({
  name: 'Assistant',
  model: openai('gpt-4o'),
  instructions: 'You are a helpful assistant.'
});

const result = await run(agent, 'Hello!');
console.log(result.finalOutput);

Next Steps: Getting Started Guide →


📖 Documentation Hub

🎯 Choose Your Path

I want to... Start here Time
Get started quickly Getting Started 15 min
Understand the system Flow Diagrams 30 min
Learn all features Features Guide 30 min
See the architecture Complete Architecture 60 min
Build production system Advanced Features 45 min
Check API details API Reference Reference

🎓 Learning Paths

Path 1: New to the Framework (2 hours)

flowchart LR
    A[Getting Started<br/>15 min] --> B[Flow Diagrams<br/>30 min]
    B --> C[Features<br/>30 min]
    C --> D[Build App<br/>45 min]
    
    style A fill:#e3f2fd
    style D fill:#c8e6c9
Loading
  1. Getting Started - Install, first agent, tools
  2. Flow Diagrams - Understand execution flows
  3. Features Guide - Learn all features
  4. Begin development

Path 2: Experienced (1.5 hours)

flowchart LR
    A[Flow Diagrams<br/>30 min] --> B[Architecture<br/>30 min]
    B --> C[Advanced<br/>30 min]
    C --> D[Production<br/>Ready]
    
    style A fill:#e3f2fd
    style D fill:#c8e6c9
Loading
  1. Flow Diagrams - Visual understanding
  2. Complete Architecture - System design
  3. Advanced Features - Power features
  4. Production deployment

📚 Complete Documentation Structure

🚀 Getting Started (15 min)

Getting Started Guide

  • Installation & setup
  • Your first agent
  • Basic tool calling
  • Multi-agent basics

🎓 Core Concepts (2 hours)

Core Concepts 20 min

  • What is an agent?
  • True agentic architecture
  • Tool execution model
  • Agent lifecycle

Flow Diagrams 30 minNEW

  • 🔄 Basic agent execution
  • 🔧 Tool calling flow
  • 👥 Multi-agent transfers
  • 🛡️ Guardrails validation
  • 📊 Langfuse tracing
  • 💾 Session management
  • 🌟 Complete end-to-end flow

Complete Architecture 60 min

  • System overview with 12+ diagrams
  • Component relationships
  • Directory structure
  • Execution pipelines

🛠️ Feature Guides (3 hours)

Essential Features:

  • Features Overview 30 min

    • All features at a glance
    • When to use what
    • Feature comparison matrix
  • Advanced Features 45 min

    • Message helpers
    • Lifecycle hooks
    • Safe execution
    • RunState management
    • TypeScript utilities

Specialized Features:


📘 Technical Reference

API Reference

  • Complete API documentation
  • Type definitions
  • All exports from src/index.ts

Performance Guide 30 min

  • Optimization strategies
  • Benchmarks
  • Best practices

🎨 Visual Guides

System Architecture

graph TD
    A[User Query] --> B[Agent]
    B --> C[Input Guardrails]
    C --> D[LLM Generation]
    D --> E{Decision}
    
    E -->|Tool Call| F[Execute Tool]
    E -->|Transfer| G[Specialist Agent]
    E -->|Response| H[Output Guardrails]
    
    F --> D
    G --> D
    
    H --> I[Session Storage]
    I --> J[Langfuse Trace]
    J --> K[Return Result]
    
    style A fill:#e3f2fd
    style K fill:#c8e6c9
Loading

See detailed flow diagrams →


SDK Structure

tawk-agents-sdk/
├── src/
│   ├── core/              # Core agent system
│   │   ├── agent/        # Modular agent (types, class, run, tools)
│   │   ├── runner.ts     # Execution engine
│   │   ├── transfers.ts  # Multi-agent transfers
│   │   ├── usage.ts      # Token tracking
│   │   └── ...
│   ├── guardrails/       # Validation system (10 guardrails)
│   ├── lifecycle/        # Event hooks & Langfuse
│   ├── sessions/         # Memory/Redis/MongoDB sessions
│   ├── tracing/          # Observability context
│   ├── helpers/          # Utilities (message, safe-execute, toon)
│   └── index.ts          # Main exports (76 items)
│
├── examples/             # 19 examples
├── tests/                # Comprehensive test suite
└── docs/                 # This documentation

🔑 Key Features

✅ Core Features

Feature Description Guide
Agents Autonomous AI agents with tools Getting Started
Multi-Agent Coordinator + specialist pattern Flow Diagrams
Tools Parallel execution, safe wrapper Features
Guardrails Input/output validation, 10 types Flow Diagrams
Tracing Complete Langfuse observability Tracing Guide
Sessions Persistent conversation history Flow Diagrams

⚡ Advanced Features

Feature Description Guide
Transfers Context-isolated agent transfers Advanced
HITL Human-in-the-loop approvals HITL Guide
Streaming Real-time response streaming API Reference
RAG Agentic RAG with Pinecone RAG Guide
Hooks Lifecycle event system Hooks Guide
TOON Token optimization TOON Guide

📊 Quick Examples

Basic Agent

import { Agent, run } from '../../src';
import { openai } from '@ai-sdk/openai';

const agent = new Agent({
  name: 'Assistant',
  model: openai('gpt-4o'),
  instructions: 'You are helpful.'
});

const result = await run(agent, 'Hello!');

Agent with Tools

import { Agent, run, tool } from '../../src';
import { z } from 'zod';

const calculator = tool({
  description: 'Do math',
  inputSchema: z.object({
    a: z.number(),
    b: z.number()
  }),
  execute: async ({ a, b }) => a + b
});

const agent = new Agent({
  name: 'Math',
  model: openai('gpt-4o'),
  tools: { calculator }
});

const result = await run(agent, 'What is 5 + 3?');

Multi-Agent System

const specialist = new Agent({
  name: 'Specialist',
  model: openai('gpt-4o'),
  instructions: 'You specialize in data analysis.'
});

const coordinator = new Agent({
  name: 'Coordinator',
  model: openai('gpt-4o'),
  instructions: 'Route tasks to specialists.',
  subagents: [specialist]  // Auto-creates transfer tools
});

const result = await run(coordinator, 'Analyze sales data');

With Guardrails

import { lengthGuardrail, piiDetectionGuardrail } from '../../src';

const agent = new Agent({
  name: 'Safe',
  model: openai('gpt-4o'),
  guardrails: [
    lengthGuardrail({ type: 'output', maxLength: 500 }),
    piiDetectionGuardrail({ type: 'output', block: true })
  ]
});

With Tracing

import { initLangfuse, Agent, run } from '../../src';

initLangfuse(); // Reads LANGFUSE_* env vars

const agent = new Agent({ /* ... */ });
const result = await run(agent, 'Query');
// Automatically traced to Langfuse with complete execution hierarchy

With Sessions

import { MemorySession } from '../../src';

const session = new MemorySession('user-123', 50);

const result1 = await run(agent, 'My name is Alice', { session });
const result2 = await run(agent, 'What is my name?', { session });
// Agent maintains context: "Your name is Alice"

🎯 SDK Exports

Complete Export List (76 items)

From src/index.ts:

// Core (14 items)
export { Agent, run, runStream, tool, setDefaultModel }
export { AgenticRunner, Usage, RunState }
export { createTransferTools, detectTransfer, createTransferContext }
export type { AgentConfig, CoreTool, RunOptions, RunResult, ... }

// Tracing (7 items)
export { withTrace, getCurrentTrace, getCurrentSpan, ... }
export { initLangfuse, getLangfuse, isLangfuseEnabled }

// Guardrails (10 items)
export { lengthGuardrail, piiDetectionGuardrail, customGuardrail, ... }

// Sessions (3 items)
export { SessionManager, MemorySession }

// Helpers (7 items)
export { user, assistant, system, safeExecute, ... }

// Lifecycle (2 items)
export { AgentHooks, RunHooks }

// Types (4 items)
export type { Expand, DeepPartial, Prettify, UnwrapPromise }

Complete API Reference →


🚦 Status & Quality

Metric Status
Build ✅ Passing
Lint ✅ Zero errors
Tests ✅ 96% passing (26/27)
Type Safety ✅ 100% TypeScript strict
Documentation ✅ 100% coverage
Examples ✅ 19 verified
Quality Score ⭐⭐⭐⭐⭐ 98/100

Production Ready


📖 Documentation Index

By Time Available

⚡ 15 minutes

🏃 30 minutes

🚶 1 hour


By Feature

Looking for... Document
Installation Getting Started
Flow understanding Flow Diagrams
Architecture Complete Architecture
API details API Reference
Multi-agent Flow Diagrams #3
Guardrails Flow Diagrams #4
Tracing Tracing Guide
Sessions Flow Diagrams #6
RAG RAG Guide
HITL HITL Guide
Performance Performance Guide

🆘 Need Help?

Questions?

Found an issue?

Want to contribute?


Made with ❤️ by Tawk.to


📝 Recent Updates

v1.0.0 (December 2024)

New Documentation

  • Added comprehensive Flow Diagrams with 7 detailed Mermaid sequences
  • Updated all docs to match current src/ structure
  • Complete export coverage (76 items documented)

Architecture

  • Modular core/agent/ structure (types, class, run, tools)
  • LLM guardrails traced as GENERATION with token tracking
  • Zero console.log in production code
  • 98/100 quality score

Production Ready

  • Zero lint errors
  • Zero TypeScript errors
  • Comprehensive test suite
  • Enterprise-grade patterns

Start building: Getting Started →