INSCRIPTION · COMPOSITION
Composing agents
Multiple agents can be bound to a single intent. They race, they cooperate, or they specialise — based on the policy you choose.
Composing agents
Many real strategies are not single-agent. A stable-yield position might benefit from a hedge on the ETH leg, a cross-chain router on rate divergence, and a vault keeper on emissions — three agents, one capital pool, one signed intent.
Composition makes that explicit. You compose an intent with multiple agents and a policy that describes how they should coordinate.
Composition policies
| Policy | Behavior |
|---|---|
highest-fit-wins | At each opportunity, only the best-fit agent acts. Others observe. |
cooperative | Agents emit plans; the runtime merges them into a single bundled execution if all bounds are respected. |
specialise | Each agent declares the capability slice it owns; no overlap. The runtime routes each opportunity to its owner. |
race | All eligible agents emit plans; the first valid plan to land wins. Useful for arbitrage. |
A worked example
typescriptimport { composeIntent } from "@magicscodes/sdk";
import { wraithOfYield } from "@magicscodes/spells";
import { hedgeAdept } from "@magicscodes/spells";
import { stableYield } from "./intents";
// Two agents bound to one intent.
// - Wraith chooses the lending venue and rotates.
// - Hedge Adept neutralises the ETH leg if the venue uses cbETH collateral.
const composed = composeIntent({
intent: stableYield,
agents: [wraithOfYield, hedgeAdept],
policy: "cooperative",
ordering: "fit-descending",
});
await composed.summon({ walletClient });The runtime invokes the Wraith first (highest fit on a lending intent), then offers the resulting plan to the Hedge Adept, which appends an offsetting perp leg if it would be needed. Both legs execute in a single bundled transaction.
Ordering & fairness
ordering controls how agents are polled. Default is fit-descending. Other options:
round-robin— useful inracepolicy to avoid one agent monopolising.static— agents act in the order you list them. Use when you have a strict dependency.random— for testing only; do not ship.