---
url: >-
  https://adk.nht.io/api/@nhtio/adk/batteries/context/compact/contracts/type-aliases/SummarizeFn.md
description: >-
  THE model-call seam this battery cannot perform itself: given a system prompt
  and a body of text to summarize, return the summary text.
---

# Type Alias: SummarizeFn

```ts
type SummarizeFn = (req: { system: string; text: string }) => Promise<string>;
```

Defined in: [src/batteries/context/compact/contracts.ts:78](https://github.com/NHTIO/ADK/blob/v1.20261003.0/src/src/batteries/context/compact/contracts.ts#L78)

THE model-call seam this battery cannot perform itself: given a system prompt and a body of text to
summarize, return the summary text.

## Parameters

| Parameter    | Type                                        | Description                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ------------ | ------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `req`        | { `system`: `string`; `text`: `string`; } | `system`: the compaction instructions (see [@nhtio/adk/batteries/context/compact/summarizer!COMPACTION\_SYSTEM\_PROMPT](../../summarizer/variables/COMPACTION_SYSTEM_PROMPT.md) for the shipped default); `text`: the body of older conversation (and, on a rolling re-summarize, the prior summary folded in — see [@nhtio/adk/batteries/context/compact/summarizer!summariseTurns](../../summarizer/functions/summariseTurns.md)) to compress. |
| `req.system` | `string`                                    | -                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `req.text`   | `string`                                    | -                                                                                                                                                                                                                                                                                                                                                                                                                                              |

## Returns

`Promise`<`string`>

The summary text, awaited. A rejected promise propagates to the caller of
`summariseTurns`/`assembleCompactedTurns` uncaught — this battery does not swallow summarizer
failures; a caller wanting graceful degradation (e.g. "fall back to the prior summary") implements
that inside their own `SummarizeFn`, exactly as the production flagship agent's own summarizer did.

## Remarks

The battery never names `DispatchRunner`, an adapter, or an executor — it has no idea how the
caller talks to a model, and it must not. The canonical ADK recipe for building one (the recipe the
production flagship agent this battery was extracted from actually uses, and the one the docs page
for this battery walks through in full) is:

```ts
const summarize: SummarizeFn = async ({ system, text }) => {
  let out = "";
  const noop = async (): Promise<void> => undefined;
  const noopArr = async (): Promise<never[]> => [];
  await DispatchRunner.dispatch({
    raw: {
      systemPrompt: new Tokenizable(system),
      standingInstructions: [],
      messages: [
        new Message({
          id: `__compact-${Date.now()}`,
          role: "user",
          content: text,
          createdAt: new Date().toISOString(),
          updatedAt: new Date().toISOString(),
        }),
      ],
      // Every other RawTurnContext capability is a noop — this dispatch never reads or writes any
      // OTHER persisted state, it only wants the model's completion text.
      fetchMemories: noopArr,
      fetchRetrievables: noopArr,
      fetchMessages: noopArr,
      fetchThoughts: noopArr,
      fetchToolCalls: noopArr,
      fetchTools: noopArr,
      refreshStandingInstructions: noopArr,
      storeStandingInstruction: noop,
      mutateStandingInstruction: noop,
      deleteStandingInstruction: noop,
      storeMemory: noop,
      mutateMemory: noop,
      deleteMemory: noop,
      storeRetrievable: noop,
      mutateRetrievable: noop,
      deleteRetrievable: noop,
      storeMessage: async (_c, v) => {
        out += v.content?.toString?.() ?? "";
      },
      mutateMessage: noop,
      deleteMessage: noop,
      storeThought: noop,
      mutateThought: noop,
      deleteThought: noop,
      storeToolCall: noop,
      mutateToolCall: noop,
      deleteToolCall: noop,
      storeMediaBytes: noop,
      storeRetrievableBytes: noop,
    } as never,
    executor: await adapter.executor({
      maxTokens: 1200,
      toolCallParser: "none",
      stream: false,
      autoAck: true,
      enableThinking: false,
    }),
  });
  return out.trim();
};
```

A caller with a different transport (a direct HTTP call to an LLM API, a queue-backed worker, a
mocked test double) supplies whatever function satisfies this signature — the battery only ever
awaits the returned string.
