{ "name": "Context Curator", "nodes": [ { "parameters": { "httpMethod": "POST", "path": "context-curator", "responseMode": "onReceived", "options": {} }, "name": "Bzzz Webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 1, "position": [250, 300] }, { "parameters": { "functionCode": "const path = $json[\"path\"] || \"\";\n\n// Simple deterministic rules (expand later)\nconst rules = [\n { pattern: /node_modules/, decision: { relevance: \"exclude\", reason: \"node_modules irrelevant\" } },\n { pattern: /.*\\.log$/, decision: { relevance: \"exclude\", reason: \"log file\" } },\n { pattern: /.*\\.css$/, decision: { relevance: \"include\", roles: [\"frontend\"], reason: \"CSS → frontend\" } },\n { pattern: /.*\\.sql$/, decision: { relevance: \"include\", roles: [\"backend\"], reason: \"SQL → backend\" } }\n];\n\n// Look for match\nlet match = null;\nfor (const rule of rules) {\n if (rule.pattern.test(path)) {\n match = rule.decision;\n break;\n }\n}\n\nreturn [{ json: { matched: !!match, decision: match, path } }];" }, "name": "Deterministic Rules", "type": "n8n-nodes-base.function", "typeVersion": 1, "position": [500, 300] }, { "parameters": { "conditions": { "boolean": [], "number": [], "string": [ { "value1": "={{$json[\"matched\"]}}", "operation": "isEqual", "value2": "true" } ] } }, "name": "Matched?", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [750, 300] }, { "parameters": { "functionCode": "return [{ json: {\n action: \"context_rule.add\",\n rule: {\n target: $json.path,\n condition: { role: $json.decision?.roles || [] },\n action: {\n relevance: $json.decision?.relevance || \"exclude\",\n scope: \"local\"\n },\n metadata: {\n reason: $json.decision?.reason || \"Deterministic rule match\"\n }\n }\n} }];" }, "name": "Build Decision (Deterministic)", "type": "n8n-nodes-base.function", "typeVersion": 1, "position": [1000, 200] }, { "parameters": { "functionCode": "return [{ json: {\n prompt: `You are the Context Curator for a multi-agent AI system. Analyze this discovery and decide which agent roles it is relevant to, whether to include, exclude, or escalate, and draft a Context Rule DSL snippet.\\n\\nPath: ${$json.path}\\n\\nMetadata: ${JSON.stringify($json.metadata || {})}`\n} }];" }, "name": "Build Model Prompt", "type": "n8n-nodes-base.function", "typeVersion": 1, "position": [1000, 400] }, { "parameters": { "resource": "chat", "operation": "create", "model": "gpt-4o", "messages": [ { "role": "system", "content": "You are the Context Curator for a multi-agent system. Decide on relevance, roles, and generate a Context Rule JSON." }, { "role": "user", "content": "={{$json[\"prompt\"]}}" } ] }, "name": "Call Curator Model", "type": "n8n-nodes-openai.chat", "typeVersion": 1, "position": [1250, 400], "credentials": { "openAIApi": "OpenAI API" } }, { "parameters": { "functionCode": "// Parse model response (assume model replies with JSON rule)\nlet rule;\ntry {\n rule = JSON.parse($json.choices[0].message.content);\n} catch (e) {\n rule = { error: \"Model response parse error\", raw: $json };\n}\n\nreturn [{ json: { action: \"context_rule.add\", rule } }];" }, "name": "Parse Model Output", "type": "n8n-nodes-base.function", "typeVersion": 1, "position": [1500, 400] }, { "parameters": { "url": "http://hive.local/api/context", "method": "POST", "jsonParameters": true, "options": {}, "body": "={{$json}}" }, "name": "Send Decision to Hive", "type": "n8n-nodes-base.httpRequest", "typeVersion": 1, "position": [1750, 300] } ], "connections": { "Bzzz Webhook": { "main": [ [ { "node": "Deterministic Rules", "type": "main", "index": 0 } ] ] }, "Deterministic Rules": { "main": [ [ { "node": "Matched?", "type": "main", "index": 0 } ] ] }, "Matched?": { "main": [ [ { "node": "Build Decision (Deterministic)", "type": "main", "index": 0 } ], [ { "node": "Build Model Prompt", "type": "main", "index": 0 } ] ] }, "Build Decision (Deterministic)": { "main": [ [ { "node": "Send Decision to Hive", "type": "main", "index": 0 } ] ] }, "Build Model Prompt": { "main": [ [ { "node": "Call Curator Model", "type": "main", "index": 0 } ] ] }, "Call Curator Model": { "main": [ [ { "node": "Parse Model Output", "type": "main", "index": 0 } ] ] }, "Parse Model Output": { "main": [ [ { "node": "Send Decision to Hive", "type": "main", "index": 0 } ] ] } } }