> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devin.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Devin SDK example: Anthropic agent patterns

> The five agent workflow patterns from Anthropic's Building effective agents, each built on Devin SDK session.run() with typed output.

> [!NOTE]
>
> Source:
> [`anthropic-patterns`](https://github.com/COG-GTM/devin-sdk-examples/tree/main/anthropic-patterns)

The patterns from
[Building effective agents](https://www.anthropic.com/engineering/building-effective-agents) with
Devin as the agent:

| Pattern | Run | What it shows |
| - | - | - |
| Prompt chaining | `bun run chaining` | Sequential steps in one session, a typed structured-output gate between them |
| Routing | `bun run routing` | A classifier turn whose zod-typed result dispatches to specialized handlers |
| Parallelization | `bun run parallelization` | Independent sessions under `Promise.all` — sectioning and majority voting |
| Orchestrator-workers | `bun run orchestrator-workers` | An orchestrator plans subtasks, workers run in parallel, the orchestrator merges |
| Evaluator-optimizer | `bun run evaluator-optimizer` | A generator/evaluator loop driven by a typed pass/feedback verdict |

The glue in every pattern is structured output: `session.run(prompt, { output: zodSchema })`
instructs the agent to reply with matching JSON, validates the reply, and gives you a fully typed
`outcome.output` to branch on in plain TypeScript. Nothing here is Devin-specific beyond that
one call, which is the point: control flow stays in your code, the model fills in one step.

```ts evaluator-optimizer.ts (excerpt) theme={null}
const Verdict = z.object({ pass: z.boolean(), feedback: z.string() });

for (let round = 1; round <= 3; round++) {
  const verdict = await evaluator.run(
    `Grade this against the criteria. No tools.\nCriteria: ${criteria}\nDraft:\n${draft}`,
    { output: Verdict },
  );
  if (verdict.output.pass) break;
  // The generator session keeps its own history; just feed it the feedback.
  draft = (
    await generator.run(
      `Revise per this feedback, code only, no tools:\n${verdict.output.feedback}`,
    )
  ).text.trim();
}
```

## What you should see

Model text varies run to run, but the shape is stable. `bun run evaluator-optimizer` prints the
grading loop converging:

```
round 1: pass=false — The implementation … does not swap lo and hi when lo > hi …
round 2: pass=true — It is a single line and correctly handles lo > hi …

final draft:
const clamp = (n, lo, hi) => Math.max(Math.min(n, Math.max(lo, hi)), Math.min(lo, hi));
```

and `bun run parallelization` prints three independent one-sentence reviews followed by
`votes safe=[false, false, false] -> majority: unsafe`.

## Run

```sh theme={null}
git clone https://github.com/COG-GTM/devin-sdk-examples
cd devin-sdk-examples/anthropic-patterns
bun install                    # @cognition-ai/sdk from npm (the pinned beta)
export DEVIN_API_KEY=cog_…
bun run chaining
```

Every pattern opens with a bare `createDevin()`, so it runs in the cloud. Pass
`createDevin({ cwd: process.cwd() })` to run through the bundled CLI instead (the patterns are
chat-only, so nothing is written there), or `createSession({ repos: ["your-org/your-repo"] })`
to give a cloud session a repository to work in.

> [card] [Launch and structured output](https://docs.devin.ai/sdk/guides/launch-and-structured-output.md)
>
> How `run(prompt, {output})` validates the reply and what happens when it doesn't match.

> [card] [Ticket enricher](https://docs.devin.ai/sdk/examples/ticket-enricher.md)
>
> One of these patterns deployed as a webhook, with a queue and a typed result.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.