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:
- Researcher -- takes a topic, gathers information, and saves its findings.
- 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.triggersdefines what starts each agent. The researcher starts onchain:start(the beginning of the pipeline). The summarizer starts onresearch:complete(the event the researcher emits when it finishes).emitsdeclares what event each agent produces. The summarizer emitschain: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:
- Click New Chain and name it
research-and-summarize. - Drag a Researcher agent node onto the canvas. Set its prompt to "Research {TOPIC} thoroughly. Save your findings."
- Drag a Summarizer agent node onto the canvas. Set its prompt to "Read the researcher's output and create a concise 3-paragraph summary."
- Draw a connection from the researcher's output port to the summarizer's input port. The builder automatically creates the
research:completeevent binding for you. - 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:
chain-runner.shreads yourresearch-and-summarize.jsonand resolves the dependency graph. It sees the researcher triggers onchain:start, so it launches first.launch-agent.shspawns the researcher in a real PTY session viapty-manager. The agent gets a full terminal -- stdin, stdout, environment variables, the works. The{TOPIC}variable is interpolated into its prompt.- The researcher does its work: calling the LLM, gathering information, writing output to its run directory.
- When the researcher finishes,
complete-agent.shwrites 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"
}
event-trigger.shis watching the.events/directory. It seesresearcher.eventappear, checks the chain definition, and finds that the summarizer triggers onresearch:complete. It launches the summarizer.- The summarizer reads the researcher's output from the path in the event file, generates a three-paragraph summary, and writes its own output.
complete-agent.shwrites.events/summarizer.eventwithchain: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.