Defined in: [src/multiagent/swarm.ts:133](https://github.com/strands-agents/harness-sdk/blob/576da59fdc411b55036a7cf66d4e1659a67d4d0d/strands-ts/src/multiagent/swarm.ts#L133)

Swarm multi-agent orchestration pattern.

Agents execute sequentially, each deciding whether to hand off to another agent or produce a final response. Routing is driven by structured output: each agent receives a Zod schema with `agentId`, `message`, and optional `context` fields. When `agentId` is present, the swarm hands off to that agent with `message` as input. When omitted, `message` becomes the final response.

Key design choices vs the Python SDK:

-   Handoffs use structured output rather than an injected `handoff_to_agent` tool. Routing logic stays in the orchestrator, not inside tool callbacks.
-   Context is passed as serialized JSON text blocks rather than a mutable SharedContext.
-   A single `maxSteps` limit replaces Python’s separate `max_handoffs`/`max_iterations`.
-   Agent descriptions are embedded in the structured output schema for routing decisions.
-   Exceeding `maxSteps` throws an exception. Python returns a FAILED result.
-   Repetitive handoff detection follows Python’s soft-stop behavior and returns a FAILED result with an error.

## Example

```typescript
const swarm = new Swarm({
  nodes: [researcher, writer],
  start: 'researcher',
  maxSteps: 10,
})

const result = await swarm.invoke('Explain quantum computing')
```

## Implements

-   `MultiAgent`

## Constructors

### Constructor

```ts
new Swarm(options): Swarm;
```

Defined in: [src/multiagent/swarm.ts:151](https://github.com/strands-agents/harness-sdk/blob/576da59fdc411b55036a7cf66d4e1659a67d4d0d/strands-ts/src/multiagent/swarm.ts#L151)

#### Parameters

| Parameter | Type |
| --- | --- |
| `options` | `SwarmOptions` |

#### Returns

`Swarm`

## Properties

### id

```ts
readonly id: string;
```

Defined in: [src/multiagent/swarm.ts:134](https://github.com/strands-agents/harness-sdk/blob/576da59fdc411b55036a7cf66d4e1659a67d4d0d/strands-ts/src/multiagent/swarm.ts#L134)

Unique identifier for this orchestrator.

#### Implementation of

```ts
MultiAgent.id
```

---

### nodes

```ts
readonly nodes: ReadonlyMap<string, AgentNode>;
```

Defined in: [src/multiagent/swarm.ts:135](https://github.com/strands-agents/harness-sdk/blob/576da59fdc411b55036a7cf66d4e1659a67d4d0d/strands-ts/src/multiagent/swarm.ts#L135)

---

### config

```ts
readonly config: Required<SwarmConfig>;
```

Defined in: [src/multiagent/swarm.ts:136](https://github.com/strands-agents/harness-sdk/blob/576da59fdc411b55036a7cf66d4e1659a67d4d0d/strands-ts/src/multiagent/swarm.ts#L136)

---

### start

```ts
readonly start: AgentNode;
```

Defined in: [src/multiagent/swarm.ts:140](https://github.com/strands-agents/harness-sdk/blob/576da59fdc411b55036a7cf66d4e1659a67d4d0d/strands-ts/src/multiagent/swarm.ts#L140)

---

### sessionManager?

```ts
readonly optional sessionManager?: SessionManager;
```

Defined in: [src/multiagent/swarm.ts:141](https://github.com/strands-agents/harness-sdk/blob/576da59fdc411b55036a7cf66d4e1659a67d4d0d/strands-ts/src/multiagent/swarm.ts#L141)

## Methods

### initialize()

```ts
initialize(): Promise<void>;
```

Defined in: [src/multiagent/swarm.ts:192](https://github.com/strands-agents/harness-sdk/blob/576da59fdc411b55036a7cf66d4e1659a67d4d0d/strands-ts/src/multiagent/swarm.ts#L192)

Initialize the swarm. Invokes the MultiAgentInitializedEvent callback. Called automatically on first invocation.

#### Returns

`Promise`<`void`\>

---

### addHook()

```ts
addHook<T>(eventType, callback): HookCleanup;
```

Defined in: [src/multiagent/swarm.ts:206](https://github.com/strands-agents/harness-sdk/blob/576da59fdc411b55036a7cf66d4e1659a67d4d0d/strands-ts/src/multiagent/swarm.ts#L206)

Register a hook callback for a specific swarm event type.

#### Type Parameters

| Type Parameter |
| --- |
| `T` *extends* [`HookableEvent`](/pr-cms-3708/docs/api/typescript/HookableEvent/index.md) |

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `eventType` | [`HookableEventConstructor`](/pr-cms-3708/docs/api/typescript/HookableEventConstructor/index.md)<`T`\> | The event class constructor to register the callback for |
| `callback` | [`HookCallback`](/pr-cms-3708/docs/api/typescript/HookCallback/index.md)<`T`\> | The callback function to invoke when the event occurs |

#### Returns

`HookCleanup`

Cleanup function that removes the callback when invoked

#### Implementation of

```ts
MultiAgent.addHook
```

---

### invoke()

```ts
invoke(input, options?): Promise<MultiAgentResult>;
```

Defined in: [src/multiagent/swarm.ts:217](https://github.com/strands-agents/harness-sdk/blob/576da59fdc411b55036a7cf66d4e1659a67d4d0d/strands-ts/src/multiagent/swarm.ts#L217)

Invoke swarm and return final result (consumes stream).

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `input` | `MultiAgentInput` | The input to pass to the start agent |
| `options?` | `MultiAgentInvokeOptions` | Optional per-invocation options (e.g., [InvocationState](/pr-cms-3708/docs/api/typescript/InvocationState/index.md)) |

#### Returns

`Promise`<`MultiAgentResult`\>

Promise resolving to the final MultiAgentResult

#### Implementation of

```ts
MultiAgent.invoke
```

---

### stream()

```ts
stream(input, options?): AsyncGenerator<MultiAgentStreamEvent, MultiAgentResult, undefined>;
```

Defined in: [src/multiagent/swarm.ts:234](https://github.com/strands-agents/harness-sdk/blob/576da59fdc411b55036a7cf66d4e1659a67d4d0d/strands-ts/src/multiagent/swarm.ts#L234)

Stream swarm execution, yielding events as agents execute. Invokes hook callbacks for each event before yielding.

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `input` | `MultiAgentInput` | The input to pass to the start agent |
| `options?` | `MultiAgentInvokeOptions` | Optional per-invocation options (e.g., [InvocationState](/pr-cms-3708/docs/api/typescript/InvocationState/index.md)) |

#### Returns

`AsyncGenerator`<`MultiAgentStreamEvent`, `MultiAgentResult`, `undefined`\>

Async generator yielding streaming events and returning a MultiAgentResult

#### Implementation of

```ts
MultiAgent.stream
```