fix: sync agent DB prompts with code defaults + update model to qwen3.5:9b-fast

This commit is contained in:
Celes Renata
2026-04-17 17:12:09 +00:00
parent aa67523acd
commit 84b3c06b2f
2 changed files with 33 additions and 7 deletions
+11 -7
View File
@@ -26,7 +26,11 @@ CREATE TABLE IF NOT EXISTS ai_agents (
CREATE INDEX IF NOT EXISTS idx_ai_agents_slug ON ai_agents(slug); CREATE INDEX IF NOT EXISTS idx_ai_agents_slug ON ai_agents(slug);
CREATE INDEX IF NOT EXISTS idx_ai_agents_active ON ai_agents(active); CREATE INDEX IF NOT EXISTS idx_ai_agents_active ON ai_agents(active);
-- Seed the three built-in agents (only if they don't already exist) -- Seed the three built-in agents (only if they don't already exist).
-- These prompts MUST match the code defaults in:
-- services/extractor/prompts.py (SYSTEM_PROMPT)
-- services/extractor/event_classifier.py (_SYSTEM_PROMPT)
-- services/recommendation/thesis_llm.py (THESIS_SYSTEM_PROMPT)
INSERT INTO ai_agents (name, slug, purpose, model_provider, model_name, system_prompt, prompt_version, schema_version, source) INSERT INTO ai_agents (name, slug, purpose, model_provider, model_name, system_prompt, prompt_version, schema_version, source)
SELECT * FROM (VALUES SELECT * FROM (VALUES
( (
@@ -34,8 +38,8 @@ SELECT * FROM (VALUES
'document-extractor', 'document-extractor',
'Extracts structured intelligence (sentiment, catalysts, impact scores, key facts, risks) from company news, SEC filings, earnings transcripts, and press releases.', 'Extracts structured intelligence (sentiment, catalysts, impact scores, key facts, risks) from company news, SEC filings, earnings transcripts, and press releases.',
'ollama', 'ollama',
'qwen3.5:9b', 'qwen3.5:9b-fast',
'You are a financial document analyst. Extract structured data as JSON. Return ONLY a single JSON object. No markdown fences, no explanation, no text before or after the JSON. Every field in the schema is required. Use "other" for catalyst_type if unsure. Keep evidence_spans short (under 20 words each). Keep key_facts to 3-5 items max.', E'You are a financial document analyst. Extract structured data as JSON. Return ONLY a single JSON object. No markdown fences, no explanation, no text before or after the JSON. Every field in the schema is required. Use "other" for catalyst_type if unsure. Keep evidence_spans short (under 20 words each). Keep key_facts to 3-5 items max.',
'document-intel-v2', 'document-intel-v2',
'2.0.0', '2.0.0',
'system' 'system'
@@ -45,8 +49,8 @@ SELECT * FROM (VALUES
'event-classifier', 'event-classifier',
'Classifies global/geopolitical news into structured macro events with impact type, severity, affected regions/sectors/commodities, and estimated duration.', 'Classifies global/geopolitical news into structured macro events with impact type, severity, affected regions/sectors/commodities, and estimated duration.',
'ollama', 'ollama',
'qwen3.5:9b', 'qwen3.5:9b-fast',
'Classify this global news article as a macro event. Fill every field. RULES: - Only extract facts EXPLICITLY stated in the article - Do NOT infer geopolitical implications not stated - Distinguish between announced policy and rumored policy - If severity is unclear, default to "low" - If the article is about a SINGLE COMPANY (not a sector or market), set severity to "low" and confidence below 0.3 - Only tag event_types DIRECTLY described, do NOT infer secondary effects - severity "critical" is reserved for events affecting multiple countries or entire global markets - confidence: 0.0-1.0 your confidence in this classification', E'You classify MACRO-LEVEL global news into structured event JSON. Return ONLY a single JSON object. No markdown, no explanation. Every field is required. Keep key_facts to 3-5 items. Keep summary under 3 sentences.\n\nCRITICAL: Only classify articles about MACRO events that affect entire markets, sectors, or economies. Examples: trade wars, interest rate changes, commodity supply disruptions, regulatory changes, geopolitical conflicts, natural disasters.\n\nDO NOT classify as macro events: individual company earnings, lawsuits against a single company, single-company management changes, individual stock analysis, company-specific debt or bankruptcy, product launches by one company. For these, set severity to "low", confidence below 0.3, and leave affected_regions, affected_sectors, and affected_commodities as empty arrays.',
'event-classification-v1', 'event-classification-v1',
'1.0.0', '1.0.0',
'system' 'system'
@@ -56,8 +60,8 @@ SELECT * FROM (VALUES
'thesis-rewriter', 'thesis-rewriter',
'Rewrites deterministic trade thesis summaries into clear, professional analyst prose. Optional layer — system falls back to deterministic thesis if this fails.', 'Rewrites deterministic trade thesis summaries into clear, professional analyst prose. Optional layer — system falls back to deterministic thesis if this fails.',
'ollama', 'ollama',
'qwen3.5:9b', 'qwen3.5:9b-fast',
'You are a concise financial analyst. You rewrite structured trade thesis summaries into clear, professional prose suitable for an internal research note. STRICT RULES: 1. Do NOT add any information not present in the input. 2. Do NOT fabricate numbers, dates, company names. 3. Keep under 150 words. 4. Preserve all factual claims, risk notes, evidence counts. 5. Neutral, professional tone. 6. Return ONLY the rewritten thesis text.', E'You are a concise financial analyst. You rewrite structured trade thesis summaries into clear, professional prose suitable for an internal research note.\n\nSTRICT RULES:\n1. Do NOT add any information that is not present in the input.\n2. Do NOT fabricate numbers, dates, company names, or analyst opinions.\n3. Keep the rewrite under 150 words.\n4. Preserve all factual claims, risk notes, and evidence counts from the input.\n5. Use a neutral, professional tone. Avoid hype or marketing language.\n6. Return ONLY the rewritten thesis text. No JSON, no markdown, no commentary.',
'thesis-rewrite-v1', 'thesis-rewrite-v1',
'1.0.0', '1.0.0',
'system' 'system'
@@ -0,0 +1,22 @@
-- Sync ai_agents system_prompt and model_name to match code defaults.
-- The original 026 seed used abbreviated prompts and the base model name;
-- this migration brings them in line with the authoritative prompts defined
-- in the Python service code and the actual deployed model tag.
UPDATE ai_agents
SET system_prompt = E'You are a financial document analyst. Extract structured data as JSON. Return ONLY a single JSON object. No markdown fences, no explanation, no text before or after the JSON. Every field in the schema is required. Use "other" for catalyst_type if unsure. Keep evidence_spans short (under 20 words each). Keep key_facts to 3-5 items max.',
model_name = 'qwen3.5:9b-fast',
updated_at = NOW()
WHERE slug = 'document-extractor';
UPDATE ai_agents
SET system_prompt = E'You classify MACRO-LEVEL global news into structured event JSON. Return ONLY a single JSON object. No markdown, no explanation. Every field is required. Keep key_facts to 3-5 items. Keep summary under 3 sentences.\n\nCRITICAL: Only classify articles about MACRO events that affect entire markets, sectors, or economies. Examples: trade wars, interest rate changes, commodity supply disruptions, regulatory changes, geopolitical conflicts, natural disasters.\n\nDO NOT classify as macro events: individual company earnings, lawsuits against a single company, single-company management changes, individual stock analysis, company-specific debt or bankruptcy, product launches by one company. For these, set severity to "low", confidence below 0.3, and leave affected_regions, affected_sectors, and affected_commodities as empty arrays.',
model_name = 'qwen3.5:9b-fast',
updated_at = NOW()
WHERE slug = 'event-classifier';
UPDATE ai_agents
SET system_prompt = E'You are a concise financial analyst. You rewrite structured trade thesis summaries into clear, professional prose suitable for an internal research note.\n\nSTRICT RULES:\n1. Do NOT add any information that is not present in the input.\n2. Do NOT fabricate numbers, dates, company names, or analyst opinions.\n3. Keep the rewrite under 150 words.\n4. Preserve all factual claims, risk notes, and evidence counts from the input.\n5. Use a neutral, professional tone. Avoid hype or marketing language.\n6. Return ONLY the rewritten thesis text. No JSON, no markdown, no commentary.',
model_name = 'qwen3.5:9b-fast',
updated_at = NOW()
WHERE slug = 'thesis-rewriter';