{ "id": "0gxdxCdYQ7oXk7gC", "name": "MAM Series Enricher", "nodes": [ { "parameters": {}, "id": "execute-workflow-trigger", "name": "Execute Workflow Trigger", "position": [ 224, 640 ], "type": "n8n-nodes-base.executeWorkflowTrigger", "typeVersion": 1 }, { "parameters": { "conditions": { "options": { "version": 2, "leftValue": "", "caseSensitive": true, "typeValidation": "strict" }, "conditions": [ { "id": "condition-1", "leftValue": "={{ $json.enrichment_status }}", "operator": { "type": "string", "operation": "notEquals" }, "rightValue": "enriched" } ], "combinator": "or" }, "options": {} }, "id": "check-enrichment-needs", "name": "Check Enrichment Needs", "position": [ 448, 640 ], "type": "n8n-nodes-base.if", "typeVersion": 2.2 }, { "parameters": { "assignments": { "assignments": [ { "id": "assign-1", "name": "success", "type": "boolean", "value": true }, { "id": "assign-2", "name": "series_id", "type": "string", "value": "={{ $json.id }}" }, { "id": "assign-3", "name": "series_name", "type": "string", "value": "={{ $json.series_name }}" }, { "id": "assign-4", "name": "message", "type": "string", "value": "Series already fully enriched" } ] }, "options": {} }, "id": "already-enriched", "name": "Already Enriched", "position": [ 848, 832 ], "type": "n8n-nodes-base.set", "typeVersion": 3.4 }, { "parameters": { "conditions": { "options": { "version": 2, "leftValue": "", "caseSensitive": true, "typeValidation": "strict" }, "conditions": [ { "id": "condition-1", "leftValue": "={{ $json.mam_series_id }}", "operator": { "type": "string", "operation": "notEmpty", "singleValue": true }, "rightValue": "" } ], "combinator": "and" }, "options": {} }, "id": "route-by-success", "name": "Route by Success", "position": [ 1472, 432 ], "type": "n8n-nodes-base.if", "typeVersion": 2.2 }, { "parameters": { "promptType": "define", "text": "=Find the Series ID for: {{ $json.series_name }} by {{ $json.author_folder }}", "hasOutputParser": true, "needsFallback": true, "options": { "systemMessage": "=You are an expert metadata librarian.\n\n### YOUR GOAL\nFind the unique Series ID (integer) on MyAnonaMouse (MAM) for the input Series Name.\n\n### YOUR TOOL\n- **search_mam**: Input is a search string. It searches Titles, Authors, and Series names. Returns a list of results.\n\n### EXECUTION STEPS\n1. **Direct Search:** Start by searching for the exact Series Name.\n2. **Author Strategy (Fallback):** If the series search fails or returns 0 results:\n - Search for the **Author's Name** (from `author_folder` or `author`).\n - Scan the list of books returned.\n - Look for ANY book that appears to belong to the target series (check `series_info`).\n - If you find a book in the series, extract the Series ID from its `series_info`.\n3. **Analyze:**\n - Look for `series_info` (e.g., `{\"669061\": [\"Series Title\", \"1\"]}`).\n - The Series ID is the key (`669061`).\n4. **Validation:** Ensure the found series name matches the user's request.\n\n### OUTPUT FORMAT\nReturn a single JSON object.\n- `mam_series_id`: The ID found (or null).\n- `found_series_name`: The exact series name from the `series_info` field.", "maxIterations": 20 } }, "type": "@n8n/n8n-nodes-langchain.agent", "typeVersion": 3, "position": [ 672, 224 ], "id": "882d88ae-7d06-468f-9524-c7dbad701365", "name": "AI Agent", "alwaysOutputData": true, "onError": "continueErrorOutput" }, { "parameters": { "workflowId": { "__rl": true, "value": "c3N3bYrOAy0rNGGq", "mode": "list", "cachedResultUrl": "/workflow/c3N3bYrOAy0rNGGq", "cachedResultName": "MAM Search API Tool" }, "workflowInputs": { "mappingMode": "defineBelow", "value": { "search_term": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('search_term', ``, 'string') }}" }, "matchingColumns": [ "search_term" ], "schema": [ { "id": "search_term", "displayName": "search_term", "required": false, "defaultMatch": false, "display": true, "canBeUsedToMatch": true, "removed": false } ], "attemptToConvertTypes": false, "convertFieldsToString": false } }, "type": "@n8n/n8n-nodes-langchain.toolWorkflow", "typeVersion": 2.2, "position": [ 752, 448 ], "id": "d8a735da-8f5b-4020-816a-1a889c546d44", "name": "Call 'MAM Search API Tool'" }, { "parameters": { "model": { "__rl": true, "value": "minimaxai/minimax-m2", "mode": "list", "cachedResultName": "minimaxai/minimax-m2" }, "responsesApiEnabled": false, "options": {} }, "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi", "typeVersion": 1.3, "position": [ 816, 656 ], "id": "54820ab8-524b-4a1a-a939-6e9d0ecf777f", "name": "OpenAI Chat Model", "credentials": { "openAiApi": { "id": "QRBx9RMx4KoFwGgl", "name": "Nvidia account" } } }, { "parameters": { "schemaType": "manual", "inputSchema": "{\n \"type\": \"object\",\n \"properties\": {\n \"mam_series_id\": {\n \"type\": [\"string\", \"null\"],\n \"description\": \"The unique Series ID found. Null if not found.\"\n },\n \"found_series_name\": {\n \"type\": [\"string\", \"null\"],\n \"description\": \"The name of the series exactly as it appears in the MAM database.\"\n }\n },\n \"required\": [\n \"mam_series_id\",\n \"found_series_name\"\n ]\n}", "autoFix": true }, "type": "@n8n/n8n-nodes-langchain.outputParserStructured", "typeVersion": 1.3, "position": [ 880, 448 ], "id": "662ea129-ecfd-4232-ad37-200ad912ea62", "name": "Structured Output Parser" }, { "parameters": { "assignments": { "assignments": [ { "id": "cc0ebae4-c92b-4d03-8786-9f7e4e6438f2", "name": "mam_series_id", "value": "={{ $json.output.mam_series_id }}", "type": "string" }, { "id": "bd249040-fe5c-4776-9ee0-0cececd613d1", "name": "series_name", "value": "={{ $json.output.found_series_name }}", "type": "string" } ] }, "options": {} }, "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 1248, 432 ], "id": "890dab5a-2306-40da-b498-564e77d1fb67", "name": "Edit Fields" } ], "connections": { "Check Enrichment Needs": { "main": [ [ { "node": "AI Agent", "type": "main", "index": 0 } ], [ { "index": 0, "node": "Already Enriched", "type": "main" } ] ] }, "Execute Workflow Trigger": { "main": [ [ { "node": "Check Enrichment Needs", "type": "main", "index": 0 } ] ] }, "Route by Success": { "main": [ [], [] ] }, "Call 'MAM Search API Tool'": { "ai_tool": [ [ { "node": "AI Agent", "type": "ai_tool", "index": 0 } ] ] }, "AI Agent": { "main": [ [ { "node": "Edit Fields", "type": "main", "index": 0 } ], [] ] }, "OpenAI Chat Model": { "ai_languageModel": [ [ { "node": "AI Agent", "type": "ai_languageModel", "index": 0 }, { "node": "Structured Output Parser", "type": "ai_languageModel", "index": 0 }, { "node": "AI Agent", "type": "ai_languageModel", "index": 1 } ] ] }, "Structured Output Parser": { "ai_outputParser": [ [ { "node": "AI Agent", "type": "ai_outputParser", "index": 0 } ] ] }, "Edit Fields": { "main": [ [ { "node": "Route by Success", "type": "main", "index": 0 } ] ] } }, "settings": { "saveExecutionProgress": true, "saveManualExecutions": true, "saveDataErrorExecution": "all", "saveDataSuccessExecution": "all", "executionOrder": "v1" }, "triggerCount": 0, "versionId": "6979f441-1ec7-4907-84ab-0255a9f21c26", "owner": { "type": "personal", "projectId": "FeLO36wNUAcn61Wj", "projectName": "Ben W ", "personalEmail": "admin@ben.io" }, "parentFolderId": "6tDyZCwqELStb6Ik", "isArchived": false }