Behaviour for injecting dynamic content into an agent's system prompt.
Implement this behaviour in a sidecar module to inject per-session context (e.g. memory, project state) into the system prompt before every LLM turn.
Behaviour
Use use Planck.Agent.Hooks.Prompt and override either or both callbacks.
Both default to returning nil (no injection).
defmodule MySidecar.Hooks.Memory do
use Planck.Agent.Hooks.Prompt
@impl true
def after_prompt(session_id) do
case :ets.lookup(:memory, session_id) do
[{^session_id, content}] -> content
[] -> nil
end
end
endDispatch
Planck.Agent stores the resolved hook module atom in state and calls
before_prompt/3 and after_prompt/3 before every LLM turn:
Hooks.Prompt.before_prompt(state.prompt_hook, state.session_id, state.sidecar_node)
Hooks.Prompt.after_prompt(state.prompt_hook, state.session_id, state.sidecar_node)module: nil— returnsnil(no injection).sidecar_node: nil— callsmodule.prepend/1/module.append/1in-process.sidecar_nodeset — calls via RPC; returnsnilon:badrpc.
The default RPC timeout is 5000 ms; override hook_timeout/0
to declare a custom expected latency.
Summary
Callbacks
Return text to inject after all other system prompt sections, or nil for no injection.
Return text to inject before the base system prompt, or nil for no injection.
RPC call timeout in milliseconds when this hook is invoked remotely.
Functions
Call module.after_prompt/1 and return the result, dispatching via RPC when
sidecar_node is set. Returns nil when module is nil or on RPC failure.
Call module.before_prompt/1 and return the result, dispatching via RPC when
sidecar_node is set. Returns nil when module is nil or on RPC failure.
Default RPC timeout used when a hook module omits hook_timeout/0.
Callbacks
Return text to inject after all other system prompt sections, or nil for no injection.
Return text to inject before the base system prompt, or nil for no injection.
@callback hook_timeout() :: pos_integer()
RPC call timeout in milliseconds when this hook is invoked remotely.
Defaults to 5000 ms.
Functions
Call module.after_prompt/1 and return the result, dispatching via RPC when
sidecar_node is set. Returns nil when module is nil or on RPC failure.
Call module.before_prompt/1 and return the result, dispatching via RPC when
sidecar_node is set. Returns nil when module is nil or on RPC failure.
@spec default_timeout() :: pos_integer()
Default RPC timeout used when a hook module omits hook_timeout/0.