Quick start guide to get your first AI agent running
Deploy your first AI agent in 5 minutes
Welcome to Fantomu! This guide will help you create and deploy your first AI agent in just 5 minutes.
# JavaScript/Node.js
npm install @fantomu/sdk
# Python
pip install fantomu-sdk
import { FantomuClient } from '@fantomu/sdk';
const client = new FantomuClient({
apiKey: 'your-api-key-here'
});
// Create an agent
const agent = await client.agents.create({
name: 'My First Agent',
description: 'A simple AI agent for testing',
capabilities: ['text_processing', 'basic_reasoning']
});
console.log('Agent created:', agent.id);
// Execute a simple task
const result = await agent.execute({
task: 'Write a short greeting message',
context: {
recipient: 'new user',
tone: 'friendly'
}
});
console.log('Result:', result.result);
Congratulations! You've successfully created and deployed your first AI agent.
Set up Fantomu SDK and CLI tools
This guide covers installing the Fantomu SDK and CLI tools for your preferred programming language.
npm install @fantomu/sdk
yarn add @fantomu/sdk
pnpm add @fantomu/sdk
pip install fantomu-sdk
pipenv install fantomu-sdk
poetry add fantomu-sdk
go get github.com/fantomu/go-sdk
composer require fantomu/php-sdk
Install the Fantomu CLI for managing agents from the command line:
# Install globally
npm install -g @fantomu/cli
# Or use npx
npx @fantomu/cli --help
Test your installation with a simple script:
// test.js
import { FantomuClient } from '@fantomu/sdk';
const client = new FantomuClient({
apiKey: process.env.FANTOMU_API_KEY
});
console.log('SDK version:', client.version);
Run it:
node test.js
Set up your API key as an environment variable:
# .env
FANTOMU_API_KEY=your-api-key-here
npm install
Get your API keys and configure access
Learn how to authenticate with the Fantomu API using API keys and configure access for your applications.
Fantomu uses API keys for authentication. Each key is associated with your account and has specific permissions.
# .env
FANTOMU_API_KEY=sk-1234567890abcdef
import { FantomuClient } from '@fantomu/sdk';
const client = new FantomuClient({
apiKey: process.env.FANTOMU_API_KEY
});
const client = new FantomuClient({
apiKey: 'sk-1234567890abcdef'
});
# Add to .gitignore
.env
*.env
Always use environment variables in production:
const apiKey = process.env.NODE_ENV === 'production'
? process.env.FANTOMU_API_KEY
: 'dev-key-for-testing';
// Test your API key
const client = new FantomuClient({
apiKey: process.env.FANTOMU_API_KEY
});
try {
const account = await client.account.get();
console.log('Authenticated as:', account.email);
} catch (error) {
console.error('Authentication failed:', error.message);
}
{
"error": "invalid_api_key",
"message": "The provided API key is invalid"
}
{
"error": "insufficient_permissions",
"message": "This API key doesn't have permission to perform this action"
}
{
"error": "rate_limited",
"message": "Too many requests. Please try again later."
}
Create and deploy your first AI agent
This comprehensive guide will walk you through creating, configuring, and deploying your first AI agent with Fantomu.
An AI agent is an autonomous system that can:
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ User Input │───▶│ AI Agent │───▶│ Task Result │
│ (Task) │ │ (Processing) │ │ (Output) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐
│ External │
│ Integrations │
└─────────────────┘
Before coding, clearly define what your agent should do:
import { FantomuClient } from '@fantomu/sdk';
const client = new FantomuClient({
apiKey: process.env.FANTOMU_API_KEY
});
// Define agent configuration
const agentConfig = {
name: 'Email Assistant',
description: 'AI agent for email management and drafting',
capabilities: [
'email_drafting',
'email_scheduling',
'email_analysis',
'contact_management'
],
settings: {
maxResponseLength: 2000,
temperature: 0.7,
model: 'gpt-4'
}
};
// Create the agent
const agent = await client.agents.create(agentConfig);
console.log('Agent created:', agent.id);
// Add custom instructions
await agent.update({
instructions: `You are a professional email assistant.
Guidelines:
- Always use professional tone
- Be concise but complete
- Include relevant details
- Suggest follow-up actions when appropriate`
});
// Set up integrations
await agent.integrations.add({
type: 'email',
provider: 'gmail',
credentials: {
clientId: process.env.GMAIL_CLIENT_ID,
clientSecret: process.env.GMAIL_CLIENT_SECRET
}
});
// Test basic functionality
const testResult = await agent.execute({
task: 'Draft a professional follow-up email',
context: {
recipient: 'client@example.com',
subject: 'Project Update - Q1 Review',
previousEmails: 2,
meetingDate: '2024-01-15'
}
});
console.log('Test result:', testResult.result);
// production.js
const client = new FantomuClient({
apiKey: process.env.FANTOMU_API_KEY,
environment: 'production'
});
// Enable monitoring
client.monitoring.enable({
logLevel: 'info',
metrics: true,
alerts: true
});
async function executeTaskSafely(agent, task, context) {
try {
const result = await agent.execute({ task, context });
return { success: true, result };
} catch (error) {
console.error('Task execution failed:', error);
// Implement fallback logic
if (error.code === 'RATE_LIMITED') {
// Retry with exponential backoff
await new Promise(resolve => setTimeout(resolve, 1000));
return executeTaskSafely(agent, task, context);
}
return {
success: false,
error: error.message,
fallback: 'Please try again later'
};
}
}
// Monitor agent performance
client.monitoring.on('task_completed', (data) => {
console.log('Task completed:', {
agentId: data.agentId,
duration: data.duration,
success: data.success
});
});
client.monitoring.on('error', (error) => {
console.error('Agent error:', error);
// Send alert to your team
});
// Optimize based on usage patterns
const analytics = await agent.getAnalytics({
period: '30d',
metrics: ['response_time', 'success_rate', 'usage_patterns']
});
// Adjust settings based on data
if (analytics.responseTime > 5000) {
await agent.update({
settings: {
...agent.settings,
temperature: 0.5, // More focused responses
maxTokens: 1000 // Shorter responses
}
});
}