# srm-repo/sample-why-agents-fail architecture

> Architecture diagram of the GitHub repository srm-repo/sample-why-agents-fail, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/srm-repo/sample-why-agents-fail
- Repository: https://github.com/srm-repo/sample-why-agents-fail

## Overview

This repository is a collection of executable learning demos for preventing AI-agent hallucinations and wasted tokens, rather than one integrated application. The principal workflow is a user query entering a demo agent, which applies a targeted retrieval, tool-selection, validation, context-management, timeout, or loop-control technique before producing a response or report. The graph preserves the README’s major demo branches; several relationships are documented at demo level, while unsampled implementation details are not inferred.

Main entry points: [`stop-ai-agent-hallucinations/01-faq-graphrag-demo/travel_agent_demo.py`](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/01-faq-graphrag-demo/travel_agent_demo.py) (FAQ travel agent), [`stop-ai-agent-hallucinations/02-semantic-tools-demo/token_comparison_app.py`](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/02-semantic-tools-demo/token_comparison_app.py) (Tool selection comparison), [`stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/chat_guarded.py`](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/chat_guarded.py) (Guarded loop chat), [`stop-ai-agents-wasting-tokens/01-context-overflow-demo/chat_pointer.py`](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/01-context-overflow-demo/chat_pointer.py) (Memory pointer chat)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_hallucination["Hallucination Controls"]
  node_faq_agent["FAQ travel agent"]
  node_faq_graph[("FAQ knowledge graph<br/>[build_graph.py]")]
  node_faq_vectors[("FAQ vector retrieval")]
  node_tool_app["Tool selection comparison"]
  node_tool_registry["Semantic tool registry<br/>[registry.py]"]
  node_travel_tools["Travel tool catalog<br/>[enhanced_tools.py]"]
  node_validation_tools["Booking validation tools<br/>[tools.py]"]
  node_symbolic_rules["Symbolic business rules<br/>[rules.py]"]
  node_agent_controls["Agent controls<br/>[setup_controls.py]"]
end

subgraph group_context["Context Management"]
  node_conversation["Conversation managers<br/>[chat.py]"]
  node_pointer_chat["Memory pointer chat<br/>[chat_pointer.py]"]
  node_pointer_tools["Pointer analysis tools<br/>[tools.py]"]
  node_swarm["Log analysis swarm<br/>[swarm_demo.py]"]
  node_swarm_tools["Shared-state tools<br/>[tools.py]"]
end

subgraph group_timeouts["MCP Timeouts"]
  node_async_chat["Async timeout chat<br/>[chat_async.py]"]
  node_sync_chat["Sync timeout chat<br/>[chat_sync.py]"]
  node_mcp_server["MCP demo server<br/>[mcp_server.py]"]
end

subgraph group_loops["Reasoning Loops"]
  node_loop_chat["Unprotected loop chat<br/>[chat_loop.py]"]
  node_guarded_chat["Guarded loop chat<br/>[chat_guarded.py]"]
  node_loop_tools["Travel retry tools<br/>[tools.py]"]
  node_loop_hooks["Tool call limits<br/>[hooks.py]"]
end

subgraph group_production["Production Examples"]
  node_booking_agent["Production booking agent<br/>[booking_agent.py]"]
end

node_learner(("Demo user"))
node_model{{"LLM provider"}}

node_learner -->|"asks FAQ"| node_faq_agent
node_faq_agent -->|"uses Graph-RAG"| node_faq_graph
node_faq_agent -->|"compares RAG"| node_faq_vectors
node_faq_agent -->|"reasons with"| node_model
node_learner -->|"asks travel query"| node_tool_app
node_tool_app -->|"selects tools"| node_tool_registry
node_tool_app -->|"loads tools"| node_travel_tools
node_tool_registry -->|"indexes tools"| node_travel_tools
node_tool_app -->|"runs queries"| node_model
node_learner -->|"requests booking"| node_validation_tools
node_learner -->|"tests rules"| node_symbolic_rules
node_learner -->|"explores controls"| node_agent_controls
node_learner -->|"asks recall question"| node_conversation
node_learner -->|"asks log question"| node_pointer_chat
node_pointer_chat -->|"registers tools"| node_pointer_tools
node_pointer_chat -->|"runs agent"| node_model
node_learner -->|"requests report"| node_swarm
node_swarm -->|"uses tools"| node_swarm_tools
node_swarm -->|"runs agents"| node_model
node_learner -->|"asks async agent"| node_async_chat
node_learner -->|"asks sync agent"| node_sync_chat
node_async_chat -.->|"uses MCP"| node_mcp_server
node_sync_chat -.->|"uses MCP"| node_mcp_server
node_learner -->|"asks travel query"| node_loop_chat
node_loop_chat -->|"calls tools"| node_loop_tools
node_loop_chat -->|"runs agent"| node_model
node_learner -->|"asks travel query"| node_guarded_chat
node_guarded_chat -->|"calls tools"| node_loop_tools
node_guarded_chat -->|"attaches limits"| node_loop_hooks
node_guarded_chat -->|"runs agent"| node_model
node_learner -->|"explores deployment"| node_booking_agent

click node_faq_agent "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/01-faq-graphrag-demo/travel_agent_demo.py"
click node_faq_graph "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/01-faq-graphrag-demo/build_graph.py"
click node_faq_vectors "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/01-faq-graphrag-demo/load_vector_data.py"
click node_tool_app "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/02-semantic-tools-demo/token_comparison_app.py"
click node_tool_registry "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/02-semantic-tools-demo/registry.py"
click node_travel_tools "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/02-semantic-tools-demo/enhanced_tools.py"
click node_validation_tools "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/03-multiagent-demo/tools.py"
click node_symbolic_rules "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/04-neurosymbolic-demo/rules.py"
click node_agent_controls "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/05-agent-control-demo/setup_controls.py"
click node_conversation "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/00-conversation-management-demo/chat.py"
click node_pointer_chat "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/01-context-overflow-demo/chat_pointer.py"
click node_pointer_tools "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/01-context-overflow-demo/tools.py"
click node_swarm "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/01-context-overflow-demo/swarm_demo.py"
click node_swarm_tools "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/01-context-overflow-demo/tools.py"
click node_async_chat "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/02-mcp-timeout-demo/chat_async.py"
click node_sync_chat "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/02-mcp-timeout-demo/chat_sync.py"
click node_mcp_server "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/02-mcp-timeout-demo/mcp_server.py"
click node_loop_chat "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/chat_loop.py"
click node_guarded_chat "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/chat_guarded.py"
click node_loop_tools "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/tools.py"
click node_loop_hooks "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/hooks.py"
click node_booking_agent "https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/06-agentcore-production-demo/agent_files/booking_agent.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_faq_agent,node_faq_graph,node_faq_vectors,node_tool_app,node_tool_registry,node_travel_tools,node_validation_tools,node_symbolic_rules,node_agent_controls,node_learner toneBlue
class node_conversation,node_pointer_chat,node_pointer_tools,node_swarm,node_swarm_tools toneAmber
class node_async_chat,node_sync_chat,node_mcp_server toneMint
class node_loop_chat,node_guarded_chat,node_loop_tools,node_loop_hooks toneRose
class node_booking_agent,node_model toneIndigo
```

## Components

### Hallucination Controls

- [FAQ travel agent](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/01-faq-graphrag-demo/travel_agent_demo.py): `stop-ai-agent-hallucinations/01-faq-graphrag-demo/travel_agent_demo.py`
- [FAQ knowledge graph](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/01-faq-graphrag-demo/build_graph.py): `stop-ai-agent-hallucinations/01-faq-graphrag-demo/build_graph.py`
- [FAQ vector retrieval](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/01-faq-graphrag-demo/load_vector_data.py): `stop-ai-agent-hallucinations/01-faq-graphrag-demo/load_vector_data.py`
- [Tool selection comparison](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/02-semantic-tools-demo/token_comparison_app.py): `stop-ai-agent-hallucinations/02-semantic-tools-demo/token_comparison_app.py`
- [Semantic tool registry](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/02-semantic-tools-demo/registry.py): `stop-ai-agent-hallucinations/02-semantic-tools-demo/registry.py`
- [Travel tool catalog](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/02-semantic-tools-demo/enhanced_tools.py): `stop-ai-agent-hallucinations/02-semantic-tools-demo/enhanced_tools.py`
- [Booking validation tools](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/03-multiagent-demo/tools.py): `stop-ai-agent-hallucinations/03-multiagent-demo/tools.py`
- [Symbolic business rules](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/04-neurosymbolic-demo/rules.py): `stop-ai-agent-hallucinations/04-neurosymbolic-demo/rules.py`
- [Agent controls](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/05-agent-control-demo/setup_controls.py): `stop-ai-agent-hallucinations/05-agent-control-demo/setup_controls.py`

### Context Management

- [Conversation managers](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/00-conversation-management-demo/chat.py): `stop-ai-agents-wasting-tokens/00-conversation-management-demo/chat.py`
- [Memory pointer chat](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/01-context-overflow-demo/chat_pointer.py): `stop-ai-agents-wasting-tokens/01-context-overflow-demo/chat_pointer.py`
- [Pointer analysis tools](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/01-context-overflow-demo/tools.py): `stop-ai-agents-wasting-tokens/01-context-overflow-demo/tools.py`
- [Log analysis swarm](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/01-context-overflow-demo/swarm_demo.py): `stop-ai-agents-wasting-tokens/01-context-overflow-demo/swarm_demo.py`
- [Shared-state tools](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/01-context-overflow-demo/tools.py): `stop-ai-agents-wasting-tokens/01-context-overflow-demo/tools.py`

### MCP Timeouts

- [Async timeout chat](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/02-mcp-timeout-demo/chat_async.py): `stop-ai-agents-wasting-tokens/02-mcp-timeout-demo/chat_async.py`
- [Sync timeout chat](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/02-mcp-timeout-demo/chat_sync.py): `stop-ai-agents-wasting-tokens/02-mcp-timeout-demo/chat_sync.py`
- [MCP demo server](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/02-mcp-timeout-demo/mcp_server.py): `stop-ai-agents-wasting-tokens/02-mcp-timeout-demo/mcp_server.py`

### Reasoning Loops

- [Unprotected loop chat](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/chat_loop.py): `stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/chat_loop.py`
- [Guarded loop chat](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/chat_guarded.py): `stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/chat_guarded.py`
- [Travel retry tools](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/tools.py): `stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/tools.py`
- [Tool call limits](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/hooks.py): `stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/hooks.py`

### Production Examples

- [Production booking agent](https://github.com/srm-repo/sample-why-agents-fail/blob/main/stop-ai-agent-hallucinations/06-agentcore-production-demo/agent_files/booking_agent.py): `stop-ai-agent-hallucinations/06-agentcore-production-demo/agent_files/booking_agent.py`

### Other components

- **Demo user**
- **LLM provider**

## Connections

- Demo user → FAQ travel agent: asks FAQ (evidence: `README.md`)
- FAQ travel agent → FAQ knowledge graph: uses Graph-RAG (evidence: `README.md`)
- FAQ travel agent → FAQ vector retrieval: compares RAG (evidence: `README.md`)
- FAQ travel agent → LLM provider: reasons with (evidence: `README.md`)
- Demo user → Tool selection comparison: asks travel query (evidence: `README.md`)
- Tool selection comparison → Semantic tool registry: selects tools (evidence: `stop-ai-agent-hallucinations/02-semantic-tools-demo/token_comparison_app.py`)
- Tool selection comparison → Travel tool catalog: loads tools (evidence: `stop-ai-agent-hallucinations/02-semantic-tools-demo/token_comparison_app.py`)
- Semantic tool registry → Travel tool catalog: indexes tools (evidence: `stop-ai-agent-hallucinations/02-semantic-tools-demo/token_comparison_app.py`)
- Tool selection comparison → LLM provider: runs queries (evidence: `stop-ai-agent-hallucinations/02-semantic-tools-demo/token_comparison_app.py`)
- Demo user → Booking validation tools: requests booking (evidence: `README.md`)
- Demo user → Symbolic business rules: tests rules (evidence: `README.md`)
- Demo user → Agent controls: explores controls (evidence: `README.md`)
- Demo user → Conversation managers: asks recall question (evidence: `README.md`)
- Demo user → Memory pointer chat: asks log question (evidence: `stop-ai-agents-wasting-tokens/01-context-overflow-demo/chat_pointer.py`)
- Memory pointer chat → Pointer analysis tools: registers tools (evidence: `stop-ai-agents-wasting-tokens/01-context-overflow-demo/chat_pointer.py`)
- Memory pointer chat → LLM provider: runs agent (evidence: `stop-ai-agents-wasting-tokens/01-context-overflow-demo/chat_pointer.py`)
- Demo user → Log analysis swarm: requests report (evidence: `README.md`)
- Log analysis swarm → Shared-state tools: uses tools (evidence: `stop-ai-agents-wasting-tokens/01-context-overflow-demo/swarm_demo.py`)
- Log analysis swarm → LLM provider: runs agents (evidence: `stop-ai-agents-wasting-tokens/01-context-overflow-demo/swarm_demo.py`)
- Demo user → Async timeout chat: asks async agent (evidence: `README.md`)
- Demo user → Sync timeout chat: asks sync agent (evidence: `README.md`)
- Async timeout chat → MCP demo server: uses MCP
- Sync timeout chat → MCP demo server: uses MCP
- Demo user → Unprotected loop chat: asks travel query (evidence: `stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/chat_loop.py`)
- Unprotected loop chat → Travel retry tools: calls tools (evidence: `stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/chat_loop.py`)
- Unprotected loop chat → LLM provider: runs agent (evidence: `stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/chat_loop.py`)
- Demo user → Guarded loop chat: asks travel query (evidence: `stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/chat_guarded.py`)
- Guarded loop chat → Travel retry tools: calls tools (evidence: `stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/chat_guarded.py`)
- Guarded loop chat → Tool call limits: attaches limits (evidence: `stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/chat_guarded.py`)
- Guarded loop chat → LLM provider: runs agent (evidence: `stop-ai-agents-wasting-tokens/03-reasoning-loops-demo/chat_guarded.py`)
- Demo user → Production booking agent: explores deployment (evidence: `README.md`)
