# Why AI Coding Tools Hallucinate And Why Context Changes Everything

Source: https://www.youtube.com/watch?v=U9dNQr_cWFU
Recap page: https://rapidrecap.app/video/U9dNQr_cWFU
Generated: 2026-01-13T18:45:42.065+00:00

---
## Quick Overview

AI coding tools hallucinate because they lack sufficient context about the code base, leading to incorrect assumptions or code generation, which is mitigated by providing explicit context like project documentation and using tools like Kiro to manage agent behavior and maintain context across iterations.

**Key Points:**
- AI coding tools hallucinate because they often lack the necessary context from the surrounding codebase, leading to incorrect or nonsensical code generation.
- The presenter demonstrates using Kiro, an agentic IDE, to build a Strands agent that generates dad jokes, initially showing how a lack of context causes hallucinations (00:44, 01:50).
- Kiro addresses context issues using Agent Steering (Markdown files like product.md, structure.md, tech.md) to provide explicit project context automatically (06:31).
- To deploy the second agent (Dad Joke Judge), the presenter configures an AWS Bedrock AgentCore MCP server in Kiro's `mcpServers` configuration (08:43, 09:28).
- The final, successful agent creation involves updating the original agent to call the deployed Judge agent via the `boto3.client('bedrock-agent-runtime')` invoke method, which requires specific payload and response structure knowledge (11:14, 12:11).
- Kiro helps manage this complexity by searching documentation (using MCP tools) for the required API patterns and generating the necessary code structure (11:43, 12:34).

![Screenshot at 00:04: The video title overlay, "Why AI Coding Tools Hallucinate \(And Why Context Changes Everything\)", establishes the core problem discussed: the tendency of generative AI coding assistants to produce incorrect code due to insufficient context.](https://ss.rapidrecap.app/screens/U9dNQr_cWFU/00-00-04.jpg)

**Context:** The video, presented by Jonathan Vogel, Senior Developer Advocate at AWS, explores the common problem of Large Language Model (LLM) based AI coding tools 'hallucinating'—generating code that appears plausible but is functionally incorrect—and demonstrates how providing rich, structured context can prevent this by guiding the AI agent's behavior and knowledge retrieval.

## Detailed Analysis

The video argues that AI coding tools frequently hallucinate because they operate without the full context of the project, leading them to make incorrect assumptions about required dependencies or API structures, as demonstrated when an initial Strands agent created to generate dad jokes produced irrelevant output (01:50). The solution presented is providing explicit context through 'Agent Steering' mechanisms within the Kiro agentic IDE. Kiro automatically analyzes the repository and creates Markdown files (product.md, structure.md, tech.md) detailing the project's purpose, structure, and tech stack, which the agent uses as context (06:31). The presenter then builds a second agent, a 'Dad Joke Judge,' which requires interacting with AWS Bedrock AgentCore. This involves configuring an AWS Bedrock AgentCore MCP server within Kiro's `mcp.json` file (08:43, 09:28). Kiro's tool-calling capability is then used to search the relevant documentation for the specific `boto3.invoke_agent_runtime` method details, including payload format (bytes vs base64) and response structure (11:41). Finally, the original dad joke agent is updated to call the newly deployed judge agent using the retrieved API knowledge, successfully generating jokes and having them rated, proving that providing structured context significantly improves agent reliability (14:43).

### The Problem of Hallucination

- AI coding tools often lack sufficient context, leading to incorrect code generation, exemplified by the initial Strands dad joke agent hallucinating on context (00:00, 01:50).

### Context Management with Kiro

- Kiro uses Agent Steering via Markdown files (product.md, structure.md, tech.md) to explicitly inject project context into the agent's understanding, increasing result reliability (06:31, 06:35).

### Integrating External Services (AWS Bedrock)

- The process requires configuring an MCP Server (AWS Bedrock AgentCore) in `mcp.json` (08:43, 09:28) and using Kiro's tool-calling feature to search documentation for necessary API invocation details (11:41).

### Building the Judge Agent

- A second agent, `dad_joke_judge.py`, is created using BedrockAgentCoreApp patterns, implementing the `boto3.invoke_agent_runtime` call with correct payload encoding and response parsing (12:14, 12:52).

### Successful Integration and Outcome

- After updating the initial agent to call the deployed judge agent via the correct API structure, the system works end-to-end, demonstrating that context-aware tooling leads to reliable, multi-agent system development (14:43, 15:05).

![Screenshot at 00:04: The video title overlay, "Why AI Coding Tools Hallucinate \(And Why Context Changes Everything\)", establishes the core problem discussed: the tendency of generative AI coding assistants to produce incorrect code due to insufficient context.](https://ss.rapidrecap.app/screens/U9dNQr_cWFU/00-00-04.jpg)
![Screenshot at 09:08: The terminal shows Kiro installing Strands Agents dependencies within a Python virtual environment, a necessary step before deploying the AWS AgentCore agent.](https://ss.rapidrecap.app/screens/U9dNQr_cWFU/00-09-08.jpg)
![Screenshot at 11:25: The presenter discusses how the generated code's simplicity \(3 lines for the initial agent\) is a benefit, but context is needed for more complex tasks like multi-agent interaction.](https://ss.rapidrecap.app/screens/U9dNQr_cWFU/00-11-25.jpg)
![Screenshot at 12:14: The screen displays the complex Python code snippet for invoking the deployed Bedrock AgentCore, highlighting the required payload formatting and response structure.](https://ss.rapidrecap.app/screens/U9dNQr_cWFU/00-12-14.jpg)
![Screenshot at 14:43: The terminal shows the successful execution of the second agent, dad\_joke\_judge.py, which now generates a joke and passes it to the deployed judge agent for rating.](https://ss.rapidrecap.app/screens/U9dNQr_cWFU/00-14-43.jpg)
