Security advisory — Malicious litellm versions 1.82.7 and 1.82.8 were removed from PyPI (potential API key exfiltration). Uninstall them, rotate exposed credentials, and upgrade to a safe release (e.g. 1.82.9+). Run pip show litellm to verify. PyPI · README

Memory

Memory system in AgenticX.

Memory in AgenticX

Memory is how an agent keeps identity, recent work, and a bounded window. Near's main path is workspace files (MEMORY.md, memory/*.md) plus session messages.json, then recall injected into the Meta system prompt. Optional Mem0 / other stores are library backends, not the Desktop default.

Diagram: MEMORY.md is recalled; messages.json may be compacted.

Worked example: write a preference, see it next turn

Scene. You want Meta to keep calling you a nickname and avoid a formatting habit.

  1. Put the fact in ~/.agenticx/workspace/MEMORY.md or memory/*.md (or the user-preference field in Settings — that is injected via _build_user_profile_block()).
  2. Start a new turn in the same Meta session. The system prompt should include the recall block from _build_memory_recall_context.
  3. Long threads may compact: older history becomes a summary system message. The file-backed facts should still be there even if the transcript was compacted.

What you should see. Workspace panel highlighting MEMORY.md. The next answer uses the nickname without you repeating it. Session title stays the persisted Chinese title, not a raw session_id.

Workspace memory file open in English
Near workspace with MEMORY.md open. The file holds the preference the next turn can recall.

Together these mechanisms approximate a layered memory stack: what must always be true (identity), what happened recently (episodes), what generalizes (semantics), what the model sees this turn (working set), what survives across sessions (long-term files and stores), and what is scoped to the user's workspace on disk.


Memory hierarchy (six-layer model)

The table maps a classic cognitive-style hierarchy to concrete AgenticX surfaces. Layers are conceptual; several features overlap in implementation.

LayerRoleAgenticX realization
Core memoryStable role, name, non-negotiable factsIDENTITY.md, SOUL.md, avatar/session system prompts, Meta-Agent identity blocks
Episodic memoryWhat was said and done in conversationschat_history / persisted messages.json, tool traces in history
Semantic memoryReusable knowledge, not tied to one chatCurated MEMORY.md, optional Mem0 / knowledge components, indexed chunks in WorkspaceMemoryStore
Short-term / working memoryScratch space for the current taskPer-session scratchpad dict, scratchpad_write / scratchpad_read tools, recent message window
Long-term memoryCross-session persistenceMEMORY.md (manual + auto-append), SQLite session store for scratchpad, optional Mem0
Workspace memoryProject- and user-scoped files under ~/.agenticx/workspaceUSER.md, daily memory/<YYYY-MM-DD>.md, directory layout per avatar/project

MemoryHook

MemoryHook is an AgentHook registered on AgentRuntime with priority=-10, so it runs after hooks with higher numeric priority when run_on_agent_end walks the registry.

When it runs

  • on_agent_end is invoked after a turn completes.
  • It reads session.chat_history. If len(chat_history) < MIN_CHAT_TURNS * 2 it returns immediately. Defaults: MIN_CHAT_TURNS = 3 → at least six chat records required.
  • Workspace directory: session.workspace_dir, else AGX_WORKSPACE_ROOT, else the user home directory.

Extraction and limits

  • Heuristic only (no extra LLM call): scans the last 20 messages for Chinese user-request cues and assistant completion cues, emits bullet lines such as - 用户请求: / - 完成事项:.
  • Caps output at MAX_FACTS_PER_SESSION (8) facts.

Persistence

  • Appends a dated block to memory/<today>.md under the workspace. Skips append if existing daily file plus new block would exceed 8000 characters.
  • If MEMORY.md exists and is under 4000 characters, appends an ## Auto-extracted section with up to four of the facts.

Scratchpad

  • Merges facts into session.scratchpad["session_facts"] (concatenated with newlines).

_maybe_compact_daily

  • If today's memory/<YYYY-MM-DD>.md exceeds 2000 characters, rewrites it: keeps headings, drops duplicate bullet lines keyed by the first 80 characters (case-folded), preserving first occurrence. This is deterministic deduplication, not an LLM summarizer.
python
1# Reference constants (agenticx/runtime/hooks/memory_hook.py)
2MIN_CHAT_TURNS = 3 # requires len(chat_history) >= MIN_CHAT_TURNS * 2
3MAX_FACTS_PER_SESSION = 8

Workspace memory

Directory layout (~/.agenticx/workspace/)

PathPurpose
IDENTITY.mdWho the agent is; stable persona
USER.mdUser profile, preferences
SOUL.mdDeeper style / values / tone
MEMORY.mdLong-form durable notes; receives optional auto-extracted sections
memory/<YYYY-MM-DD>.mdDaily session-fact log from MemoryHook

Additional session artifacts (avatars, groups) may live alongside; the search index explicitly pulls the four root markdown files plus memory/*.md.

Automatic recall: _build_memory_recall_context

Defined in agenticx/runtime/prompts/meta_agent.py. When building the Meta-Agent system prompt it:

  1. Collects text from the last five user messages (up to 200 characters each).
  2. Builds a query string (max 500 characters).
  3. Calls WorkspaceMemoryStore.search_sync(..., limit=5, mode="hybrid").
  4. Injects a ## 相关历史记忆(自动召回) section with snippets capped around 500 characters total.

If there are no user messages or no hits, the section is omitted.


Mem0 integration

Mem0 is optional. Install with the extra that pulls memory dependencies:

bash
1pip install "agenticx[memory]"

At runtime, agenticx.memory exposes Mem0 / async variants when dependencies are present; the vendored integration under agenticx/integrations/mem0/ supports multiple vector stores and configs. Use Mem0 when you want managed long-term semantic memory (add/search APIs, hosted or local) instead of or alongside file-based MEMORY.md.


Session scratchpad

Each StudioSession carries a scratchpad dictionary persisted via SQLite (agenticx/memory/session_store.py). Besides user/agent keys from scratchpad_write, the runtime uses reserved patterns:

Key patternPurpose
subagent_result::<id>Summary text after a subagent / delegation completes
delegation_result::<id>Same pipeline writes delegation outcomes for Meta-Agent follow-up
session_factsIncremental lines from MemoryHook
__pending_subagent_summaries__Queue of pending subagent reports (internal)
__taskspace_hint__ / __taskspace_label_hint__Taskspace path hints from tools

Meta-Agent context building reads subagent_result::* entries for "historical subagent results" when registry rows are missing.


Context compaction (ContextCompactor)

Before each turn, AgentRuntime runs ContextCompactor.maybe_compact on sanitized agent_messages.

ParameterDefaultBehavior
threshold_messages20Compact if message count exceeds this
threshold_chars48000Or if sum of content string lengths exceeds this
retain_recent_messages8Oldest portion is summarized; these tail messages stay verbatim

Process:

  1. Split into prefix (to compact) and suffix (retained).
  2. Call the runtime LLM with a Chinese compaction instruction (temperature 0, max_tokens 400).
  3. Replace the prefix with a single system message prefixed with [compacted] and the summary.
  4. On failure, fall back to concatenated short snippets.

Minimum enforced floors: threshold_messages >= 8, threshold_chars >= 4000, retain_recent_messages >= 4.


Memory-related configuration

ItemWhereDescription
memory.backend~/.agenticx/config.yamlDeclared in docs for pluggable memory backends (sqlite, redis, postgresql, etc.)
memory.path~/.agenticx/config.yamlWorkspace root for memory features
AGX_WORKSPACE_ROOTEnvironmentFallback workspace directory for MemoryHook when session.workspace_dir is unset
MIN_CHAT_TURNSCode constantMemoryHook gate: needs len(chat_history) >= MIN_CHAT_TURNS * 2
MAX_FACTS_PER_SESSIONCode constantCap on heuristic facts per on_agent_end
WorkspaceMemoryStore DBDefault path~/.agenticx/memory/main.sqlite (DEFAULT_WORKSPACE_MEMORY_DB)
ContextCompactor thresholdsCode defaults20 messages / 48000 chars trigger; retain 8 messages
yaml
1# ~/.agenticx/config.yaml (illustrative memory block)
2memory:
3 backend: sqlite
4 path: ~/.agenticx/workspace

See also