Agentic.Memory.ContextKeeper (agentic v0.2.2)

Copy Markdown

Per-workspace in-process working memory.

Maintains two data structures:

  • facts — structured triples extracted from tool results and LLM responses (entity/relation/value). Capped at 500 entries, oldest dropped first.

  • working_set — key-value pairs stored explicitly by the agent or loop stages. Supports TTL (seconds or :infinity) and priority (:high, :normal, :low).

Registered via Agentic.Memory.ContextKeeperRegistry so there is at most one keeper per workspace. Survives session restarts but stops when the workspace disconnects.

Summary

Functions

Returns a specification to start this module under a supervisor.

Return formatted context string for injection into system prompt.

Retrieve a value from the working set.

Ingest a list of facts from FactExtractor.

Query facts matching a substring in entity or value fields.

Check if a ContextKeeper is running for the given workspace.

Store a key-value pair in the working set.

Types

fact()

@type fact() :: %{
  entity: String.t(),
  relation: String.t(),
  value: String.t(),
  confidence: float(),
  source_turn: integer(),
  inserted_at: DateTime.t()
}

state()

@type state() :: %{
  workspace_id: String.t(),
  facts: [fact()],
  working_set: %{required(String.t()) => working_entry()}
}

working_entry()

@type working_entry() :: %{
  value: term(),
  ttl: integer() | :infinity,
  priority: :high | :normal | :low,
  inserted_at: DateTime.t()
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_context(workspace_id)

@spec get_context(String.t()) :: String.t() | nil

Return formatted context string for injection into system prompt.

Includes high-priority working set items and recent facts.

get_working_value(workspace_id, key)

@spec get_working_value(String.t(), String.t()) :: term() | nil

Retrieve a value from the working set.

ingest(workspace_id, facts)

@spec ingest(String.t(), [fact()]) :: :ok

Ingest a list of facts from FactExtractor.

query(workspace_id, query_string)

@spec query(String.t(), String.t()) :: {:ok, [fact()]}

Query facts matching a substring in entity or value fields.

running?(workspace_id)

@spec running?(String.t()) :: boolean()

Check if a ContextKeeper is running for the given workspace.

set_working_value(workspace_id, key, value, opts \\ [])

@spec set_working_value(String.t(), String.t(), term(), keyword()) :: :ok

Store a key-value pair in the working set.

start_link(opts)