ADK.Context (ADK v0.0.1-alpha.1)

Copy Markdown View Source

Invocation context threaded through the agent pipeline.

Summary

Functions

Emit an event via the streaming callback if one is set.

Create a child context for a sub-agent.

Fork context for a parallel branch.

Get a value from temp state.

Put a value in temp state, returning updated context.

Types

t()

@type t() :: %ADK.Context{
  agent: any(),
  app_name: String.t() | nil,
  artifact_service: {module(), keyword()} | nil,
  branch: String.t() | nil,
  callbacks: [module()],
  credential_service: module() | nil,
  ended: boolean(),
  invocation_id: String.t(),
  memory_store: {module(), keyword()} | nil,
  on_event: (ADK.Event.t() -> any()) | nil,
  plugins: [{module(), term()}],
  policies: [module()],
  run_config: ADK.RunConfig.t() | nil,
  session_pid: pid() | nil,
  temp_state: map(),
  user_content: map() | nil,
  user_id: String.t() | nil
}

Functions

emit_event(ctx, event)

@spec emit_event(t(), ADK.Event.t()) :: :ok

Emit an event via the streaming callback if one is set.

Uses the process dictionary to deduplicate: if an event with the same ID was already emitted in this invocation, the call is a no-op. This allows both LlmAgent (which emits events inline during execution) and Runner (which emits at the end as a fallback) to call emit_event without double-firing.

This is called internally by agents and the runner to stream events in real-time when an on_event callback is configured in the context.

for_child(ctx, agent_spec)

@spec for_child(t(), map()) :: t()

Create a child context for a sub-agent.

Extends the branch path to include the child agent name, enabling branch-aware content filtering. The branch uses dot-delimited paths like Python ADK's invocation_id hierarchy.

fork_branch(ctx, child_name)

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

Fork context for a parallel branch.

Examples

iex> ctx = %ADK.Context{invocation_id: "inv-1", branch: nil}
iex> child = ADK.Context.fork_branch(ctx, "searcher")
iex> child.branch
"searcher"

get_temp(context, key)

@spec get_temp(t(), term()) :: term() | nil

Get a value from temp state.

put_temp(ctx, key, value)

@spec put_temp(t(), term(), term()) :: t()

Put a value in temp state, returning updated context.