# Step (/docs/build/step)



`.step()` runs one agent, tool, flow agent or `flow()`. Steps run in order, and
each step receives the previous step's output unless its `input` function
computes something else.

```ts
import { Agent } from "@nylorun/agents";

export const report = Agent({ id: "report" })
  .step(researcher)
  .step(analyst, {
    input: ({ results }) => `Summarize: ${results.researcher.findings}`,
  })
  .step(publish, {
    input: ({ input }) => ({ summary: input.summary }),
  });
```

## Values and results [#values-and-results]

* `input` is what this step would receive: the previous step's output.
* `results` holds earlier steps' outputs in this sequence, keyed by step id.
* `flowInput` is the flow agent's own input.

A step's id is the agent's id or the tool's name. Set `id` when the same agent
appears more than once, or when you want a stable result key:

```ts
.step(writer)
.step(editor)
.step(writer, { id: "final-writer", input: ({ results }) => results.editor })
```

The step with its own id runs in its own session (`final-writer`), with the
same definition. Where there is no options object, `.withId("final-writer")`
does the same.

A flow agent's output is its last stage's output. Runtime checkpoints every
stage, so a resumed flow does not repeat completed work.

See the shipped [`chain` example](https://github.com/nylorun/agents/tree/main/examples/agents/chain),
then learn how to [route with Switch](/docs/build/switch).
