Memory

Veska has two types of memory: Agent Memory (private to each agent) and Shared Memory (accessible by all agents). Both persist across conversations with pluggable backends.

Agent Memory

Each agent has its own private memory with categorized entries:

agent_memory.py
# Agent memory is automatic — the agent stores facts as it works
agent.memory.add("user_preference", "dark mode", category="general")
agent.memory.add_decision("Use PostgreSQL for the database")
agent.memory.add_file("/src/app.py", "Main application entry point")
agent.memory.add_task("task_123", "Completed research on AI agents")
agent.memory.add_error("API timeout on first attempt")

# Query memory
all_entries = agent.memory.get_all()
decisions = agent.memory.get_decisions()
files = agent.memory.get_files()           # {path: description}
tasks = agent.memory.get_tasks()           # {task_id: result}
errors = agent.memory.get_errors()
recent = agent.memory.get_recent(count=5)

# Get a compressed summary (for injection into context)
summary = agent.memory.get_summary()

Memory categories: decisions, files, tasks, errors, connections, general

Shared Memory

The Orchestrator manages shared memory that all agents can access:

shared.py
# The orchestrator's shared memory
orchestrator.shared_memory.store(agent.memory)
orchestrator.shared_memory.get("researcher")
orchestrator.shared_memory.get_summary("researcher")

# Share knowledge between agents
orchestrator.shared_memory.share("researcher", "writer", category="files")

# Get an overview of all agents' memories
overview = orchestrator.shared_memory.get_overview()
all_ids = orchestrator.shared_memory.get_all_agent_ids()

Persistent backends

By default, memory is in-memory only. Use a backend to persist across restarts:

backends.py
from veska import Agent, FileMemoryStore, SQLiteMemoryStore

# File-based memory (JSON files on disk)
agent = Agent(
    name="assistant",
    system_prompt="You remember user preferences.",
    model="claude-sonnet-4-6",
    memory_store=FileMemoryStore("./memory"),
)

# SQLite memory
agent = Agent(
    name="assistant",
    system_prompt="You remember user preferences.",
    model="claude-sonnet-4-6",
    memory_store=SQLiteMemoryStore("./memory.db"),
)

Cache

Cache stores responses to avoid duplicate API calls. Two built-in backends:

cache.py
from veska import InMemoryCache, FileCache

# In-memory cache (fast, ephemeral)
agent = Agent(
    name="assistant",
    model="claude-sonnet-4-6",
    cache=InMemoryCache(),
)

# File cache (persists to disk)
agent = Agent(
    name="assistant",
    model="claude-sonnet-4-6",
    cache=FileCache("./cache"),
)

Custom cache backend

Implement the CacheStore interface for Redis, PostgreSQL, or any backend:

custom_cache.py
from veska import CacheStore

class RedisCache(CacheStore):
    def __init__(self, redis_client):
        self.redis = redis_client

    async def get(self, key: str):
        return await self.redis.get(key)

    async def set(self, key: str, value, ttl: int = None):
        await self.redis.set(key, value, ex=ttl)

    async def delete(self, key: str):
        await self.redis.delete(key)

    async def clear(self):
        await self.redis.flushdb()

    async def exists(self, key: str) -> bool:
        return await self.redis.exists(key)

Session store

Session stores save conversation history so agents can continue conversations:

sessions.py
from veska import FileSessionStore, SQLiteSessionStore

# File-based sessions
agent = Agent(
    name="assistant",
    model="claude-sonnet-4-6",
    session_store=FileSessionStore("./sessions"),
)

# Use with user/session IDs
result = agent.run(
    "What did we discuss last time?",
    user_id="user_123",
    session_id="session_abc",
)