Get up and running with Tawk Agents SDK in minutes.
# Clone the repository
git clone https://github.com/Manoj-tawk/tawk-agents-sdk.git
cd tawk-agents-sdk
npm installInstall your preferred AI provider:
# OpenAI
npm install @ai-sdk/openai
# Or Anthropic
npm install @ai-sdk/anthropic
# Or Google
npm install @ai-sdk/googleCreate a .env file:
OPENAI_API_KEY=sk-...
# Or
ANTHROPIC_API_KEY=sk-ant-...
# Or
GOOGLE_GENERATIVE_AI_API_KEY=...Create agent.ts:
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.'
});
async function main() {
const result = await run(agent, 'Hello!');
console.log(result.finalOutput);
}
main();Run it:
npx ts-node agent.tsTools let your agent perform actions:
import { Agent, run, tool } from '../../src';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';
const calculator = tool({
description: 'Perform calculations',
inputSchema: z.object({
expression: z.string().describe('Mathematical expression to evaluate')
}),
execute: async ({ expression }) => {
return { result: eval(expression) };
}
});
const agent = new Agent({
name: 'calculator',
model: openai('gpt-4o'),
instructions: 'You help users with calculations.',
tools: { calculator }
});
const result = await run(agent, 'What is 15 + 23?');
console.log(result.finalOutput); // "The result is 38"Sessions maintain conversation history:
import { Agent, run, MemorySession } 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 session = new MemorySession('user-123', 50); // id, maxMessages
// First message
await run(agent, 'My name is Alice', { session });
// Second message - remembers context
const result = await run(agent, 'What is my name?', { session });
console.log(result.finalOutput); // "Your name is Alice"Get real-time responses:
import { Agent, runStream } 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 stream = await runStream(agent, 'Tell me a story');
for await (const chunk of stream.textStream) {
process.stdout.write(chunk);
}
const result = await stream.completed;- Core Concepts - Learn about agents, tools, sessions, and more
- Features Guide - Explore all available features
- API Reference - Complete API documentation