Tool use patterns
Structured patterns for calling external tools, APIs, and functions from within Meridian agent loops. Covers parallel execution, chaining, and error recovery.
Parallel fan-out
When multiple tool calls share no data dependencies, dispatch them simultaneously. Meridian merges results into a single context window before the next reasoning step, cutting latency by up to 4×.
// All three calls fire in parallel
const [weather, news, stock] = await Promise.all([
tool.weather("NYC"),
tool.news("tech"),
tool.stock("AAPL")
])Sequential chaining
When output of tool A feeds input of tool B, run them in order. Meridian preserves intermediate results so the model can inspect each step before proceeding.
const user = await tool.dbQuery("SELECT id FROM users");
const perms = await tool.checkPerms(user.id);
return perms.canAccess ? grant() : deny();Retry with backoff
External APIs fail. Wrap tool calls in a retry loop with exponential backoff and jitter. Meridian surfaces transient errors so the model can decide whether to retry or fall back.
for (let i = 0; i < 3; i++) {
try { return await tool.apiCall(); }
catch (e) {
if (i === 2) throw e;
await sleep(2 ** i * 100 + Math.random() * 50);
}
}Tool result validation
Always validate tool outputs before passing them back to the model. Malformed JSON, unexpected schemas, or empty results should trigger a structured error the model can reason about.