# Context-Aware Coding: Give AI Agents the Right Context

## Executive summary

Effective AI coding requires providing agents with comprehensive, structured context beyond a simple prompt. The speaker outlines that for an agent to generate correct, idiomatic code, it must understand the entire codebase, including existing patterns, dependency versions, repository structure, and developer intent. The goal is not to dump all information, but to curate the *right* context to guide the agent's decisions.

## Key takeaways

- Context is paramount for AI coding agents: A single prompt is insufficient for complex coding tasks, as the agent must understand the existing codebase, framework, and established patterns (e.g., folder layout, error format).
- Use tests as a feedback loop: Providing the agent with tests allows it to write code, run it, and then attempt to fix and resolve failing tests, ensuring the output meets established quality standards.
- Let the agent ask for missing context: Instead of assuming what the agent needs, instruct it to 'interview' or 'explore' the repository first to surface necessary context, such as architectural assumptions or missing dependencies.
- Curate context, don't overload it: Models perform best with relevant information at the beginning and end of the input. Irrelevant files or excessive context will dilute the agent's attention, making focused context crucial.

## Technical details

- Repository Structure & Codebase Mapping: Agents should be given tools to build a compact 'repo map' (a list of files and symbols) rather than requiring them to read every line of code. Pointing the agent to relevant files (e.g., via a README) helps guide its initial search.
- Dependency Management: It is critical to provide the agent with the dependency version, not just the library name. A 'lock file' (a machine-generated file) records the exact resolved versions of all dependencies, preventing hallucinated functions due to version mismatches.
- Documentation & Intent: Valuable documentation includes conventions, build commands, and explicit constraints (e.g., 'don't touch this directory'). Developer intent—what 'done' looks like—is context the agent cannot discover by reading the repo alone.
- Agent Workflow Strategy: Before coding, the agent should be instructed to 'interview' and 'explore' the repository to build a shared understanding of the project's map. This process should conclude with the agent writing its assumptions into a dedicated file (e.g., `agents.md`).

## Practical implications

- Implement a process to generate and maintain a 'repo map' or symbol list to provide agents with a high-level understanding of the project architecture.
- Ensure that dependency management utilizes lock files to provide the agent with precise, resolved version information.
- Establish a dedicated `agents.md` file to capture and update developer intent, conventions, and build constraints for AI agents to reference.
- Structure coding tasks to start fresh sessions, pointing only to the specific files and modules relevant to the current task, thereby minimizing context noise.

## Topics

AI Agents, Agentic Coding, Software Development Lifecycle, Context Management, Build Systems, IBM Technology YouTube Channel, IBM Developer YouTube Channel

Source: https://www.youtube.com/watch?v=EkdIZXDnRK8
