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_code | text (PK) | Уникальный код (analyst, planner, executor) |
| goal | text | Цель агента (для prompt assembly) |
| allowed_tools | text[] | Список разрешённых инструментов |
| forbidden_tools | text[] | Список запрещённых инструментов |
| preferred_models | text[] | Предпочитаемые модели (phi4-mini, qwen3:8b) |
| default_temperature | numeric | Температура по умолчанию |
| response_contract | jsonb | JSON Schema ожидаемого ответа |
agent_selection_policy — Политики выбора
Правила выбора агента на основе intent, process_code, scope. Matching идёт по приоритету (DESC).
| Поле | Тип | Описание |
|---|---|---|
| match_intent | text[] | Интенты для matching (analyze, plan, search) |
| match_process_code | text[] | Коды процессов (web_search, daily_checkin) |
| match_scope | text[] | Области (chat, process, operator) |
| priority | integer | Приоритет (выше = важнее) |
Примеры данных
-- 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 agentIndexes
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)
Анализ запросов
Планирование
Выполнение
Web search
Генерация текста
Review и QA
Напоминания
Operator plane
Self-reflection
Что делать дальше
- → Agent Profiles — детальное описание каждого профиля
- → Agent Selection — алгоритм выбора
- → Runtime Policy — политики в runtime