Build a simple AI agent from scratch
npm install @boostgpt/core-sdk
import { BoostGPT } from '@boostgpt/core-sdk';
// Initialize client
const client = new BoostGPT({
apiKey: process.env.BOOSTGPT_API_KEY
});
async function main() {
// 1. Create a bot
console.log('Creating bot...');
const botResult = await client.createBot({
name: 'Customer Support Assistant',
model: 'gpt-4o',
instruction: 'You are a helpful customer support agent. Be friendly and concise.'
});
if (botResult.err) {
console.error('Error creating bot:', botResult.err);
return;
}
const botId = botResult.response.id;
console.log('Bot created:', botId);
// 2. Add training data
console.log('\nAdding training data...');
const trainingResult = await client.startTraining({
bot_id: botId,
type: 'text',
source: `
Q: What are your business hours?
A: We're open Monday-Friday, 9am-5pm EST.
Q: How do I reset my password?
A: Click "Forgot Password" on the login page and follow the instructions.
Q: What's your return policy?
A: We accept returns within 30 days of purchase.
`
});
if (trainingResult.err) {
console.error('Error adding training:', trainingResult.err);
return;
}
console.log('Training queued:', trainingResult.response.id);
// Wait for training to process
console.log('Waiting for training to complete...');
await new Promise(resolve => setTimeout(resolve, 3000));
// 3. Chat with bot
console.log('\nTesting bot...');
const chatResult = await client.chat({
bot_id: botId,
message: 'What are your business hours?',
chat_id: 'user-123'
});
if (chatResult.err) {
console.error('Error chatting:', chatResult.err);
return;
}
console.log('Bot response:', chatResult.response);
}
main();
import { BoostGPT } from '@boostgpt/core-sdk';
const client = new BoostGPT({
apiKey: process.env.BOOSTGPT_API_KEY
});
const botResult = await client.createBot({
name: 'Customer Support Assistant',
model: 'gpt-4o',
instruction: 'You are a helpful customer support agent.'
});
const botId = botResult.response.id;
await client.startTraining({
bot_id: botId,
type: 'text',
source: 'Your training content here...'
});
const chatResult = await client.chat({
bot_id: botId,
message: 'User question',
chat_id: 'user-123'
});
console.log(chatResult.response);
# Set API key
export BOOSTGPT_API_KEY=your_api_key
# Run
node basic-bot.js
Creating bot...
Bot created: bot_abc123
Adding training data...
Training queued: source_xyz789
Waiting for training to complete...
Testing bot...
Bot response: We're open Monday-Friday, 9am-5pm EST.
const chatResult = await client.chat({
bot_id: botId,
message: 'Tell me about your services',
stream: true
});
// Handle streaming
for await (const chunk of chatResult.response) {
process.stdout.write(chunk);
}
// Add FAQ
await client.startTraining({
bot_id: botId,
type: 'text',
source: 'FAQ content...'
});
// Add from website
await client.startTraining({
bot_id: botId,
type: 'website',
source: 'https://example.com'
});
// Add files
await client.startTraining({
bot_id: botId,
type: 'file',
source: ['manual.pdf', 'guide.docx']
});
const chatResult = await client.chat({
bot_id: botId,
message: 'Question',
model: 'gpt-4o-mini', // Override model
max_reply_tokens: 500, // Limit response length
reasoning_mode: 'stepwise' // Use step-by-step reasoning
});
const result = await client.createBot({
name: 'My Bot',
model: 'gpt-4o'
});
if (result.err) {
console.error('Error:', result.err);
// Handle error
return;
}
// Use result.response
const botId = result.response.id;
Was this page helpful?