ADK.Tool.Context (adk_ex v1.1.0)

Copy Markdown View Source

Context passed to tool execution.

Wraps a CallbackContext and adds function_call_id and its own Actions. Each tool call gets its own ToolContext with independent actions that are merged after all tool calls complete.

Summary

Functions

Returns the agent name from the underlying callback context.

Gets a value from session state, checking tool actions then callback actions then session.

Lists artifact filenames for the current session.

Loads an artifact by filename. Version 0 (default) loads the latest.

Creates a new tool context from a callback context and function call ID.

Saves an artifact and tracks it in the tool's artifact_delta.

Searches memory for entries matching the query.

Sets a value in the tool actions state_delta.

Types

t()

@type t() :: %ADK.Tool.Context{
  actions: ADK.Event.Actions.t(),
  callback_context: ADK.Agent.CallbackContext.t(),
  function_call_id: String.t() | nil
}

Functions

agent_name(context)

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

Returns the agent name from the underlying callback context.

get_state(context, key)

@spec get_state(t(), String.t()) :: any()

Gets a value from session state, checking tool actions then callback actions then session.

list_artifacts(ctx)

@spec list_artifacts(t()) :: {:ok, [String.t()]} | {:error, term()}

Lists artifact filenames for the current session.

load_artifact(ctx, filename, version \\ 0)

@spec load_artifact(t(), String.t(), non_neg_integer()) ::
  {:ok, ADK.Types.Part.t()} | {:error, term()}

Loads an artifact by filename. Version 0 (default) loads the latest.

new(cb_ctx, function_call_id \\ nil)

@spec new(ADK.Agent.CallbackContext.t(), String.t() | nil) :: t()

Creates a new tool context from a callback context and function call ID.

save_artifact(ctx, filename, part)

@spec save_artifact(t(), String.t(), ADK.Types.Part.t()) ::
  {:ok, non_neg_integer(), t()} | {:error, term()}

Saves an artifact and tracks it in the tool's artifact_delta.

Returns {:ok, version, updated_context} or {:error, reason}.

search_memory(context, query)

@spec search_memory(t(), String.t()) :: {:ok, [ADK.Memory.Entry.t()]}

Searches memory for entries matching the query.

set_state(ctx, key, value)

@spec set_state(t(), String.t(), any()) :: t()

Sets a value in the tool actions state_delta.