Skip to content

dspi/agent-zero

Repository files navigation

Agent Zero

A project to learn about creating a memory aware AI agent.

Agent Loop and Memory - the core of the system

The basic loop follows this repeating sequence

  • INPUT handling - User Input
  • Memory RETRIEVAL - SQL/vector databases
  • PROMPT BUILDER - CONTEXT assembly
  • LLM: Local or cloud
  • TOOL USE - decision and execution inner loop (optional)
  • STORE Memory - write-back to databases
  • OUTPUT - User gets the response

A detailed view of the components

---
title: DETAILED AGENT LOOP
config:
  htmlLabels: false
---
flowchart LR

    user(("👤 User"))

    input(["➡️ INPUT"])

    %% MEMORY LAYERS
    sql[("🗄️ SQL Memory
        (user profile, skills)
    ")]
    vector[("🧠 Vector Memory
        (past interactions)
    ")]

    %% RETRIEVAL
    retrieval["🔍 RETRIEVAL
        (hybrid: SQL + vector)
    "]

    %% SHORT TERM MEMORY
    history[("🧾 Short-term History
        (recent messages)
    ")]

    %% CONTROL / STATE
    control[("🎛️ Agent State
        (current situation, intent, mode)
    ")]

    %% PROMPT BUILDER
    prompt["📦 PROMPT BUILDER
        (context assembly)
    "]


    system["📜 System Instructions"]
    toolsDef["🧰 Tool Definitions"]

    %% LLM
    llm["🧠 LLM"]

    %% TOOL USE
    decision{"Use Tool?"}
    tool["🔨 Tool Execution"]

    %% MEMORY WRITE
    store["💾 MEMORY WRITE"]


    %% OUTPUT
    output(["📝 OUTPUT"])

    %% FLOW
    user --> input --> retrieval

    retrieval --> sql
    retrieval --> vector

    retrieval --> prompt
    input --> prompt
    history --> prompt
    control --> prompt
    system --> prompt
    toolsDef --> prompt

    prompt --> llm

    llm --> decision

    decision -->|yes| tool --> llm
    decision -->|no| store

    llm --> store

    store --> sql
    store --> vector
    store --> history

    store --> output
Loading

Prompt Builder

This is where everything comes together:

  • user input
  • retrieved memory (RAG)
  • system instructions
  • agent state
  • tools

Agent State

Structured, short-lived data that controls what the agent is trying to do right now. This prevents the LLM from drifting.

It is NOT:

  • long-term memory (that’s your DBs)
  • the LLM itself
  • just chat history

It IS

  • the current situation
  • intent
  • mode of operation

Two memory types

SQL

  • structured facts
  • skill tracking

Vector

  • semantic recall
  • past conversations

Tool use

  • tools are defined in prompt
  • LLM decides whether to call them
  • system executes them
  • result goes back into LLM

Memory write is centralized

Everything funnels through:

  • one place that decides what to store
  • updates:
    • SQL
    • vector DB
    • short-term history

Agent State vs Memory

Agent State

  • short-lived
  • session-level
  • controls behavior

Memory (SQL/vector)

  • long-term
  • persistent
  • stores facts/history

 

Notes

About

Building an AI agent

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages