create_trigger
Set up automation triggers for AI agents—webhook, database event, email, or schedule—with validation against Zihin's schema. Define configuration, sender access, and execution options in one call.
Instructions
Cria um novo trigger para um agente. Contrato autoritativo: resource zihin://schemas/trigger_config (o mesmo JSON Schema que o servidor valida; envie apenas agent_id/name/trigger_type/trigger_config — tenant_id e ids são injetados pelo servidor). Use SOMENTE os enums abaixo — não invente valores como "public" para sender_access.mode. A configuração (trigger_config) depende do tipo:
webhook: { query_extraction: { field: "chatInput" }, response_adapter: { format: "ebarn"|"slack"|"teams"|"twiml"|"raw" }, context_mapping: {}, session_strategy: { mode: "derive"|"ephemeral", fields?: [] }, sender_access?: { mode: "any"|"members"|"whitelist", identity_field?, match_column?, whitelist? }, execution?: { mode: "sync"|"async", ack_response?: { body, content_type }, callback?: { url, method, content_type, auth: { type, secret_ref }, body_template, response_transform }, message_buffer?: { enabled, window_ms, max_messages, concat_separator }, split_config?: { enabled, max_chunk_size, max_chunks, chunk_strategy: "paragraph"|"sentence"|"length", numbering, inter_chunk_delay_ms } } }
db_event: { table, events: ["INSERT","UPDATE"], conditions: {} }
email: { allowed_senders: [], subject_filter: "" }
schedule: { cron: "0 9 * * *", timezone: "America/Sao_Paulo", query_template: "mensagem fixa", enabled_days?: ["monday","friday"], session_strategy?: { mode: "new"|"persistent" }, output?: { channel: "webhook"|"silent"|"callback", webhook_url?: "https://..." (webhook), callback?: { url, method?, content_type?, auth?: { type, secret_ref }, body_template?, response_transform?: { strip_markdown, max_length } } (callback) } }
response_adapter.format determina defaults automáticos de transform: twiml → strip_markdown=true, max_length=4096. Override via execution.callback.response_transform. sender_access controla quem pode acionar o webhook: "any" (default), "members" (tenant_users), "whitelist" (lista explícita). message_buffer agrupa mensagens rápidas (popcorn) em uma janela de debounce via Redis antes de executar o agente. split_config divide respostas longas em múltiplos chunks para canais com limite de tamanho (WhatsApp, SMS).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Nome do trigger | |
| agent_id | Yes | UUID do agente | |
| api_key_id | No | UUID da API Key para execução autenticada | |
| description | No | Descrição do trigger | |
| trigger_type | Yes | Tipo de trigger | |
| trigger_config | No | Configuração do trigger. Estrutura por tipo: WEBHOOK: { query_extraction: { mode: "field"|"full_body", field?: string (default: "message") }, response_adapter: { format: "ebarn"|"slack"|"teams"|"twiml"|"raw", content_type?: string, max_length?: number }, context_mapping?: { campo: "$.path.no.body" }, session_strategy?: { mode: "derive"|"ephemeral", fields?: string[] }, sender_access?: { mode: "any"|"members"|"whitelist", identity_field?: string, match_column?: string, whitelist?: string[] }, execution?: { mode: "sync"|"async", ack_response?: { body: string|object, content_type: string }, callback?: { url: string, method: "POST"|"PUT"|"PATCH", content_type: string, auth: { type: "basic"|"bearer"|"api_key"|"none", secret_ref: string }, headers?: object, body_template: object|string, response_transform?: { strip_markdown: boolean, max_length: number } }, message_buffer?: { enabled: boolean, window_ms?: number (100-60000, default 5000), max_messages?: number (1-100, default 10), concat_separator?: string (default "\n") }, split_config?: { enabled: boolean, max_chunk_size?: number (100-50000, default 1500), max_chunks?: number (1-50, default 10), chunk_strategy?: "paragraph"|"sentence"|"length" (default "paragraph"), numbering?: boolean (default true), inter_chunk_delay_ms?: number (0-10000, default 500) } } } SCHEDULE: { cron: string (ex: "0 9 * * *"), timezone?: string (default: "America/Sao_Paulo"), query_template: string (tarefa para o agente), enabled_days?: string[] (ex: ["monday","friday"]), session_strategy?: { mode: "new"|"persistent" }, output?: { channel: "webhook"|"silent"|"callback" (default: "silent"), webhook_url?: string (se channel=webhook), callback?: { url, method?, content_type?, auth?: { type, secret_ref }, body_template?, response_transform?: { strip_markdown?, max_length? } } (se channel=callback) }, memory_config?: { enabled: boolean, user_key_field?: string (campo do body_template, ex: "To"), strip_prefix?: string (ex: "whatsapp:"), ttl_hours?: number (default: 48), user_key?: string (fixo, alternativa a user_key_field) } } DB_EVENT: { table: string, events: ["INSERT"|"UPDATE"|"DELETE"], conditions?: object } EMAIL: { allowed_senders: string[], subject_filter?: string } |