Examples

Explore real-world examples of AI agents built with Reminix. These examples demonstrate different use cases and patterns you can implement.

Chatbot Agent

A simple conversational agent that responds to user messages:

chatbot.ts:

import { AgentHandler } from '@reminix/types'

export const handler: AgentHandler = async (input) => {
  const { message, context } = input
  
  // Simple response logic
  const responses = [
    "That's interesting! Tell me more.",
    "I understand. How can I help you with that?",
    "Thanks for sharing that with me.",
    "I see what you mean. What would you like to do next?"
  ]
  
  const randomResponse = responses[Math.floor(Math.random() * responses.length)]
  
  return {
    response: randomResponse,
    metadata: {
      agent_type: 'chatbot',
      response_type: 'conversational'
    }
  }
}
typescript

Data Processing Agent

An agent that processes and analyzes data:

data-processor.ts:

import { AgentHandler } from '@reminix/types'

interface DataInput {
  data: number[]
  operation: 'sum' | 'average' | 'max' | 'min'
}

export const handler: AgentHandler = async (input) => {
  const { message, context } = input
  
  try {
    const dataInput: DataInput = JSON.parse(message)
    const { data, operation } = dataInput
    
    let result: number
    
    switch (operation) {
      case 'sum':
        result = data.reduce((a, b) => a + b, 0)
        break
      case 'average':
        result = data.reduce((a, b) => a + b, 0) / data.length
        break
      case 'max':
        result = Math.max(...data)
        break
      case 'min':
        result = Math.min(...data)
        break
      default:
        throw new Error(`Unknown operation: ${operation}`)
    }
    
    return {
      response: JSON.stringify({
        operation,
        result,
        data_length: data.length
      }),
      metadata: {
        agent_type: 'data_processor',
        processing_time: Date.now() - context.timestamp
      }
    }
  } catch (error) {
    return {
      response: `Error processing data: ${error.message}`,
      metadata: {
        agent_type: 'data_processor',
        error: true
      }
    }
  }
}
typescript

Weather Agent

An agent that fetches weather information:

weather.ts:

import { AgentHandler } from '@reminix/types'

interface WeatherData {
  location: string
  temperature: number
  condition: string
  humidity: number
}

export const handler: AgentHandler = async (input) => {
  const { message, context } = input
  
  // Extract location from message
  const location = message.trim()
  
  if (!location) {
    return {
      response: "Please provide a location to get weather information.",
      metadata: {
        agent_type: 'weather',
        error: 'no_location'
      }
    }
  }
  
  try {
    // In a real implementation, you would call a weather API
    // For this example, we'll simulate the response
    const weatherData: WeatherData = {
      location,
      temperature: Math.round(Math.random() * 30 + 10), // 10-40°C
      condition: ['sunny', 'cloudy', 'rainy', 'snowy'][Math.floor(Math.random() * 4)],
      humidity: Math.round(Math.random() * 100)
    }
    
    const response = `Weather in ${weatherData.location}:
🌡️ Temperature: ${weatherData.temperature}°C
☁️ Condition: ${weatherData.condition}
💧 Humidity: ${weatherData.humidity}%`
    
    return {
      response,
      metadata: {
        agent_type: 'weather',
        location: weatherData.location,
        timestamp: new Date().toISOString()
      }
    }
  } catch (error) {
    return {
      response: `Sorry, I couldn't fetch weather data for ${location}.`,
      metadata: {
        agent_type: 'weather',
        error: error.message
      }
    }
  }
}
typescript

File Processing Agent

An agent that processes uploaded files:

file-processor.ts:

import { AgentHandler } from '@reminix/types'

export const handler: AgentHandler = async (input) => {
  const { message, context } = input
  
  try {
    const fileData = JSON.parse(message)
    const { filename, content, type } = fileData
    
    let processedContent: string
    let metadata: any = {
      filename,
      type,
      size: content.length
    }
    
    switch (type) {
      case 'text/plain':
        processedContent = content.toUpperCase()
        metadata.lines = content.split('\n').length
        metadata.words = content.split(/\s+/).length
        break
        
      case 'application/json':
        const jsonData = JSON.parse(content)
        processedContent = JSON.stringify(jsonData, null, 2)
        metadata.keys = Object.keys(jsonData).length
        break
        
      case 'text/csv':
        const lines = content.split('\n')
        const headers = lines[0].split(',')
        processedContent = `Headers: ${headers.join(', ')}\nRows: ${lines.length - 1}`
        metadata.columns = headers.length
        metadata.rows = lines.length - 1
        break
        
      default:
        processedContent = `File type ${type} is not supported yet.`
        metadata.supported = false
    }
    
    return {
      response: processedContent,
      metadata: {
        agent_type: 'file_processor',
        ...metadata,
        processed_at: new Date().toISOString()
      }
    }
  } catch (error) {
    return {
      response: `Error processing file: ${error.message}`,
      metadata: {
        agent_type: 'file_processor',
        error: true
      }
    }
  }
}
typescript

E-commerce Agent

An agent that handles product recommendations:

ecommerce.ts:

import { AgentHandler } from '@reminix/types'

interface Product {
  id: string
  name: string
  price: number
  category: string
  rating: number
}

interface UserPreferences {
  categories: string[]
  maxPrice: number
  minRating: number
}

export const handler: AgentHandler = async (input) => {
  const { message, context } = input
  
  try {
    const request = JSON.parse(message)
    const { action, data } = request
    
    switch (action) {
      case 'recommend':
        return handleRecommendations(data)
      case 'search':
        return handleSearch(data)
      case 'compare':
        return handleComparison(data)
      default:
        return {
          response: "Unknown action. Supported actions: recommend, search, compare",
          metadata: { agent_type: 'ecommerce', error: 'unknown_action' }
        }
    }
  } catch (error) {
    return {
      response: `Error processing request: ${error.message}`,
      metadata: { agent_type: 'ecommerce', error: true }
    }
  }
}

function handleRecommendations(preferences: UserPreferences) {
  // Simulate product database
  const products: Product[] = [
    { id: '1', name: 'Wireless Headphones', price: 99, category: 'electronics', rating: 4.5 },
    { id: '2', name: 'Coffee Maker', price: 49, category: 'home', rating: 4.2 },
    { id: '3', name: 'Running Shoes', price: 120, category: 'sports', rating: 4.8 }
  ]
  
  const recommendations = products.filter(product => 
    preferences.categories.includes(product.category) &&
    product.price <= preferences.maxPrice &&
    product.rating >= preferences.minRating
  )
  
  const response = recommendations.length > 0 
    ? `Here are ${recommendations.length} recommendations:\n` +
      recommendations.map(p => `• ${p.name} - $${p.price} (${p.rating}⭐)`).join('\n')
    : "No products match your criteria. Try adjusting your preferences."
  
  return {
    response,
    metadata: {
      agent_type: 'ecommerce',
      action: 'recommend',
      recommendations_count: recommendations.length
    }
  }
}

function handleSearch(query: string) {
  return {
    response: `Searching for "${query}"... Found 5 products matching your query.`,
    metadata: {
      agent_type: 'ecommerce',
      action: 'search',
      query
    }
  }
}

function handleComparison(products: string[]) {
  return {
    response: `Comparing ${products.length} products... Here's a detailed comparison.`,
    metadata: {
      agent_type: 'ecommerce',
      action: 'compare',
      products_count: products.length
    }
  }
}
typescript

Deployment Examples

Using the CLI

Deploy with CLI:

$ [object Object],[object Object],
$ reminix deploy
$ ,[object Object],[object Object],
$ reminix deploy --env production
$ ,[object Object],[object Object],
$ reminix deploy --config custom-config.json
$ ,[object Object],[object Object],
$ curl -X POST \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "my-agent"}' \
  https://api.reminix.com/v1/agents
shell

Using the API

Deploy via API:

import { ReminixClient } from '@reminix/sdk'

const client = new ReminixClient({
  apiKey: process.env.REMINIX_API_KEY
})

// Create and deploy agent
const agent = await client.agents.create({
  name: 'my-agent',
  handler: fs.readFileSync('./handler.ts', 'utf8')
})

console.log(`Agent deployed: ${agent.id}`)
javascript

Best Practices

💡 Info
These examples follow Reminix best practices for agent development.

  1. Error Handling: Always wrap your logic in try-catch blocks
  2. Input Validation: Validate and sanitize input data
  3. Metadata: Include useful metadata in responses
  4. Performance: Keep processing time reasonable
  5. Security: Never expose sensitive information in responses

Next Steps