---
title: "Rank memory, search, and tools"
lesson_id: "03"
---

# Rank memory, search, and tools

- **Lesson ID:** 03
- **Goal:** Rank slices by score and token cost, cap each lane, and fill leftover budget.
- **Human lesson:** [03-rank-memory-search-tools.html](03-rank-memory-search-tools.html)

## Prerequisites

- Lesson 02 leftover budget.

## Inputs, outputs, and artifacts

- **Inputs:** Scored slices with token costs and leftover budget.
- **Outputs:** An ordered pack that fits.

## Agent build steps

1. Define memory, search, and tool lanes.
2. Sort by score, then cheaper tokens on a tie.
3. Cap each lane so one source cannot fill the window.
4. Allow-list tools from app state, not similarity.
5. Drop leftover slices. Do not summarize on the first ship.

## Constraints

No LangChain. No em dashes.

## Key concepts

- Three competing lanes: memory, search hits, and tools.
- Each slice gets a score, a token cost, and a lane.
- Fill leftover budget from the top. Drop the rest.
- Cap each lane. Four memories and four hits is a sane start.

## Takeaways

- Score memory and search with your ranker. Tools use a hard allow-list.
- Tool schemas cost tokens too.
- Drop low slices first. Do not summarize until you have eval for summaries.

## Acceptance checks

- Three lanes are defined.
- A pack function is shown.
- Agent brief link is present.
