The Lumen Main Chat Response Agent is the backend chat workflow that powers Lumen’s core AI response experience.

It receives a chat request from the frontend, converts the user’s selected mode, memories, recent messages, and prompt-builder fields into a structured model prompt, sends the request to OpenRouter, and returns a normalized JSON response to the app.

This workflow is designed for Lumen’s positioning as an AI workspace. Instead of treating every chat as a plain message, the agent makes the response context-aware through modes, memory selection, prompt-builder metadata, and short-term conversation history. The chat capabilities are deliberately kept limited to keep the scope of

How the Workflow Works

  1. Webhook receives the chat request

The workflow starts with a POST webhook at /lumen-chat. The frontend sends the user message, selected mode, selected memories, recent messages, model preference, temperature, and optional prompt-builder fields.

  1. Build Prompt node prepares the model input

A JavaScript Code node extracts the request body and builds the final message array for the model. It supports multiple modes: Research Mode, Builder Mode, Tutorial Mode, Writing Mode, Strategy Mode.

  1. OpenRouter Chat node calls the model backend

The workflow sends the prepared messages to OpenRouter’s /chat/completions endpoint. The model defaults to openrouter/auto, but the frontend can override it by passing a model value.

  1. Normalize Response node standardizes the output

A second JavaScript Code node checks whether OpenRouter returned an error. If successful, it extracts the assistant reply, model name, usage metadata, and returns a clean success payload.

  1. Respond to Webhook returns JSON to the frontend

The workflow responds to the original request with a JSON object containing the final reply, model used, usage data, and status.

image.png

Tech Stack

n8n, OpenRouter AI Models, and custom JavaScript normalization logic.

Cleaned JSON Code

(Replaced sensitive/public-risk fields including credential IDs/names, Google Sheets document ID and URLs, Slack channel ID/name, webhook IDs, node IDs, workflow/version IDs, and the n8n instance ID.)