BeamAgent.Context (beam_agent_ex v0.1.0)

Copy Markdown View Source

Elixir facade for canonical BeamAgent context management.

BeamAgent.Context keeps compaction explicit and caller-driven. It reports current pressure, summary state, and memory handoff candidates, then lets the caller decide when to compact. It does not start a hidden scheduler or background compactor.

Use budget_estimate/1 or context_status/1 to inspect pressure first, then call maybe_compact/2 or compact_now/2 from a boundary you already own, such as a routine runner or orchestration completion hook.

Summary

Types

Context budget estimate map.

Immediate compaction result map.

Context-layer error returned by the Erlang public API.

Current context status map.

Policy-driven compaction result map.

Session or thread scope accepted by the context manager.

Functions

Estimate current context budget pressure using default thresholds.

Summarize, optionally promote to memory, and compact immediately.

Return current context pressure and available summary/memory state.

Compact only when a configured policy trigger fires.

Types

budget_estimate_result()

@type budget_estimate_result() :: :beam_agent_context.budget_estimate_result()

Context budget estimate map.

compact_now_result()

@type compact_now_result() :: :beam_agent_context.compact_now_result()

Immediate compaction result map.

context_error()

@type context_error() :: :beam_agent_context.context_error()

Context-layer error returned by the Erlang public API.

context_status()

@type context_status() :: :beam_agent_context.context_status()

Current context status map.

maybe_compact_result()

@type maybe_compact_result() :: :beam_agent_context.maybe_compact_result()

Policy-driven compaction result map.

scope()

@type scope() :: :beam_agent_context.scope()

Session or thread scope accepted by the context manager.

Functions

budget_estimate(session_or_thread)

@spec budget_estimate(scope()) :: {:ok, budget_estimate_result()} | {:error, term()}

Estimate current context budget pressure using default thresholds.

compact_now(session_or_thread, opts)

@spec compact_now(scope(), map()) ::
  {:ok, compact_now_result()}
  | {:error, context_error() | {:hook_denied, binary()} | {:hook_ask, binary()}}

Summarize, optionally promote to memory, and compact immediately.

context_status(session_or_thread)

@spec context_status(scope()) :: {:ok, context_status()} | {:error, term()}

Return current context pressure and available summary/memory state.

maybe_compact(session_or_thread, opts)

@spec maybe_compact(scope(), map()) ::
  {:ok, maybe_compact_result()}
  | {:error, context_error() | {:hook_denied, binary()} | {:hook_ask, binary()}}

Compact only when a configured policy trigger fires.