Skip to content
← all posts
4 min read

Build Your First Agent Chain in 5 Minutes

Mentiko Team

You have a Mentiko instance running. Now what? Let's build something real: a two-agent chain where one agent researches a topic and a second agent summarizes the findings. End to end, this takes about five minutes.

What you're building

The chain has two agents:

  1. Researcher -- takes a topic, gathers information, and saves its findings.
  2. Summarizer -- reads the researcher's output and condenses it into a three-paragraph brief.

The researcher triggers the summarizer automatically through Mentiko's event system. You don't wire them together with function calls or shared state. The researcher emits an event when it finishes, and the summarizer is watching for that event. That's it.

Step 1: Define the chain

Create a file called research-and-summarize.json in your chains/ directory:

{
  "name": "research-and-summarize",
  "agents": [
    {
      "name": "researcher",
      "prompt": "Research {TOPIC} thoroughly. Save your findings.",
      "triggers": ["chain:start"],
      "emits": ["research:complete"]
    },
    {
      "name": "summarizer",
      "prompt": "Read the researcher's output and create a concise 3-paragraph summary.",
      "triggers": ["research:complete"],
      "emits": ["chain:complete"]
    }
  ]
}

A few things to notice:

  • {TOPIC} is a variable. You'll pass its value at runtime.
  • triggers defines what starts each agent. The researcher starts on chain:start (the beginning of the pipeline). The summarizer starts on research:complete (the event the researcher emits when it finishes).
  • emits declares what event each agent produces. The summarizer emits chain:complete, which signals the entire chain is done.

This is the same portable JSON format whether you write it by hand or export it from the visual builder.

Step 2: Or use the visual builder

If you prefer drag-and-drop, open the chain editor in your Mentiko dashboard:

  1. Click New Chain and name it research-and-summarize.
  2. Drag a Researcher agent node onto the canvas. Set its prompt to "Research {TOPIC} thoroughly. Save your findings."
  3. Drag a Summarizer agent node onto the canvas. Set its prompt to "Read the researcher's output and create a concise 3-paragraph summary."
  4. Draw a connection from the researcher's output port to the summarizer's input port. The builder automatically creates the research:complete event binding for you.
  5. Click Save. The builder writes the same JSON shown above to your chains/ directory.

Both paths produce identical chain definitions. Use whichever fits your workflow.

Step 3: Run the chain

From the CLI:

mentiko run research-and-summarize --var TOPIC="event-driven architecture"

From the UI:

Click Run on the chain page, enter event-driven architecture for the TOPIC variable, and hit Execute. The dashboard shows each agent's status in real time -- you'll see the researcher go active, then complete, then the summarizer pick up automatically.

What happens under the hood

When you hit run, here's the sequence:

  1. chain-runner.sh reads your research-and-summarize.json and resolves the dependency graph. It sees the researcher triggers on chain:start, so it launches first.
  2. launch-agent.sh spawns the researcher in a real PTY session via pty-manager. The agent gets a full terminal -- stdin, stdout, environment variables, the works. The {TOPIC} variable is interpolated into its prompt.
  3. The researcher does its work: calling the LLM, gathering information, writing output to its run directory.
  4. When the researcher finishes, complete-agent.sh writes an event file to .events/researcher.event:
{
  "agent": "researcher",
  "status": "complete",
  "output_path": "/runs/abc123/researcher/output",
  "tokens_used": 8400,
  "duration_seconds": 22,
  "timestamp": "2026-03-19T10:15:33Z"
}
  1. event-trigger.sh is watching the .events/ directory. It sees researcher.event appear, checks the chain definition, and finds that the summarizer triggers on research:complete. It launches the summarizer.
  2. The summarizer reads the researcher's output from the path in the event file, generates a three-paragraph summary, and writes its own output.
  3. complete-agent.sh writes .events/summarizer.event with chain:complete, and the chain run is finished.

The entire flow is observable through those event files. If something fails, you cat the event file to see what happened. If you want to re-run just the summarizer with different settings, delete summarizer.event and re-trigger -- the researcher's output is still there.

What you can do next

This two-agent chain is the building block. From here:

  • Add more agents. Insert an editor between the researcher and summarizer, or add a fact-checker that runs in parallel with the summarizer. Each new agent is one more entry in the JSON array with its own trigger and emit declarations.
  • Schedule it on cron. Run the chain every morning with mentiko schedule research-and-summarize --cron "0 8 * * *" --var TOPIC="competitor updates". Your daily brief writes itself.
  • Add error handling. Create a recovery agent that watches for error events and routes failures to the right fix -- retry with a different model, truncate input for context length errors, or alert you for issues that need a human.
  • Parameterize everything. Add more variables: {MODEL}, {OUTPUT_FORMAT}, {MAX_TOKENS}. The same chain definition works across different configurations without editing the JSON.

The chain definition is a JSON file in your repo. Version it, review it in PRs, diff it between environments. It's your workflow, on your infrastructure, under your control.

Ready to build something more complex? Read Why Event-Driven Beats DAG-Based Agent Orchestration for the architecture behind how Mentiko chains work.

Get new posts in your inbox

No spam. Unsubscribe anytime.