# pguso/agents-from-scratch architecture

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

- Interactive diagram: https://gitdiagram.com/pguso/agents-from-scratch
- Repository: https://github.com/pguso/agents-from-scratch

## Overview

This repository is an educational, local-first agent built incrementally across 12 lessons. Its central workflow is a user request entering the Agent, which uses a local LLM to generate responses or structured decisions, then may execute a tool or use memory, state, and plans before returning results. The graph also preserves the documented evaluation and telemetry capabilities. Several agent internals are represented by the same source file; unsampled relationships are omitted rather than inferred.

Main entry points: [`agent/agent.py`](https://github.com/pguso/agents-from-scratch/blob/main/agent/agent.py) (Agent), [`complete_example.py`](https://github.com/pguso/agents-from-scratch/blob/main/complete_example.py) (Lesson examples), [`shared/llm.py`](https://github.com/pguso/agents-from-scratch/blob/main/shared/llm.py) (Local LLM), [`agent/planner.py`](https://github.com/pguso/agents-from-scratch/blob/main/agent/planner.py) (Plans and actions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_examples["Examples"]
  node_examples["Lesson examples"]
end

subgraph group_runtime["Agent runtime"]
  node_agent["Agent<br/>[agent.py]"]
  node_decisions["Decisions and outputs<br/>[agent.py]"]
  node_agent_loop["Agent loop<br/>[agent.py]"]
  node_tool_requests["Tool requests<br/>[agent.py]"]
  node_tools["Tool execution<br/>[tools.py]"]
  node_memory["Memory<br/>[memory.py]"]
  node_state["Agent state<br/>[state.py]"]
  node_planning["Plans and actions<br/>[planner.py]"]
end

subgraph group_support["Local support"]
  node_llm["Local LLM<br/>[llm.py]"]
  node_llama_log["Native logging control<br/>[llama_logging.py]"]
  node_json_utils["JSON utilities<br/>[utils.py]"]
end

subgraph group_observability["Observability"]
  node_evals["Agent evaluations<br/>[evals.py]"]
  node_golden_data["Golden datasets<br/>[golden_datasets.py]"]
  node_telemetry["Runtime telemetry<br/>[telemetry.py]"]
end

node_user(("User"))
node_local_model{{"Local model runtime"}}

node_user -->|"runs examples"| node_examples
node_examples -->|"creates and calls"| node_agent
node_agent -->|"handles requests"| node_decisions
node_agent -->|"runs loop"| node_agent_loop
node_agent -->|"requests tools"| node_tool_requests
node_agent -->|"reads and updates"| node_memory
node_agent -->|"updates state"| node_state
node_agent -->|"creates plans"| node_planning
node_agent -->|"generates text"| node_llm
node_llm -->|"runs inference"| node_local_model
node_llm -->|"disables logging"| node_llama_log
node_agent -->|"executes tool calls"| node_tools
node_planning -->|"generates plans"| node_llm
node_planning -->|"parses model output"| node_json_utils
node_agent -->|"parses structured output"| node_json_utils
node_evals -->|"evaluates behavior"| node_agent
node_examples -->|"demonstrates evals"| node_evals
node_examples -->|"logs operations"| node_telemetry
node_examples -->|"uses test cases"| node_golden_data

click node_examples "https://github.com/pguso/agents-from-scratch/blob/main/complete_example.py"
click node_agent "https://github.com/pguso/agents-from-scratch/blob/main/agent/agent.py"
click node_decisions "https://github.com/pguso/agents-from-scratch/blob/main/agent/agent.py"
click node_agent_loop "https://github.com/pguso/agents-from-scratch/blob/main/agent/agent.py"
click node_tool_requests "https://github.com/pguso/agents-from-scratch/blob/main/agent/agent.py"
click node_tools "https://github.com/pguso/agents-from-scratch/blob/main/agent/tools.py"
click node_memory "https://github.com/pguso/agents-from-scratch/blob/main/agent/memory.py"
click node_state "https://github.com/pguso/agents-from-scratch/blob/main/agent/state.py"
click node_planning "https://github.com/pguso/agents-from-scratch/blob/main/agent/planner.py"
click node_llm "https://github.com/pguso/agents-from-scratch/blob/main/shared/llm.py"
click node_llama_log "https://github.com/pguso/agents-from-scratch/blob/main/shared/llama_logging.py"
click node_json_utils "https://github.com/pguso/agents-from-scratch/blob/main/shared/utils.py"
click node_evals "https://github.com/pguso/agents-from-scratch/blob/main/agent/evals.py"
click node_golden_data "https://github.com/pguso/agents-from-scratch/blob/main/evals/golden_datasets.py"
click node_telemetry "https://github.com/pguso/agents-from-scratch/blob/main/agent/telemetry.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_examples,node_user toneBlue
class node_agent,node_decisions,node_agent_loop,node_tool_requests,node_tools,node_memory,node_state,node_planning toneAmber
class node_llm,node_llama_log,node_json_utils toneMint
class node_evals,node_golden_data,node_telemetry toneRose
class node_local_model toneIndigo
```

## Components

### Examples

- [Lesson examples](https://github.com/pguso/agents-from-scratch/blob/main/complete_example.py): `complete_example.py`

### Agent runtime

- [Agent](https://github.com/pguso/agents-from-scratch/blob/main/agent/agent.py): `agent/agent.py`
- [Decisions and outputs](https://github.com/pguso/agents-from-scratch/blob/main/agent/agent.py): `agent/agent.py`
- [Agent loop](https://github.com/pguso/agents-from-scratch/blob/main/agent/agent.py): `agent/agent.py`
- [Tool requests](https://github.com/pguso/agents-from-scratch/blob/main/agent/agent.py): `agent/agent.py`
- [Tool execution](https://github.com/pguso/agents-from-scratch/blob/main/agent/tools.py): `agent/tools.py`
- [Memory](https://github.com/pguso/agents-from-scratch/blob/main/agent/memory.py): `agent/memory.py`
- [Agent state](https://github.com/pguso/agents-from-scratch/blob/main/agent/state.py): `agent/state.py`
- [Plans and actions](https://github.com/pguso/agents-from-scratch/blob/main/agent/planner.py): `agent/planner.py`

### Local support

- [Local LLM](https://github.com/pguso/agents-from-scratch/blob/main/shared/llm.py): `shared/llm.py`
- [Native logging control](https://github.com/pguso/agents-from-scratch/blob/main/shared/llama_logging.py): `shared/llama_logging.py`
- [JSON utilities](https://github.com/pguso/agents-from-scratch/blob/main/shared/utils.py): `shared/utils.py`

### Observability

- [Agent evaluations](https://github.com/pguso/agents-from-scratch/blob/main/agent/evals.py): `agent/evals.py`
- [Golden datasets](https://github.com/pguso/agents-from-scratch/blob/main/evals/golden_datasets.py): `evals/golden_datasets.py`
- [Runtime telemetry](https://github.com/pguso/agents-from-scratch/blob/main/agent/telemetry.py): `agent/telemetry.py`

### Other components

- **User**
- **Local model runtime**

## Connections

- User → Lesson examples: runs examples (evidence: `README.md`)
- Lesson examples → Agent: creates and calls (evidence: `complete_example.py`)
- Agent → Decisions and outputs: handles requests (evidence: `agent/agent.py`)
- Agent → Agent loop: runs loop (evidence: `agent/agent.py`)
- Agent → Tool requests: requests tools (evidence: `agent/agent.py`)
- Agent → Memory: reads and updates (evidence: `agent/agent.py`)
- Agent → Agent state: updates state (evidence: `agent/agent.py`)
- Agent → Plans and actions: creates plans (evidence: `agent/agent.py`)
- Agent → Local LLM: generates text (evidence: `agent/agent.py`)
- Local LLM → Local model runtime: runs inference (evidence: `shared/llm.py`)
- Local LLM → Native logging control: disables logging (evidence: `shared/llm.py`)
- Agent → Tool execution: executes tool calls (evidence: `agent/agent.py`)
- Plans and actions → Local LLM: generates plans (evidence: `agent/planner.py`)
- Plans and actions → JSON utilities: parses model output (evidence: `agent/planner.py`)
- Agent → JSON utilities: parses structured output (evidence: `agent/agent.py`)
- Agent evaluations → Agent: evaluates behavior (evidence: `agent/evals.py`)
- Lesson examples → Agent evaluations: demonstrates evals (evidence: `README.md`)
- Lesson examples → Runtime telemetry: logs operations (evidence: `complete_example.py`)
- Lesson examples → Golden datasets: uses test cases (evidence: `README.md`)
