Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/dominikKos9/AgentForge/llms.txt

Use this file to discover all available pages before exploring further.

SessionMemory is a lightweight in-process store that gives each user session its own isolated history and image cache. It is instantiated once when orchestrator_agent.py is imported and lives for the lifetime of the server process. When the orchestrator receives an image, it first looks up the session record, validates the file, computes a SHA-256 hash, and checks whether that hash already has a cached result — avoiding redundant calls to the vision and speech agents for duplicate uploads.

SessionMemory class

session_memory.py
class SessionMemory:
    def __init__(self):
        self.store = {}

    def get(self, session_id):
        if session_id not in self.store:
            self.store[session_id] = {
                "history": [],
                "cache": {},
                "last_hash": None
            }
        return self.store[session_id]
The store attribute is a plain Python dictionary keyed by session_id. Calling get with a new session ID creates the record automatically, so callers never need to check for existence themselves.

Session record structure

Each value in store is a dictionary with three keys:
KeyTypeDescription
historylistOrdered list of past interactions for this session. Used to give the LLM conversation context.
cachedictMaps SHA-256 hex digests to previously computed {"description": ..., "audio_path": ...} payloads.
last_hashNone | strThe hash of the most recently processed image for this session. Not used for cache lookup — cache is used for that — but available for auditing or display.

Cache lookup in the orchestrator

The orchestrator uses SessionMemory before forwarding state to the vision and speech nodes. If the image hash already exists in the session’s cache dict, it merges the cached payload directly into the state and returns — the LangGraph route function still sees valid_image: True, but because the description and audio path are already populated the result is returned to the caller without running the downstream agents.
orchestrator_agent.py
from backend.tools.image_validator import validate_image
from backend.tools.hash_tool import generate_hash
from backend.memory.session_memory import SessionMemory


memory_store = SessionMemory()


def orchestrator_agent(state):

    path = state["image_path"]
    session_id = state["session_id"]

    memory = memory_store.get(session_id)

    # validate
    is_valid = validate_image(path)
    if not is_valid:
        return {
            **state,
            "valid_image": False,
            "error": "Invalid image"
        }

    # hash
    image_hash = generate_hash(path)

    state["image_hash"] = image_hash

    if image_hash in memory["cache"]:
        cached = memory["cache"][image_hash]

        return {
            **state,
            "valid_image": True,
            **cached,
            "description": cached["description"],
            "audio_path": cached["audio_path"]
        }

    return {
        **state,
        "valid_image": True
    }
When no cache entry exists, the orchestrator returns the state with valid_image: True and no description or audio path, allowing the vision and speech agents to run normally.
SessionMemory is a plain in-process Python object with no persistence layer. All session records, history, and cached results are lost when the server process restarts. If you need durable caching across restarts, replace the store dictionary with a Redis client or a similar external store while keeping the same get interface.
Pass a unique session_id for each distinct user or browser tab. Because SessionMemory.get auto-creates records by key, two sessions with the same ID will share history and cache entries. Generating a UUID per session (for example with Python’s uuid.uuid4()) guarantees isolation without any extra setup.

Build docs developers (and LLMs) love