Orchestrate multiple agents
Sequence agent runs or run independent tasks in parallel using your app code or integration.
Coordinate several agents by giving each one a defined task and passing its results through your app or integration. You will choose a sequence or parallel pattern, define the data exchanged between runs, and decide what happens when a run fails.
Choose a coordination pattern
Agents do not share memory. Orchestration is the logic you build in your app, records, integrations, and API calls to sequence or fan out runs and pass their data.
| Pattern | Use it when | Your code or integration must |
|---|---|---|
| Sequence in an app page | A later agent needs an earlier answer | Wait for successful completion, then map outputs to the next agent's inputs. |
| Parallel runs from app code | Tasks use the same source data independently | Save each run ID, read each result, and combine answers after the required runs complete. |
| Sequence in an integration | Work begins with a schedule or business event | Start the first run, delay, read it, check its status, then start the next. |
Each run starts fresh. Include the original request context and any earlier findings the next agent needs in its inputs.
Define the exchange between agents
- Name one job for each agent. For example, a triage agent classifies a ticket, and a reply agent drafts a response for that category.
- Define the first agent's outputs. Use fields such as Text
Category, NumberUrgency, and TextReason. These names are examples you choose. - Define matching inputs for the next agent. Include the original ticket text as well as the category if the reply requires both.
- Decide which statuses allow the next run to start. Continue only when required runs are
Completedand their outputs pass your checks. - Save the execution IDs and findings with the business item so you can inspect each handoff.
A completed run means structured results are available. Check that those results meet your business requirements before passing them onward. For example, route an unrecognized category to a reviewer rather than assuming it is valid.
Coordinate from an app page
Use the SDK to start a run and handle its completion. kf.app.getAgent(agentId) returns the agent without sending a request. execute({ inputData }) returns {ExecutionId, Status}. onExecutionComplete(executionId, onComplete, onWatchError) watches the run and returns a function that stops the watch. SDK calls reject with {isError: true, error, errorCode} on failure, so wrap them in try/catch. See Agent SDK and the SDK reference.
Two limits shape this design. The watch gives up after about 6 minutes (AGENT_OBSERVATION_STOPPED). Form, field, gallery and table scripts stop after 1 minute, and a pending call or watch ends with the script without calling back. Run these examples from a custom page or a custom component, not from those scripts.
Example 1: triage, then reply
This sequence starts a triage agent, waits for it, and passes its output to a reply agent. The input and output names are examples you define.
// Start a run and resolve with the finished execution.
// execute() rejects on error. The watch error handler rejects too.
async function runAgent(agent, inputData) {
const { ExecutionId } = await agent.execute({ inputData });
return new Promise((resolve, reject) => {
agent.onExecutionComplete(ExecutionId, resolve, reject);
});
}
const triage = kf.app.getAgent("<TRIAGE_AGENT_ID>");
const reply = kf.app.getAgent("<REPLY_AGENT_ID>");
const ticket = "My order arrived damaged.";
try {
const t = await runAgent(triage, { Ticket: ticket });
if (t.Status !== "Completed") throw t; // a Failed run is a result, not a rejection
const first = t.Output.items[0]; // output shape: {"items":[{...}]}
if (!first) throw new Error("The triage agent returned no result.");
const r = await runAgent(reply, {
Ticket: ticket,
Category: first.Category,
Urgency: first.Urgency,
});
if (r.Status !== "Completed") throw r;
console.log(r.Output.items[0]);
} catch (e) {
// Stop here. Send the ticket to a person.
// A rejected call has errorCode and error. A failed run has Status and Error.
console.log(e.errorCode || e.Status, e.error || e.Error);
}Example 2: two agents in parallel
Independent checks can run side by side. Start both, wait for both, then combine their items.
const credit = kf.app.getAgent("<CREDIT_AGENT_ID>");
const news = kf.app.getAgent("<NEWS_AGENT_ID>");
// Reuse the runAgent wrapper from Example 1.
const [c, n] = await Promise.allSettled([
runAgent(credit, { Vendor: "Example supplier" }),
runAgent(news, { Vendor: "Example supplier" }),
]);
const ok = (x) => x.status === "fulfilled" && x.value.Status === "Completed";
if (!ok(c) || !ok(n)) {
// One failed. Don't continue. Actions the other run took are not undone.
console.log("Review needed", c, n);
} else {
const combined = [...c.value.Output.items, ...n.value.Output.items];
console.log(combined);
}Promise.all rejects early if execute or the watch rejects. A Failed execution still resolves in this wrapper, so check each run's Status. Other runs continue. Each run still counts toward the account's Live-run limit, so some may stay Queued. See Limits. If observation stops after about 6 minutes, read the run later with getExecution and the saved ExecutionId. Queue time is separate from the 5-minute run limit.
Coordinate from an integration
- Start the first agent with an HTTP POST and save
ExecutionId. - Add a Delay, then GET that run. The Delay connector's minimum is 1 hour. See Delay connector.
- Inspect the status and validate the required outputs.
- Start the next agent only after those checks pass. Map the selected findings into its
InputData. - Handle its completion through tool writeback or another delayed read.
If one hour is too slow, chain from page code (SDK) or from your own system through the API, where you read the run as soon as it finishes. Keep pending runs available for later reads and send failed runs for review. Runs do not retry automatically. Before repeating any run, inspect tool actions to avoid duplicate changes.
Good to know
Your page code, integration or API calls coordinate the runs. An agent can't call another agent as a tool, and there is no built-in orchestrator or "agent finished" trigger yet.

