Build a tool-using agent with Meridian

A step-by-step walkthrough of the function-calling loop — how Meridian agents decide when to invoke tools, pass arguments, and incorporate results into their response stream.

The loop

1

User sends a message: "What's the weather in Oslo?"

2

Meridian emits a tool_call event with name get_weather and args { city: "Oslo" }

3

Your runtime executes the function, returns { temp: 7, condition: "cloudy" } as a tool_result

4

Meridian streams the final answer: "Oslo is 7°C and cloudy right now."

Minimal implementation

const tools = [{
  name: "get_weather",
  description: "Get current weather for a city",
  parameters: { city: "string" }
}];

for await (const event of meridian.stream({ tools })) {
  if (event.type === "tool_call") {
    const result = await executeTool(event);
    meridian.submit({ type: "tool_result", result });
  }
  if (event.type === "text") {
    process.stdout.write(event.content);
  }
}

Ready to build your own agent?

Get started