ASK KNOX
beta
LESSON 347

The Query-First Habit: Recall Before You Act

The single most powerful memory discipline is not what you store — it is querying what you have before you take the first step on any task.

8 min read·Agent Memory 101

Introduction

You have a memory system. Facts are stored. Decisions are recorded. Past failures are documented. None of it matters if the agent — or you — does not actually look before acting.

The query-first habit is the discipline of retrieving relevant prior knowledge at the start of every task. Not after you hit a problem. Not when something feels familiar. Before. Always before.

This is a workflow rule, not a technical feature. You can have the best memory system in the world and still get zero value from it if the query step is skipped.

Core Concept

Why "First" Matters

The natural human (and AI) instinct is to start working, hit a problem, and then look up past experience. This feels efficient. It is not.

When you start working without querying memory, you commit to a direction before you have the full picture. That commitment creates momentum. By the time you hit a wall or realize you are repeating prior work, you have already spent time going the wrong direction — and now you have to reverse.

The query-first habit front-loads the information retrieval. You spend 10 seconds running a memory query before the first action. If the query surfaces a critical prior decision, you pivot before you invest any effort. If it surfaces nothing relevant, you proceed with confidence that you are not duplicating prior work.

The asymmetry is stark: a query that returns nothing costs 10 seconds. A query that prevents a wrong turn saves hours.

What to Query

The common beginner mistake is querying too narrowly. "What do we know about authentication?" returns results about authentication. But the task might also be affected by:

  • Prior security decisions that constrain the implementation
  • A past failure involving session handling that is adjacent to authentication
  • A team preference about library choices
  • A decision made two months ago about JWT token lifetime

A better query casts a wider net: "authentication, session management, security decisions, library preferences, past failures."

Good query-first practice means querying on:

  1. The core topic of the task
  2. Related technical domains
  3. Past decisions or constraints that might apply
  4. Known failure modes in this area
  5. The specific project or system involved

In a semantic memory layer, a single memory_query call with this multi-concept search returns the top-k semantically relevant chunks from thousands of indexed documents. The right context surfaces within seconds. Agents that run this query at session start arrive at work with the equivalent of months of accumulated experience already loaded.

The Two-Phase Pattern

In practice, query-first means two phases before any action:

Phase 1 — Broad recall. Query the memory store with several related concepts. Skim the results. You are looking for: prior decisions that apply, past failures to avoid, established patterns to follow, or open questions that are already in progress.

Phase 2 — Focused context. If Phase 1 surfaces something directly relevant, do a targeted follow-up: "expand on the Supabase Auth decision from 2026-03 to get the full rationale." Now you have both breadth and depth.

If Phase 1 returns nothing relevant, proceed. You have already done due diligence. If it returns something, you act on it. Both outcomes are good.

Practical Application

Here is a real workflow pattern: an AI coding agent is assigned to add a caching layer to a Python service.

Without the query-first habit, it reaches for Redis (a reasonable default) and starts drafting the implementation. Twenty minutes later, the human reviews the PR and says: "We decided three months ago not to use Redis in this stack due to licensing concerns. We use Valkey. This needs a complete rewrite."

With the query-first habit:

The agent queries memory: "caching, Redis, cache layer, Python service dependencies, infrastructure decisions."

The query returns a stored decision: "Do not use Redis — licensing concerns raised 2026-02-14. Use Valkey as drop-in replacement. Decision approved by Knox."

The agent implements Valkey from the start. No wasted work. No PR rejection. No rewrite.

The query took 3 seconds. The alternative cost 20 minutes of wrong work plus a demoralized PR review.

Encoding This in Agent Prompts

If you are building agents, the query-first step should be explicit in the prompt, not assumed. Something like:

Before beginning any task:
1. Query memory for prior decisions, patterns, and failures related to the task domain.
2. Surface and apply any relevant prior knowledge before writing a single line of code.
3. If a prior decision applies, state it explicitly and follow it.

Without explicit instruction, agents will skip this step. The natural default is to go directly to execution. Build the query step into your agent scaffolding as a hard requirement, not a suggestion.

Common Mistakes

Querying only when stuck. Running a memory query after you have already gone down the wrong path is better than never querying, but it is not the query-first habit. By then, you have already paid the cost of the wrong direction. The value is in querying before any commitment.

Querying with a single narrow term. "authentication" as a query will miss related patterns filed under "security," "session," "OAuth," or "login failure." Cast a wide net with multiple related terms. Memory recall should feel like a broad sweep, not a precise lookup.

Skipping the query on "familiar" tasks. Familiarity is exactly when the habit matters most. Familiar tasks are where you are most likely to have prior decisions, established patterns, or known failure modes stored. The unfamiliar task you approach carefully. The familiar task you approach on autopilot — and that is when you repeat the same mistake you documented last quarter.

Treating query results as definitive. A memory query surfaces what was stored, not the complete truth. If a stored fact is stale or was superseded by a later decision, the query result could mislead. Always treat results as starting context, not final authority — especially if something feels inconsistent with what you know now.

Summary

  • Query first means retrieving relevant prior knowledge before taking any action on a task
  • The asymmetry is decisive: a 10-second query that prevents a 20-minute wrong turn is an obvious trade
  • Query broadly — include related domains, past decisions, failure modes, and project context
  • Use two phases: broad recall first, targeted follow-up when something relevant surfaces
  • Build the query-first step into agent prompts explicitly — agents will skip it otherwise
  • Do not skip queries on familiar tasks; familiarity is where you are most likely to have stored prior experience

What's Next

Query-first gets you the knowledge. But what happens when stored knowledge conflicts — when you stored "X is true" and a new session is telling you "Y is true"? The next lesson covers trust scores and contradiction detection: how to assign confidence to stored facts and what to do when the store and the present disagree.