Planck.Agent.Context (Planck.Agent v0.3.0)

Copy Markdown View Source

Context fields for a running agent.

Holds the conversation state: working directory, system prompt, tools, messages, token usage, and the dissolved skill index fields.

Skill index fields (formerly Planck.Agent.SkillIndex):

  • skills_pool — frozen list of Skill.t() for the system prompt
  • skills_ranked — skill names ordered by usage history
  • skills_top_n — maximum number of ranked skills shown
  • skills_names — skill names declared in TEAM.json
  • skills_refresh_fn — returns the live skill pool for tool dispatch
  • skills_index_refresh_fn — rebuilds skills_pool/skills_ranked after compaction

Summary

Types

t()

An agent's context.

Functions

Add a tool at runtime.

Build a Context from agent start opts and a tool map.

Build the AI request context from identity, hooks, and context.

Drains control marker from the context

Flush unpersisted messages and reload from session.

Load messages from the session store without stripping orphans.

Persist a message via the hooks persistence layer.

Persist usage via the hooks persistence layer.

Reload messages from the session store.

Remove a tool by name at runtime.

Remove unpersisted

Types

t()

@type t() :: %Planck.Agent.Context{
  context_tokens: non_neg_integer(),
  cwd: String.t(),
  messages: [Planck.Agent.Message.t()],
  opts: keyword(),
  skills_index_refresh_fn: (-> {[Planck.Agent.Skill.t()], [String.t()]}) | nil,
  skills_names: [String.t()],
  skills_pool: [Planck.Agent.Skill.t()],
  skills_ranked: [String.t()],
  skills_refresh_fn: (-> [Planck.Agent.Skill.t()]) | nil,
  skills_top_n: pos_integer(),
  system_prompt: String.t(),
  tools: %{required(String.t()) => Planck.Agent.Tool.t()},
  usage: Planck.Agent.Usage.t()
}

An agent's context.

Functions

add_tool(context, tool)

@spec add_tool(t(), Planck.Agent.Tool.t()) :: t()

Add a tool at runtime.

append_messages(context, identity, hooks, messages, opts \\ [])

@spec append_messages(
  t(),
  Planck.Agent.Identity.t(),
  Planck.Agent.Hooks.t(),
  [Planck.Agent.Message.t()],
  keyword()
) :: t()

Appends messages to the context

build(opts)

@spec build(keyword()) :: t()

Build a Context from agent start opts and a tool map.

calculate_context(context, identity, hooks)

Build the AI request context from identity, hooks, and context.

compact(context, identity, hooks, opts)

@spec compact(t(), Planck.Agent.Identity.t(), Planck.Agent.Hooks.t(), keyword()) ::
  t()

Compacts the context.

drain_control_markers(context, identity, hooks)

@spec drain_control_markers(t(), Planck.Agent.Identity.t(), Planck.Agent.Hooks.t()) ::
  {:clear, t()} | {:compact, t(), %{prompt: String.t() | nil}} | :none

Drains control marker from the context

flush_unpersisted(context, identity, hooks)

@spec flush_unpersisted(t(), Planck.Agent.Identity.t(), Planck.Agent.Hooks.t()) :: t()

Flush unpersisted messages and reload from session.

load_messages(context, identity, hooks)

@spec load_messages(t(), Planck.Agent.Identity.t(), Planck.Agent.Hooks.t()) :: t()

Load messages from the session store without stripping orphans.

persist_message(identity, hooks, msg)

Persist a message via the hooks persistence layer.

persist_usage(context, identity, hooks)

@spec persist_usage(t(), Planck.Agent.Identity.t(), Planck.Agent.Hooks.t()) :: :ok

Persist usage via the hooks persistence layer.

reload_from_session(context, identity, hooks)

@spec reload_from_session(t(), Planck.Agent.Identity.t(), Planck.Agent.Hooks.t()) ::
  t()

Reload messages from the session store.

remove_tool(context, name)

@spec remove_tool(t(), String.t()) :: t()

Remove a tool by name at runtime.

remove_unpersisted(context, id)

@spec remove_unpersisted(t(), String.t()) :: t()

Remove unpersisted

replace_messages(context, identity, hooks, messages, opts \\ [])

@spec replace_messages(
  t(),
  Planck.Agent.Identity.t(),
  Planck.Agent.Hooks.t(),
  [Planck.Agent.Message.t()],
  keyword()
) :: t()

Replaces messages in the context

update_usage(context, identity, hooks, input, output)

Updates usage in context