Inferensys

Prompt

Repository Summary Generation Prompt for Agent Memory

A practical prompt playbook for generating dense, token-efficient repository summaries that enable coding agents to perform accurate downstream tasks within limited context windows.
Developer reviewing multi-agent chat interface on laptop, agent conversation logs visible, casual coding session at WeWork desk.
PROMPT PLAYBOOK

When to Use This Prompt

Define the job, reader, and constraints for the Repository Summary Generation Prompt for Agent Memory.

This prompt is for AI coding agents that operate within a limited context window and need a compressed, high-signal overview of a repository before executing a task. The primary job-to-be-done is to produce a dense, structured summary covering the architecture, tech stack, key modules, and conventions of a codebase so that a downstream agent can make accurate decisions without loading every file into its working memory. The ideal user is an AI engineer or platform developer building a coding agent harness where context budgets are tight—typically under 128k tokens—and where every token spent on orientation must earn its place through downstream task accuracy.

Use this prompt when an agent first enters a repository, when it needs to refresh its understanding after a significant number of changes, or when a new sub-agent is spawned to handle a specific domain within a monorepo. The required inputs include a structured file inventory, key configuration files, a dependency manifest, and a directory tree. The prompt is not a replacement for targeted file retrieval during task execution; it is a pre-computed or just-in-time memory artifact. Do not use this prompt when the agent already has a fresh, task-specific context assembled, or when the repository is small enough to fit entirely in the context window without compression.

The prompt is designed to be paired with a validation harness that checks the summary against a set of downstream task-completion metrics. If the summary omits a critical module, misidentifies the primary language, or hallucinates a build command, the agent will fail silently on subsequent steps. Before relying on this prompt in production, run it against a golden set of repositories where you know the correct answers for architecture, entry points, and conventions. Measure whether agents using the summary complete representative tasks—such as adding a feature, fixing a bug, or writing a test—at an acceptable accuracy rate. If accuracy drops, the summary is either too compressed or contains errors that must be caught by the harness before the summary is committed to agent memory.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Repository Summary Generation Prompt delivers value and where it introduces risk. Use these cards to decide if this prompt fits your agent architecture before wiring it into a context assembly pipeline.

01

Good Fit: Context Window Compression

Use when: your coding agent has a limited context window and needs a dense, structured overview of a repository before performing multi-file tasks. Guardrail: set an explicit token budget for the summary and verify that downstream task accuracy does not degrade compared to providing raw file contents.

02

Bad Fit: Single-File Edits

Avoid when: the agent only needs to read and edit one known file. A full repository summary adds latency and consumes context tokens without improving task performance. Guardrail: gate summary generation behind a repository novelty check—only generate when the agent enters an unfamiliar codebase.

03

Required Inputs

What you need: a file listing with paths, key config files parsed for framework and language hints, top-level directory structure, and build system indicators. Guardrail: validate that the input inventory covers at least 90% of non-generated, non-vendor source files before generating the summary. Missing inputs produce hallucinated architecture.

04

Operational Risk: Stale Summaries

What to watch: summaries generated once and reused across many tasks become stale as the codebase changes. The agent acts on outdated architecture assumptions. Guardrail: attach a generation timestamp and git commit hash to every summary. Invalidate and regenerate when the HEAD commit changes or after a configurable TTL.

05

Operational Risk: Hallucinated Modules

What to watch: the model invents plausible-sounding modules, conventions, or dependencies that do not exist in the actual codebase. Guardrail: require every module claim in the summary to cite at least one source file path. Run a post-generation verification step that checks cited paths exist in the repository tree.

06

Operational Risk: Token Budget Overrun

What to watch: the generated summary exceeds the allocated token budget, leaving insufficient room for task instructions, tool outputs, and conversation history. Guardrail: enforce a hard token limit on summary output using model-level max_tokens or a post-generation truncation step. Log budget utilization per task for monitoring.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A reusable prompt template with square-bracket placeholders for generating a dense, token-efficient repository summary suitable for agent memory.

The following prompt template is designed to produce a compressed, structured overview of a codebase that an AI coding agent can store in its working memory. It forces the model to prioritize architectural patterns, key modules, and critical conventions over exhaustive file listings, making it suitable for agents with tight context windows. The template uses square-bracket placeholders that you must replace with concrete values from your agent's discovery phase before execution.

text
You are an expert software architect creating a dense, high-signal summary of a codebase for an AI coding agent with a limited context window. Your summary will be the agent's primary memory of the repository. It must be accurate, concise, and structured for rapid retrieval.

## Repository Context
- Repository Path: [REPO_ROOT]
- Primary Language(s): [LANGUAGES]
- Build System(s): [BUILD_SYSTEMS]
- Framework(s): [FRAMEWORKS]

## Input Data
You are provided with the following pre-assembled context from the repository exploration phase:
- A directory tree of the top [MAX_DEPTH] levels: [DIRECTORY_TREE]
- Key configuration file contents: [CONFIG_FILES]
- A list of discovered entry points: [ENTRY_POINTS]
- A dependency graph summary: [DEPENDENCY_SUMMARY]
- A symbol index of major public interfaces: [SYMBOL_INDEX]

## Output Schema
Produce a JSON object conforming to this exact structure:
{
  "architecture_overview": "A single paragraph describing the high-level architecture, main components, and data flow.",
  "tech_stack": {
    "languages": ["string"],
    "frameworks": ["string"],
    "databases": ["string"],
    "message_brokers": ["string"],
    "key_libraries": ["string"]
  },
  "top_level_modules": [
    {
      "name": "string",
      "path": "string",
      "responsibility": "string",
      "public_interfaces": ["string"]
    }
  ],
  "critical_conventions": {
    "naming": "string",
    "error_handling": "string",
    "testing": "string",
    "dependency_injection": "string"
  },
  "entry_points": [
    {
      "type": "http_server | cli | worker | cron",
      "file": "string",
      "description": "string"
    }
  ],
  "anti_patterns_and_risks": ["string"],
  "agent_guidance": "A paragraph with specific advice for an AI coding agent working in this codebase, including files to avoid modifying, required review processes, and common pitfalls."
}

## Constraints
- The entire output must not exceed [MAX_OUTPUT_TOKENS] tokens.
- Prioritize information that would be most useful for an agent planning a code change.
- If you are uncertain about a field, mark it explicitly with "UNCERTAIN: <your best guess>" rather than omitting it.
- Do not invent libraries, frameworks, or modules not present in the input data.
- For the `agent_guidance` field, be specific and actionable. Avoid generic advice like "follow best practices."

To adapt this template for your agent harness, replace the placeholders with values gathered during the repository exploration phase. The [DIRECTORY_TREE], [CONFIG_FILES], [ENTRY_POINTS], [DEPENDENCY_SUMMARY], and [SYMBOL_INDEX] placeholders should be populated by upstream tool calls—such as list_files, read_file, and search_symbols—before this prompt is assembled. Set [MAX_OUTPUT_TOKENS] based on your agent's remaining context budget after accounting for system prompts and other memory. A typical value is 1500-2500 tokens. If your agent uses a model with strong JSON mode, append a final instruction to enforce the schema strictly; otherwise, include a retry harness that validates the JSON structure and requests corrections for missing or malformed fields.

IMPLEMENTATION TABLE

Prompt Variables

Required inputs for the Repository Summary Generation Prompt. Each variable must be populated before the prompt is assembled and sent. Missing or malformed inputs are the most common cause of incomplete or hallucinated summaries.

PlaceholderPurposeExampleValidation Notes

[REPO_NAME]

Identifies the repository being summarized; used to scope the summary and prevent cross-repo contamination.

inference-systems/api-harness

Must be a non-empty string. Validate against the actual repository origin from the agent's workspace metadata. Reject if it does not match the checked-out repository.

[FILE_LIST]

Provides the agent with a flat list of all non-ignored file paths in the repository. This is the primary evidence source for the summary.

src/index.ts src/routes/auth.ts tests/auth.test.ts package.json Dockerfile

Must be a newline-separated list of relative paths. Validate that the count is non-zero and that no paths match .gitignore patterns. Truncate with a note if the list exceeds 5000 entries to avoid context overflow.

[DEPENDENCY_MANIFEST]

Contains the parsed contents of package.json, Cargo.toml, go.mod, or equivalent. Drives the tech stack and framework detection.

{"dependencies": {"express": "^4.18.0", "typescript": "^5.3.0"}, "devDependencies": {...}}

Must be valid JSON or TOML as a string. Validate parseability before prompt assembly. If the repository has multiple manifests, concatenate with file-path headers. Null allowed only if no manifest exists.

[DIRECTORY_TREE]

Provides a depth-limited tree view of the top-level directory structure for architecture inference.

src/ routes/ middleware/ services/ tests/ unit/ integration/ docs/

Must be a string with indentation representing hierarchy. Validate that depth does not exceed 3 levels to stay within token budget. Generate from [FILE_LIST] using a tree utility; do not accept hand-written trees.

[README_CONTENT]

Supplies the raw text of the repository's README file for purpose and convention extraction.

API Harness

A lightweight API testing framework...

Getting Started

...

Must be a string. Validate that the file exists and is non-empty. If no README is found, set to null and add a flag to the harness that the summary will have lower confidence on purpose and conventions.

[TOKEN_BUDGET]

Defines the maximum token count for the generated summary. The prompt must compress the output to fit within this limit.

2048

Must be a positive integer. Validate that the value is between 512 and 8192. The harness must enforce this budget by truncating the summary and appending a truncation notice if the model exceeds it.

[OUTPUT_SCHEMA]

Specifies the exact JSON schema the summary must conform to, including required fields for architecture, tech stack, modules, and conventions.

{"type": "object", "required": ["architecture", "tech_stack", "modules", "conventions"], "properties": {...}}

Must be a valid JSON Schema object. Validate parseability and that required fields include at minimum: architecture, tech_stack, key_modules, and conventions. Reject schemas that allow empty required arrays.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the repository summary prompt into an agent's memory pipeline with validation, token budgeting, and retry logic.

The repository summary prompt is not a one-off query; it is a memory injection step that runs before task execution and after repository discovery. The harness must call this prompt when the agent's context window is too small to hold the full codebase map, typically after the initial scan and symbol indexing steps have completed. The prompt consumes a structured inventory of files, directories, and key symbols and compresses it into a dense summary that fits within a predefined token budget. The output becomes part of the agent's persistent working memory for the session, so the harness must store it, version it, and invalidate it when the repository state changes.

Wire the prompt into a pipeline with these stages: input assembly, token budget enforcement, model invocation, output validation, and memory injection. For input assembly, collect the outputs from upstream discovery prompts—directory tree, entry points, build system, language map, and dependency graph—and serialize them into a single structured [CODEBASE_INVENTORY] block. Truncate or summarize the inventory if it exceeds the model's context limit before adding the prompt template. Set a hard [TOKEN_BUDGET] constraint in the prompt (e.g., 2000 tokens) and enforce it post-generation by counting tokens and rejecting summaries that exceed the budget. Use a mid-tier model like GPT-4o or Claude 3.5 Sonnet for this task; smaller models often omit critical architectural details when forced to compress. Implement a retry loop with a stricter budget on failure: if the first attempt exceeds the budget, retry with a 20% lower token limit and an explicit instruction to cut redundant descriptions. Log every attempt, the token count, and the validation result for debugging compression failures.

Validation must check three things before the summary enters agent memory. First, completeness: verify that the summary mentions every top-level directory and build system identified in the discovery phase. A simple keyword match against directory names catches most omissions. Second, hallucination: check that every file path, module name, and technology claim in the summary appears in the source inventory. Flag any invented paths or frameworks for human review. Third, downstream task accuracy: run a lightweight eval where the agent, armed only with the summary, must answer a set of pre-written questions about the codebase (e.g., 'Where are tests located?' or 'What is the primary language?'). If accuracy drops below 90%, the summary is too lossy and needs regeneration with a higher token budget or a different compression strategy. For high-risk repositories where incorrect architecture understanding could cause destructive edits, require human approval of the summary before the agent proceeds to any file modification tasks. Store the approved summary alongside the session ID and git commit hash so future debugging can correlate agent behavior with its compressed worldview.

IMPLEMENTATION TABLE

Expected Output Contract

Fields, types, and validation rules for the repository summary object. Use this contract to build a parser that rejects incomplete or malformed summaries before they enter agent memory.

Field or ElementType or FormatRequiredValidation Rule

summary.architecture_overview

string (max 500 chars)

Must contain at least one architectural pattern keyword (e.g., monolith, microservices, layered, event-driven). Reject if empty or purely generic.

summary.tech_stack

array of objects

Each object must have 'language' or 'framework' key with a non-empty string value. Array length must be >= 1. Reject if any entry has both keys null.

summary.key_modules

array of objects

Each object requires 'name' (string), 'path' (string), and 'responsibility' (string). 'path' must match an actual directory from the discovery scan. Reject if any module path is not found in the provided [FILE_TREE] input.

summary.entry_points

array of strings

Each string must be a relative file path. At least one entry must match a known entry-point pattern (main.go, index.js, app.py, etc.). Reject if array is empty or all paths fail pattern match.

summary.conventions

array of objects

If present, each object requires 'category' (naming, testing, imports, config) and 'rule' (string). Null allowed for entire field. Reject if 'category' value is not from the allowed enum.

summary.external_dependencies

array of strings

Each string must be a package name or service identifier. Cross-check against [DEPENDENCY_LIST] if provided. Reject if array contains only generic terms like 'database' or 'api' without specific names.

summary.known_risks

array of strings

If present, each string must describe a specific risk (e.g., 'circular dependency between auth and user modules'). Reject entries that are vague (e.g., 'some issues'). Null allowed for entire field.

summary.token_count_estimate

integer

Must be a positive integer. Validate that the value is <= [MAX_TOKEN_BUDGET]. Reject if 0 or negative. Warn if estimate exceeds 80% of budget before insertion into agent memory.

PRACTICAL GUARDRAILS

Common Failure Modes

Repository summaries are high-stakes compression. When they fail, downstream agent tasks fail silently. Here are the most common failure modes and how to guard against them.

01

Hallucinated Modules and Dependencies

What to watch: The model invents plausible-sounding directories, frameworks, or libraries that don't exist in the repository. This is especially common when the repo uses less popular packages or internal forks. Guardrail: Require the harness to cross-reference every module and dependency claim against the actual file tree and package manifest. Flag any summary entry that cannot be traced to a real file path or lockfile entry.

02

Token Budget Overrun on Large Repos

What to watch: The model either truncates the summary mid-structure or omits critical modules because the repository is too large for a single pass. The summary looks complete but is missing entire subsystems. Guardrail: Implement a pre-flight token estimator. If the repo exceeds the budget, chunk by top-level directory and generate per-chunk summaries, then merge with a second pass. Validate that every top-level source directory appears in the final output.

03

Stale Summary Drift After Code Changes

What to watch: The agent relies on a cached summary generated hours or days earlier. New commits have added modules, changed the tech stack, or removed deprecated code. The agent plans edits against a ghost. Guardrail: Attach a git commit hash to every generated summary. Before any downstream task, compare the current HEAD against the summary's commit hash. If they differ, regenerate or flag the drift. Never let an agent act on a summary with a mismatched hash.

04

Conflating Application Code with Vendored or Generated Code

What to watch: The summary treats node_modules, vendor/, __pycache__, or generated protobuf stubs as first-class modules. The agent wastes context budget reasoning about code the team doesn't maintain. Guardrail: Pre-filter the file tree to exclude known vendor, build output, and generated directories before summarization. Use .gitignore patterns as a starting filter. Validate that no summary entry points into an excluded directory.

05

Missing Implicit Conventions and Unwritten Rules

What to watch: The summary captures what's in the code but misses team conventions that aren't codified: naming patterns, preferred error-handling style, or unwritten PR norms. The agent follows the summary literally and produces code that violates team expectations. Guardrail: Supplement the structural summary with a conventions extraction pass that scans for repeated patterns (e.g., consistent error wrapping, logging format, test structure). Flag when the summary lacks a conventions section and prompt the harness to run the extraction step.

06

Incorrect Tech Stack Inference from Ambiguous Files

What to watch: A Dockerfile references multiple languages, a Makefile invokes several build tools, or a monorepo contains sub-projects in different frameworks. The model picks the wrong primary stack or reports a confusing mix. Guardrail: Require the summary to distinguish between primary application stack, build-time tooling, and deployment infrastructure. Validate that the primary language claim matches the language with the highest source-line count. Flag ambiguous repos for human review before agent task execution.

IMPLEMENTATION TABLE

Evaluation Rubric

Criteria for testing whether a repository summary prompt produces output that enables accurate downstream task completion without exceeding the [MAX_OUTPUT_TOKENS] budget. Use this rubric to evaluate summary quality before integrating the prompt into an agent memory pipeline.

CriterionPass StandardFailure SignalTest Method

Token Budget Compliance

Output token count is less than or equal to [MAX_OUTPUT_TOKENS] for all test repositories

Output exceeds [MAX_OUTPUT_TOKENS] by more than 5% on any test repo

Run prompt against 3 test repos of varying sizes; count tokens with tiktoken or equivalent; flag any over-budget output

Architecture Accuracy

Summary correctly identifies the top-level architecture pattern (monolith, microservices, monorepo, plugin system) for all test repos

Summary misclassifies architecture pattern or omits it entirely

Compare summary architecture claim against a manually labeled ground-truth label for each test repo; require exact match

Tech Stack Completeness

Summary lists all primary languages, frameworks, and databases present in the repo with at least 90% recall against a manual inventory

Summary misses 2 or more primary stack components or hallucinates a component not present

Generate a manual tech stack inventory for each test repo; compute recall of summary items against inventory; flag if recall below 0.9

Key Module Coverage

Summary identifies at least 80% of the top-level source directories and their inferred responsibilities

Summary omits more than 20% of top-level source directories or assigns a clearly wrong responsibility to a module

Extract top-level source dirs from repo; compare summary module list; compute coverage ratio; spot-check 3 module descriptions for correctness

Convention Extraction

Summary captures at least one naming convention, one file organization pattern, and one testing convention when present in the repo

Summary states no conventions when conventions are clearly present, or fabricates a convention not found in the repo

Manually annotate conventions present in each test repo; check summary for at least one match per category; flag fabricated conventions via grep negation

Downstream Task Enablement

A developer given only the summary can correctly answer 4 out of 5 factual questions about the repo structure and stack

Developer answers fewer than 3 out of 5 questions correctly using only the summary

Prepare 5 factual questions per test repo; give summary to a developer unfamiliar with the repo; score correct answers; require score of 4+

Hallucination Rate

Zero fabricated file paths, library names, or configuration values across all test summaries

Summary contains any file path, library name, or config value not present in the repo

Grep summary output for file paths, library names, and config keys; cross-reference against repo file tree and dependency manifests; flag any mismatch

Compression Ratio

Summary token count is at most 10% of the total token count of all source files in the repo

Summary exceeds 15% of source token count, indicating insufficient compression

Compute total token count of all non-generated, non-vendor source files; divide summary tokens by source tokens; flag if ratio exceeds 0.15

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Use the base prompt with a generous token budget and manual review of the summary. Replace [TOKEN_BUDGET] with a fixed number like 2000. Skip the downstream-task validation step and instead spot-check 3 summaries for architecture accuracy.

Watch for

  • Summaries that omit the tech stack or primary language
  • Overly verbose module descriptions that waste token budget
  • Hallucinated dependencies not present in package manifests
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.