Agents

Agents API

The Agents API allows you to create, manage, and deploy AI-powered customer support agents. Agents can handle customer interactions across multiple channels and be customized with specific instructions, knowledge bases, and tools.

Base URL

https://api.aloochat.ai/api/public

Authentication

All requests require an API key in the x-api-key header:

x-api-key: your_api_key_here

Endpoints Overview

MethodEndpointDescription
GET/agentsList all agents
POST/agentsCreate a new agent
GET/agents/{id}Get agent by ID
PUT/agents/{id}Update an agent
DELETE/agents/{id}Delete an agent
POST/agents/draftSave agent draft
GET/agents/draftGet agent draft
DELETE/agents/draftClear agent draft

Agent Properties

PropertyTypeDescription
idstringUnique agent identifier (UUID)
titlestringAgent name/title
collection_idstringAssociated knowledge base collection ID
use_business_profilebooleanWhether to use company business profile
task_descriptionstringDescription of the agent’s primary task
instructionsarrayList of instructions for the agent
custom_blocksarrayCustom prompt blocks
welcome_messagestringMessage displayed when conversation starts
avatarstringURL to agent avatar image
genderstringAgent gender for voice synthesis
primary_languagestringPrimary language (default: “english”)
stylestringCommunication style
tonestringCommunication tone
use_self_querybooleanEnable self-query for retrieval
use_rerankingbooleanEnable result reranking
retrieval_top_kintegerNumber of documents to retrieve
enable_vectorsearchbooleanEnable vector search
enable_elasticsearchbooleanEnable Elasticsearch
enable_mongosearchbooleanEnable MongoDB search
categoriesarrayAssociated data categories
toolsarrayAssociated agent tools

Create Agent

Create a new AI agent for your company.

const response = await fetch('https://api.aloochat.ai/api/public/agents', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': 'your_api_key_here'
  },
  body: JSON.stringify({
    title: "Customer Support Agent",
    task_description: "Provide helpful customer support and answer questions about our products",
    instructions: [
      "Be polite and professional",
      "Always ask clarifying questions when needed",
      "Escalate complex issues to human agents"
    ],
    use_business_profile: true,
    welcome_message: "Hello! How can I help you today?",
    primary_language: "english",
    style: "professional",
    tone: "friendly",
    categories: ["support", "products"],
    custom_blocks: [
      {
        type: "text",
        content: "Always end responses with 'Is there anything else I can help you with?'"
      }
    ]
  })
});
 
const agent = await response.json();
console.log('Agent created:', agent);

Response

{
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "title": "Customer Support Agent",
  "collection_id": null,
  "use_business_profile": true,
  "category_names": ["support", "products"],
  "task_description": "Provide helpful customer support and answer questions about our products",
  "instructions": [
    "Be polite and professional",
    "Always ask clarifying questions when needed",
    "Escalate complex issues to human agents"
  ],
  "custom_blocks": [
    {
      "type": "text",
      "content": "Always end responses with 'Is there anything else I can help you with?'"
    }
  ],
  "welcome_message": "Hello! How can I help you today?",
  "primary_language": "english",
  "style": "professional",
  "tone": "friendly",
  "use_self_query": true,
  "use_reranking": false,
  "retrieval_top_k": 6,
  "enable_vectorsearch": true,
  "enable_elasticsearch": false,
  "enable_mongosearch": false,
  "allow_partial_categories": true,
  "tools": [],
  "created_at": "2024-01-15T10:30:00Z",
  "updated_at": "2024-01-15T10:30:00Z"
}

List Agents

Retrieve a paginated list of all agents for your company.

const response = await fetch('https://api.aloochat.ai/api/public/agents?limit=20&skip=0', {
  method: 'GET',
  headers: {
    'x-api-key': 'your_api_key_here'
  }
});
 
const agents = await response.json();
console.log('Agents:', agents);

Query Parameters

ParameterTypeDefaultDescription
skipinteger0Number of agents to skip (pagination)
limitinteger100Maximum number of agents to return

Get Agent

Retrieve a specific agent by its ID.

const agentId = "123e4567-e89b-12d3-a456-426614174000";
const response = await fetch(`https://api.aloochat.ai/api/public/agents/${agentId}`, {
  method: 'GET',
  headers: {
    'x-api-key': 'your_api_key_here'
  }
});
 
const agent = await response.json();
console.log('Agent:', agent);

Update Agent

Update an existing agent’s properties.

const agentId = "123e4567-e89b-12d3-a456-426614174000";
const response = await fetch(`https://api.aloochat.ai/api/public/agents/${agentId}`, {
  method: 'PUT',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': 'your_api_key_here'
  },
  body: JSON.stringify({
    title: "Updated Customer Support Agent",
    welcome_message: "Hi there! I'm here to help with any questions you have.",
    tone: "casual",
    instructions: [
      "Be friendly and approachable",
      "Use simple language",
      "Provide step-by-step guidance"
    ]
  })
});
 
const updatedAgent = await response.json();
console.log('Updated agent:', updatedAgent);

Delete Agent

Delete an existing agent.

const agentId = "123e4567-e89b-12d3-a456-426614174000";
const response = await fetch(`https://api.aloochat.ai/api/public/agents/${agentId}`, {
  method: 'DELETE',
  headers: {
    'x-api-key': 'your_api_key_here'
  }
});
 
const result = await response.json();
console.log('Delete result:', result);

Response

{
  "message": "Agent deleted successfully"
}

Draft Management

The API provides draft functionality to save agent configurations before final creation.

Save Draft

const response = await fetch('https://api.aloochat.ai/api/public/agents/draft', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': 'your_api_key_here'
  },
  body: JSON.stringify({
    title: "Draft Agent",
    task_description: "Work in progress agent",
    instructions: ["Be helpful"],
    primary_language: "english"
  })
});
 
const result = await response.json();
console.log('Draft saved:', result);

Get Draft

const response = await fetch('https://api.aloochat.ai/api/public/agents/draft', {
  method: 'GET',
  headers: {
    'x-api-key': 'your_api_key_here'
  }
});
 
const draft = await response.json();
console.log('Draft:', draft);

Error Responses

The API returns standard HTTP status codes and detailed error messages:

400 Bad Request

{
  "detail": "Cannot enable business profile when company business profile is not set"
}

401 Unauthorized

{
  "detail": "Invalid or missing API key"
}

403 Forbidden

{
  "detail": "Not enough permissions"
}

404 Not Found

{
  "detail": "Agent not found"
}

422 Validation Error

{
  "detail": [
    {
      "loc": ["body", "title"],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]
}

429 Too Many Requests

{
  "detail": "Rate limit exceeded. Please try again later."
}

Rate Limiting

API requests are limited to 100 requests per minute per API key. When the limit is exceeded, you’ll receive a 429 Too Many Requests response.

Best Practices

Agent Configuration

  • Clear Instructions: Provide specific, actionable instructions for your agent
  • Appropriate Tone: Choose a tone that matches your brand and use case
  • Knowledge Base: Associate relevant collections for better context
  • Categories: Use categories to organize and filter agent responses

Performance Optimization

  • Retrieval Settings: Adjust retrieval_top_k based on your knowledge base size
  • Search Methods: Enable appropriate search methods (vector, Elasticsearch, MongoDB)
  • Reranking: Enable reranking for improved response relevance

Security

  • API Key Protection: Never expose API keys in client-side code
  • HTTPS Only: Always use HTTPS for API requests
  • Company Isolation: Agents are automatically isolated by company

Error Handling

  • Retry Logic: Implement exponential backoff for rate-limited requests
  • Validation: Validate UUIDs and required fields before making requests
  • Graceful Degradation: Handle API errors gracefully in your application