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

# Optimize an agent with plans

> Move tool calls an agent repeats every time into a plan it calls once, so it makes fewer model calls.

Every tool call an agent makes costs a model round. When it makes the same calls on every run, a plan can make them instead, with no model in between.

## Find the repeated calls

Run the agent and read the tool calls on stderr. This `release_notes` agent looks up the latest release, then reads the commits since it:

```bash theme={null}
graph ask --agent release_notes \
  "Draft release notes for what is unreleased."
```

```text theme={null}
→ github__tool__gh_release {"tag":""}
✓ github__tool__gh_release 1.3s
→ github__tool__git_log {"base":"v0.15.0","head":"HEAD"}
✓ github__tool__git_log 69.9ms
3 calls · 10k in / 2k out (4k cached) · $0.06
```

It makes the same two calls every time, so they can move into a plan.

## Put the calls in a plan

Save the sequence as `./.graph/plans/unreleased_changes.yaml`. The `output` finish returns the results as JSON without a model call:

```yaml theme={null}
version: 2
identifier: unreleased_changes
name: Unreleased changes
description: The commits since the latest release.
steps:
- id: release
  tool_name: github__tool__gh_release
  input: {}
- id: commits
  tool_name: github__tool__git_log
  input:
    base: '{{release.tag}}'
    head: HEAD
finish:
  output:
    since: '{{release.tag}}'
    commits: '{{commits.commits}}'
```

## Give the agent the plan

Replace the tools in the agent's `tools` list with the plan, as `plan__<identifier>`:

```yaml theme={null}
tools:
- plan__unreleased_changes
```

## Compare

Run the same question again. The agent calls the plan once, and the plan makes the tool calls:

```text theme={null}
→ plan__unreleased_changes {}
  → github__tool__gh_release {}
  ✓ github__tool__gh_release 1.1s
  → github__tool__git_log {"base":"v0.15.0","head":"HEAD"}
  ✓ github__tool__git_log 51.7ms
✓ plan__unreleased_changes 1.2s
2 calls · 5k in / 1k out · $0.04
```

## Related guides

> **[Draft a plan in the workbench](/plans/guides/draft-in-workbench)**
>
> Describe the work and let the workbench write the plan.

> **[Steer tool choice](/agents/guides/steer-tool-choice)**
>
> Help the agent pick the plan over other tools.

> **[Talk to an agent](/agents/guides/talk-to-an-agent)**
>
> Run the agent with `graph ask` and `graph chat`.


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