Agent Tables

Таблицы для определения агентов, их методов, политик выбора и связей. Агент = DB entity, не Python class.

Связи и зависимости

Предыдущие шаги: Process Tables

Следующие шаги: Agent Profiles, Agent Selection

Необходимые навыки: SQL, JSON Schema, Array types

ER-диаграмма Agent Domain

┌─────────────────────────┐     ┌─────────────────────────┐
│     agent_profile       │     │    prompt_fragment      │
├─────────────────────────┤     ├─────────────────────────┤
│ agent_code (PK)         │     │ fragment_id (PK, uuid)  │
│ goal                    │     │ fragment_key            │
│ description             │     │ content                 │
│ allowed_tools (text[])  │     │ fragment_type           │
│ forbidden_tools (text[])│     │ variables               │
│ preferred_models (text[])│    │ is_active               │
│ default_temperature     │     └───────────┬─────────────┘
│ response_contract       │                 │
│ is_active               │                 │
└───────────┬─────────────┘                 │
            │                               │
            │ N:M                           │
            ▼                               │
┌─────────────────────────┐                 │
│ agent_profile_prompt_map│                 │
├─────────────────────────┤                 │
│ map_id (PK, uuid)       │                 │
│ agent_code (FK)         │─────────────────┘
│ fragment_id (FK)        │
│ weight                  │
│ ordinal                 │
│ assembly_mode           │
│ is_required             │
└─────────────────────────┘

┌─────────────────────────┐     ┌─────────────────────────┐
│ agent_selection_policy  │     │     agent_methods       │
├─────────────────────────┤     ├─────────────────────────┤
│ policy_id (PK, uuid)    │     │ method_id (PK, uuid)    │
│ agent_code (FK)         │     │ agent_code (FK)         │
│ match_intent (text[])   │     │ method_key              │
│ match_process_code[]    │     │ description             │
│ match_scope (text[])    │     │ prompt_template         │
│ match_team_id           │     │ tool_bindings           │
│ priority                │     │ input_schema            │
│ is_active               │     │ output_schema           │
└─────────────────────────┘     └─────────────────────────┘

agent_profile — Профили агентов

Основная таблица для определения агента. Каждый агент = одна запись.

ПолеТипОписание
agent_codetext (PK)Уникальный код (analyst, planner, executor)
goaltextЦель агента (для prompt assembly)
allowed_toolstext[]Список разрешённых инструментов
forbidden_toolstext[]Список запрещённых инструментов
preferred_modelstext[]Предпочитаемые модели (phi4-mini, qwen3:8b)
default_temperaturenumericТемпература по умолчанию
response_contractjsonbJSON Schema ожидаемого ответа

agent_selection_policy — Политики выбора

Правила выбора агента на основе intent, process_code, scope. Matching идёт по приоритету (DESC).

ПолеТипОписание
match_intenttext[]Интенты для matching (analyze, plan, search)
match_process_codetext[]Коды процессов (web_search, daily_checkin)
match_scopetext[]Области (chat, process, operator)
priorityintegerПриоритет (выше = важнее)

Примеры данных

-- Agent Profile
INSERT INTO clowbot.agent_profile (
  agent_code, goal, allowed_tools, preferred_models, default_temperature
) VALUES (
  'analyst',
  'Analyze user requests and extract structured requirements',
  ARRAY['web_search', 'read_document'],
  ARRAY['phi4-mini', 'qwen3:8b'],
  0.3
);

-- Selection Policy
INSERT INTO clowbot.agent_selection_policy (
  agent_code, match_intent, match_scope, priority
) VALUES (
  'analyst',
  ARRAY['analyze', 'understand', 'clarify'],
  ARRAY['chat', 'operator'],
  100
);

-- Prompt Map (связь с prompt_fragment)
INSERT INTO clowbot.agent_profile_prompt_map (
  agent_code, fragment_id, ordinal, assembly_mode
) VALUES (
  'analyst',
  'uuid-of-fragment',
  1,
  'prepend'
);

Алгоритм выбора агента

-- 1. Получить intent из сообщения
-- 2. Найти подходящие политики
SELECT asp.*, ap.goal, ap.preferred_models
FROM clowbot.agent_selection_policy asp
JOIN clowbot.agent_profile ap ON ap.agent_code = asp.agent_code
WHERE asp.is_active = true
  AND asp.match_intent @> ARRAY[$intent]  -- GIN index
  AND (asp.match_scope = '{}' OR asp.match_scope @> ARRAY[$scope])
ORDER BY asp.priority DESC
LIMIT 1;

-- Если нет matching — fallback к default agent

Indexes

idx_agent_selection_active — (is_active, priority DESC) WHERE is_active = true

idx_agent_selection_intent — GIN (match_intent) WHERE is_active = true

idx_agent_selection_process — GIN (match_process_code) WHERE is_active = true

idx_agent_prompt_map_agent — (agent_code, ordinal)

Текущие агенты (9 profiles)

analyst

Анализ запросов

planner

Планирование

executor

Выполнение

researcher

Web search

writer

Генерация текста

reviewer

Review и QA

reminder

Напоминания

operator

Operator plane

reflector

Self-reflection

Что делать дальше