HIVE

API Reference

Agents API

Agents API

The Agents API allows you to create, read, update, and delete AI agents programmatically. Agents are the AI entities that participate in swarms and respond to messages.

Database Schema

-- agents table
CREATE TABLE agents (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  user_id UUID REFERENCES auth.users(id) NOT NULL,
  name TEXT NOT NULL,
  role TEXT,
  avatar TEXT,
  framework TEXT NOT NULL DEFAULT 'openai',
  model TEXT,
  system_prompt TEXT,
  settings JSONB DEFAULT '{}',
  status TEXT DEFAULT 'idle',
  created_at TIMESTAMPTZ DEFAULT now(),
  updated_at TIMESTAMPTZ DEFAULT now()
);

-- RLS Policies
ALTER TABLE agents ENABLE ROW LEVEL SECURITY;

CREATE POLICY "Users can view own agents"
  ON agents FOR SELECT TO authenticated
  USING (auth.uid() = user_id);

CREATE POLICY "Users can create own agents"
  ON agents FOR INSERT TO authenticated
  WITH CHECK (auth.uid() = user_id);

CREATE POLICY "Users can update own agents"
  ON agents FOR UPDATE TO authenticated
  USING (auth.uid() = user_id)
  WITH CHECK (auth.uid() = user_id);

CREATE POLICY "Users can delete own agents"
  ON agents FOR DELETE TO authenticated
  USING (auth.uid() = user_id);

Endpoints Overview

OperationMethodEndpointDescription
ListGET/rest/v1/agentsGet all user's agents
GetGET/rest/v1/agents?id=eq.{id}Get single agent
CreatePOST/rest/v1/agentsCreate new agent
UpdatePATCH/rest/v1/agents?id=eq.{id}Update agent
DeleteDELETE/rest/v1/agents?id=eq.{id}Delete agent

List Agents

Retrieve all agents owned by the authenticated user.

Request

Using Supabase Client:

const { data: agents, error } = await supabase
  .from('agents')
  .select('*')
  .order('created_at', { ascending: false });

Using REST API:

curl -X GET \
  'https://your-project.supabase.co/rest/v1/agents?order=created_at.desc' \
  -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
  -H 'apikey: YOUR_ANON_KEY'

Response

{
  "data": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440001",
      "user_id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "Research Assistant",
      "role": "Researcher",
      "avatar": "https://api.dicebear.com/7.x/bottts/svg?seed=research",
      "framework": "openai",
      "model": "gpt-4o",
      "system_prompt": "You are a helpful research assistant specializing in data analysis and literature review.",
      "settings": {
        "temperature": 0.7,
        "max_tokens": 4096,
        "presence_penalty": 0,
        "frequency_penalty": 0
      },
      "status": "idle",
      "created_at": "2024-01-15T10:00:00.000Z",
      "updated_at": "2024-01-15T10:00:00.000Z"
    },
    {
      "id": "550e8400-e29b-41d4-a716-446655440002",
      "user_id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "Code Reviewer",
      "role": "Developer",
      "avatar": "https://api.dicebear.com/7.x/bottts/svg?seed=coder",
      "framework": "anthropic",
      "model": "claude-sonnet-4-20250514",
      "system_prompt": "You are an expert code reviewer...",
      "settings": {
        "temperature": 0.3,
        "max_tokens": 8192
      },
      "status": "idle",
      "created_at": "2024-01-14T15:30:00.000Z",
      "updated_at": "2024-01-15T09:00:00.000Z"
    }
  ],
  "error": null
}

Query Parameters

ParameterTypeDescription
selectstringFields to return (default: *)
orderstringSort order (e.g., created_at.desc)
limitnumberMax results to return
offsetnumberNumber of results to skip

Filter Examples

// Filter by framework
const { data } = await supabase
  .from('agents')
  .select('*')
  .eq('framework', 'openai');

// Filter by status
const { data } = await supabase
  .from('agents')
  .select('*')
  .eq('status', 'active');

// Search by name
const { data } = await supabase
  .from('agents')
  .select('*')
  .ilike('name', '%assistant%');

// Pagination
const { data } = await supabase
  .from('agents')
  .select('*')
  .range(0, 9); // First 10 results

Get Agent

Retrieve a single agent by ID.

Request

Using Supabase Client:

const { data: agent, error } = await supabase
  .from('agents')
  .select('*')
  .eq('id', '550e8400-e29b-41d4-a716-446655440001')
  .maybeSingle();

Using REST API:

curl -X GET \
  'https://your-project.supabase.co/rest/v1/agents?id=eq.550e8400-e29b-41d4-a716-446655440001' \
  -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
  -H 'apikey: YOUR_ANON_KEY' \
  -H 'Accept: application/vnd.pgrst.object+json'

Response

{
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440001",
    "user_id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "Research Assistant",
    "role": "Researcher",
    "avatar": "https://api.dicebear.com/7.x/bottts/svg?seed=research",
    "framework": "openai",
    "model": "gpt-4o",
    "system_prompt": "You are a helpful research assistant...",
    "settings": {
      "temperature": 0.7,
      "max_tokens": 4096
    },
    "status": "idle",
    "created_at": "2024-01-15T10:00:00.000Z",
    "updated_at": "2024-01-15T10:00:00.000Z"
  },
  "error": null
}
// Get agent with assigned tools
const { data: agent, error } = await supabase
  .from('agents')
  .select(`
    *,
    agent_tools (
      tool_id,
      enabled,
      configuration,
      tool:tools (
        id,
        name,
        description,
        category
      )
    )
  `)
  .eq('id', agentId)
  .maybeSingle();

Create Agent

Create a new AI agent.

Request

Using Supabase Client:

const { data: agent, error } = await supabase
  .from('agents')
  .insert({
    name: 'Data Analyst',
    role: 'Analyst',
    framework: 'openai',
    model: 'gpt-4o',
    system_prompt: `You are a data analyst expert. You help users:
- Analyze datasets and identify patterns
- Create visualizations and reports
- Provide statistical insights
- Recommend data-driven decisions

Always explain your methodology and cite sources.`,
    settings: {
      temperature: 0.5,
      max_tokens: 4096,
      presence_penalty: 0.1,
      frequency_penalty: 0.1
    }
  })
  .select()
  .single();

Using REST API:

curl -X POST \
  'https://your-project.supabase.co/rest/v1/agents' \
  -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
  -H 'apikey: YOUR_ANON_KEY' \
  -H 'Content-Type: application/json' \
  -H 'Prefer: return=representation' \
  -d '{
    "name": "Data Analyst",
    "role": "Analyst",
    "framework": "openai",
    "model": "gpt-4o",
    "system_prompt": "You are a data analyst expert...",
    "settings": {
      "temperature": 0.5,
      "max_tokens": 4096
    }
  }'

Request Body

FieldTypeRequiredDescription
namestringYesAgent display name (1-100 chars)
rolestringNoAgent role/title
avatarstringNoAvatar URL
frameworkstringYesAI provider: openai, anthropic, google
modelstringNoModel ID (defaults to provider default)
system_promptstringNoSystem instructions for the agent
settingsobjectNoModel configuration settings

Settings Object

FieldTypeDefaultDescription
temperaturenumber0.7Creativity (0-2)
max_tokensnumber4096Max response length
presence_penaltynumber0Topic diversity (-2 to 2)
frequency_penaltynumber0Repetition penalty (-2 to 2)
top_pnumber1Nucleus sampling
stopstring[]nullStop sequences

Response

{
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440003",
    "user_id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "Data Analyst",
    "role": "Analyst",
    "avatar": null,
    "framework": "openai",
    "model": "gpt-4o",
    "system_prompt": "You are a data analyst expert...",
    "settings": {
      "temperature": 0.5,
      "max_tokens": 4096,
      "presence_penalty": 0.1,
      "frequency_penalty": 0.1
    },
    "status": "idle",
    "created_at": "2024-01-15T12:00:00.000Z",
    "updated_at": "2024-01-15T12:00:00.000Z"
  },
  "error": null
}

Validation Errors

{
  "data": null,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Invalid request body",
    "details": {
      "name": "Name is required",
      "framework": "Framework must be one of: openai, anthropic, google"
    }
  }
}

Update Agent

Update an existing agent's properties.

Request

Using Supabase Client:

const { data: agent, error } = await supabase
  .from('agents')
  .update({
    name: 'Senior Data Analyst',
    system_prompt: 'Updated instructions...',
    settings: {
      temperature: 0.6,
      max_tokens: 8192
    }
  })
  .eq('id', '550e8400-e29b-41d4-a716-446655440003')
  .select()
  .single();

Using REST API:

curl -X PATCH \
  'https://your-project.supabase.co/rest/v1/agents?id=eq.550e8400-e29b-41d4-a716-446655440003' \
  -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
  -H 'apikey: YOUR_ANON_KEY' \
  -H 'Content-Type: application/json' \
  -H 'Prefer: return=representation' \
  -d '{
    "name": "Senior Data Analyst",
    "settings": {"temperature": 0.6}
  }'

Partial Updates

Only include fields you want to change:

// Update only the model
const { error } = await supabase
  .from('agents')
  .update({ model: 'gpt-4-turbo' })
  .eq('id', agentId);

// Update only settings (merges with existing)
const { error } = await supabase
  .from('agents')
  .update({
    settings: { ...existingSettings, temperature: 0.8 }
  })
  .eq('id', agentId);

Delete Agent

Permanently delete an agent.

Request

Using Supabase Client:

const { error } = await supabase
  .from('agents')
  .delete()
  .eq('id', '550e8400-e29b-41d4-a716-446655440003');

Using REST API:

curl -X DELETE \
  'https://your-project.supabase.co/rest/v1/agents?id=eq.550e8400-e29b-41d4-a716-446655440003' \
  -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
  -H 'apikey: YOUR_ANON_KEY'

Response

Success returns empty response with 204 status.

Cascade Behavior

Deleting an agent:

  • Removes agent from all swarms
  • Deletes agent tool assignments
  • Preserves messages (sender marked as deleted)

Agent Tools

Manage tool assignments for agents.

List Agent Tools

const { data: tools, error } = await supabase
  .from('agent_tools')
  .select(`
    id,
    agent_id,
    tool_id,
    enabled,
    configuration,
    created_at,
    tool:tools (
      id,
      name,
      description,
      category,
      icon,
      input_schema
    )
  `)
  .eq('agent_id', agentId);

Assign Tool to Agent

const { data, error } = await supabase
  .from('agent_tools')
  .insert({
    agent_id: agentId,
    tool_id: toolId,
    enabled: true,
    configuration: {
      api_key_ref: 'user_weather_api_key',
      default_units: 'metric'
    }
  })
  .select()
  .single();

Update Tool Configuration

const { error } = await supabase
  .from('agent_tools')
  .update({
    enabled: false,
    configuration: { ...newConfig }
  })
  .eq('agent_id', agentId)
  .eq('tool_id', toolId);

Remove Tool from Agent

const { error } = await supabase
  .from('agent_tools')
  .delete()
  .eq('agent_id', agentId)
  .eq('tool_id', toolId);

Agent Status

Track agent activity status.

Status Values

StatusDescription
idleAgent not currently active
thinkingAgent processing a request
respondingAgent generating response
errorAgent encountered an error

Update Status

const { error } = await supabase
  .from('agents')
  .update({ status: 'thinking' })
  .eq('id', agentId);

Subscribe to Status Changes

const channel = supabase
  .channel('agent-status')
  .on(
    'postgres_changes',
    {
      event: 'UPDATE',
      schema: 'public',
      table: 'agents',
      filter: `id=eq.${agentId}`
    },
    (payload) => {
      console.log('Agent status:', payload.new.status);
    }
  )
  .subscribe();

Error Codes

CodeStatusDescription
AGENT_NOT_FOUND404Agent does not exist
AGENT_LIMIT_REACHED403Max agents limit reached
INVALID_FRAMEWORK400Unknown AI provider
INVALID_MODEL400Model not available for framework
PERMISSION_DENIED403Cannot access this agent
  • [Swarms API](/docs/api/swarms-api): Assign agents to swarms
  • [Messages API](/docs/api/messages-api): Agent responses
  • [Tools API](/docs/api/tools-api): Tool management

Cookie Preferences

We use cookies to enhance your experience, analyze site traffic, and for marketing purposes. By clicking "Accept All", you consent to our use of cookies. Read our Privacy Policy for more information.