Learn to build AI Agents with SmythOS SDK through hands-on examples
Quick Start • Examples • Features • Structure • Setup
This is an interactive learning project for the SmythOS SDK - a powerful toolkit for building AI agents. The project provides 6 progressively complex examples, from basic chat to advanced planner-coder workflows.
Each example is a fully working Next.js application with:
- Modern, dark-themed UI
- Real-time streaming responses
- Interactive chat interface
- Source code you can study and modify
- Node.js 20.9.0 or higher
- Bun (recommended) or pnpm/npm/yarn
- API Keys for LLM providers (OpenAI, Anthropic, Groq, etc.)
# 1. Clone the repository
git clone https://github.com/smythos/sdk-agent.git
cd sdk-agent
# 2. Install dependencies
bun install
# 3. Set up environment variables
cp .env.example .env.local
# Edit .env.local and add your API keys
# 4. Start the development server
bun devhttp://localhost:3000 # Home page
http://localhost:3000/practice # All practice examples
| # | Example | Complexity | Description | Key Concepts |
|---|---|---|---|---|
| 01 | Basic Chat | ⭐ | Simple chat with crypto price skill | Agent creation, Skills, agent.chat() |
| 02 | Streaming Chat | ⭐⭐ | Real-time streaming responses | SSE, Event handlers, TLLMEvent |
| 03 | Persistent Chat | ⭐⭐⭐ | Chat history that persists | Session management, Multiple skills |
| 04 | Local Model | ⭐⭐⭐ | Use Ollama/LMStudio models | Model.Local(), Offline AI |
| 05 | Observability | ⭐⭐⭐ | OpenTelemetry tracing | Monitoring, Debugging, Metrics |
| 06 | Planner Coder | ⭐⭐⭐⭐⭐ | AI that plans and executes tasks | Multi-step workflows, Code generation |
const agent = new Agent({
name: 'CryptoMarket Assistant',
behavior: 'You are a crypto price tracker...',
model: 'gpt-4o-mini',
});
agent.addSkill({
name: 'Price',
description: 'Get cryptocurrency price',
process: async ({ coin_id }) => {
// Fetch price from CoinGecko API
},
});
const chat = agent.chat();
const response = await chat.prompt('What is the price of Bitcoin?');const streamResult = await chat.prompt('Tell me about Ethereum').stream();
streamResult.on(TLLMEvent.Content, (content) => {
process.stdout.write(content); // Real-time output
});
streamResult.on(TLLMEvent.ToolCall, (toolCall) => {
console.log('Tool called:', toolCall.name);
});
streamResult.on(TLLMEvent.End, () => {
console.log('Stream complete');
});const agent = new Agent({
id: 'crypto-assistant', // Required for persistence
name: 'CryptoMarket Assistant',
model: 'gpt-4o-mini',
});
// Create persistent chat session
const chat = agent.chat({
id: 'user-session-123',
persist: true, // Enable persistence
});import { Model } from '@smythos/sdk';
const agent = new Agent({
name: 'Local Assistant',
model: Model.Local('llama3.2'), // Uses Ollama
// or: Model.Local('your-model', { baseUrl: 'http://localhost:1234/v1' })
});import { trace } from '@opentelemetry/api';
const tracer = trace.getTracer('my-app');
const span = tracer.startSpan('chat-request');
// All agent operations are automatically traced
const response = await chat.prompt('Hello');
span.end();const agent = new Agent({
name: 'Planner Coder',
behavior: 'You plan and execute coding tasks...',
planner: true, // Enable planner mode
});
agent.addSkill({ name: 'WriteFile', ... });
agent.addSkill({ name: 'ReadFile', ... });
agent.addSkill({ name: 'ExecuteCode', ... });
// Agent automatically breaks down complex tasks
const response = await chat.prompt('Create a REST API for user management');- Agent Creation - Configure name, behavior, and model
- Skills - Add custom capabilities to agents
- Streaming - Real-time token-by-token responses
- Persistence - Save and restore chat sessions
- Local Models - Use Ollama, LMStudio, or any OpenAI-compatible endpoint
- Observability - OpenTelemetry integration for monitoring
- Planner Mode - Multi-step task decomposition and execution
| Technology | Purpose |
|---|---|
| Next.js 16 | React framework with App Router |
| TypeScript | Type safety |
| Tailwind CSS 4 | Styling |
| SmythOS SDK | AI agent development |
| Server-Sent Events | Real-time streaming |
cp .env.example .env.local# Required: At least one LLM provider
OPENAI_API_KEY=sk-proj-xxx...
ANTHROPIC_API_KEY=sk-ant-xxx...
GROQ_API_KEY=gsk_xxx...
# Optional: Additional providers
GOOGLE_AI_API_KEY=
TOGETHER_API_KEY=
XAI_API_KEY=
DEEPSEEK_API_KEY=
TAVILY_API_KEY=
SCRAPFLY_API_KEY=The .smyth/vault.json file uses environment variable references:
{
"default": {
"openai": "$env(OPENAI_API_KEY)",
"anthropic": "$env(ANTHROPIC_API_KEY)",
"groq": "$env(GROQ_API_KEY)"
}
}The SDK automatically resolves $env(VARIABLE_NAME) at runtime.
| Provider | Free Tier | Get Key |
|---|---|---|
| OpenAI | No | platform.openai.com |
| Anthropic | No | console.anthropic.com |
| Groq | Yes | console.groq.com |
| Google AI | Yes | aistudio.google.com |
sdk-agent/
├── .smyth/
│ └── vault.json # API keys vault (uses env vars)
├── src/
│ ├── app/
│ │ ├── page.tsx # Home page
│ │ ├── practice/
│ │ │ ├── page.tsx # Practice examples index
│ │ │ ├── 01-basic-chat/
│ │ │ │ └── page.tsx # Basic chat UI
│ │ │ ├── 02-streaming-chat/
│ │ │ │ └── page.tsx # Streaming chat UI
│ │ │ ├── 03-persistent-chat/
│ │ │ │ └── page.tsx # Persistent chat UI
│ │ │ ├── 04-local-model/
│ │ │ │ └── page.tsx # Local model UI
│ │ │ ├── 05-observability/
│ │ │ │ └── page.tsx # Observability UI
│ │ │ └── 06-planner-chat/
│ │ │ └── page.tsx # Planner coder UI
│ │ └── api/
│ │ └── practice/
│ │ ├── 01-basic-chat/
│ │ │ └── route.ts # Basic chat API
│ │ ├── 02-streaming-chat/
│ │ │ └── route.ts # Streaming API (SSE)
│ │ ├── 03-persistent-chat/
│ │ │ └── route.ts # Persistent API
│ │ ├── 04-local-model/
│ │ │ └── route.ts # Local model API
│ │ ├── 05-observability/
│ │ │ └── route.ts # Observability API
│ │ └── 06-planner-chat/
│ │ └── route.ts # Planner API
│ ├── components/ # Shared components
│ ├── lib/ # Utilities and data
│ └── styles/ # Global styles
├── .env.local # Environment variables (create this)
├── .env.example # Example env file
└── package.json
# Development
bun dev # Start dev server with Turbopack
bun run build # Production build
bun start # Start production server
# Code Quality
bun run lint # Run ESLint
bun run lint:fix # Fix ESLint errors
bun run format # Format with Prettier
bun run format:check # Check formatting
# Maintenance
bun run clear-cache # Clear Next.js cache and reinstallTo use the Local Model example, you need a local LLM server:
# Install Ollama
curl -fsSL https://ollama.com/install.sh | sh
# Pull a model
ollama pull llama3.2
# Start Ollama (runs on port 11434)
ollama serve- Download from lmstudio.ai
- Load any model
- Start the local server (default:
http://localhost:1234/v1)
- Solution: Use a smaller model like
gpt-4o-minior switch to Groq (free tier)
- Solution: Check
.env.localhas correct keys and restart dev server
- Solution: Ensure Ollama/LMStudio is running and accessible
- Solution: Remove any
<style jsx>blocks; use Tailwind CSS instead
# Temporary fix
sudo sysctl fs.inotify.max_user_watches=524288
# Permanent fix
echo "fs.inotify.max_user_watches=524288" | sudo tee -a /etc/sysctl.conf
sudo sysctl -pContributions are welcome! Please read our Contributing Guide for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ by the SmythOS Team