MechaMental
Guides

Building a Pipeline

Step-by-step guide to creating an augmentation pipeline with stages, steps, prompts, tools, and streaming.

Prerequisites

  • A workspace with at least one app created
  • At least one logical model configured in your workspace

Overview

This guide walks you through building a complete augmentation pipeline in MechaMental: creating the pipeline, adding stages and steps, writing a prompt, attaching tools, enabling streaming, and testing via an endpoint.

Create the Pipeline

  1. Open your app and navigate to the Augmentations tab
  2. Click the New Pipeline button in the top-right corner
  3. The Create Augmentation Pipeline dialog appears with two fields:
    • Name -- a short identifier (e.g., chat_flow, summarize_flow)
    • Description -- what this pipeline does
  4. Click Create Pipeline

You are automatically navigated to the pipeline editor, which displays a horizontal stage layout.

Add a Stage

Stages are horizontal columns that group related steps. The pipeline executes stages left to right, and steps within a stage run in order (top to bottom).

  1. In the pipeline editor, click the Add Stage button (the dashed-border card on the right side of the canvas)
  2. The Create Stage dialog appears with:
    • Name -- e.g., "Retrieval", "Processing", "Response"
    • Description -- purpose of this stage
  3. Click Create Stage

The new stage appears as a column in the pipeline editor. For a simple pipeline, one stage is enough.

Add an Inference Step

  1. Inside your stage, click + Add Step
  2. The step detail dialog opens on the General tab
  3. Fill in:
    • Name -- e.g., "LLM Response"
    • Step Type -- select Inference (Brain icon, purple)
    • Description -- optional explanation
  4. Under Execution Settings, configure:
    • Timeout (seconds) -- maximum time before the step times out (default 30)
    • Max Retries -- number of retry attempts on failure

Step Types

The step type dropdown shows all available types with icons and descriptions. Inference is the most common, but see Configuring Step Types for the full list.

Configure the Prompt

  1. Switch to the Prompt tab in the step detail dialog
  2. The tab presents a full-screen Jinja2 editor styled like an IDE, with:
    • A prompt.jinja2 file tab at the top
    • A character count and variable count badge in the header
    • Syntax hints in the footer: {{ }} for variables, {% %} for control flow
  3. Write your system prompt using Jinja2 template syntax:
You are a helpful customer support assistant for {{ endpoint_payload.company_name }}.

The user's query: {{ endpoint_payload.message }}

Respond concisely and professionally. If you need more information,
ask a clarifying question.

Variable Syntax

Use {{ endpoint_payload.field }} to inject values from the incoming request. Use {{ stages.stage_name.steps.step_name.field }} to reference outputs from previous steps. The variable count badge updates as you add template variables.

Attach Tools (Optional)

If your pipeline needs to call external tools during inference:

  1. Switch to the Tools tab (labeled Tools & Skills)
  2. The tab shows all active MCP-compatible tool instances in your workspace
  3. Use the search bar to find specific tools, then click a tool row to select it
  4. Selected tools appear as amber chips at the top with a count badge
  5. Under Execution Settings (appears when tools are selected):
    • Tool Execution Mode: choose Single Turn (tool called once, then LLM responds) or Multi Turn (Agentic) (LLM calls tools in a loop until done)
    • Max Tool Rounds: if multi-turn, set the maximum rounds (1--10) before forcing a final answer

Enable Event Streaming (Optional)

To stream responses in real time via Server-Sent Events:

  1. Switch to the Advanced tab
  2. Under Event Streaming (SSE), toggle Enable Event Publishing on
  3. For inference steps, toggle Stream Tokens to stream LLM tokens as they are generated
  4. Configure the Event Mode:
    • Domain Event -- standardized event name based on step type (e.g., inference.completed)
    • Custom Event -- define your own event name
  5. Set the Event Action:
    • Primary -- user-facing response or main output
    • Secondary -- thinking, intermediate feedback, or auxiliary output (shows in Cortex's cognitive chain)
    • Default -- standard action for the step type

Create an Endpoint and Test

  1. Back in the pipeline editor toolbar, you can create an endpoint connected to this pipeline
  2. Set the path (e.g., /chat), method (POST), and optionally define an input schema
  3. After the endpoint is created, test it with any HTTP client:
curl -X POST https://api.mechamental.com/v1/trigger/chat \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"message": "How do I reset my password?", "company_name": "Acme"}'

For SSE streaming, the response streams events as they are produced by the pipeline.

Next Steps

On this page