OpenAI.Agents.Context (openai_agents v0.1.2)

Manages context state throughout agent execution.

Context provides a way to pass application-specific state through the entire agent execution pipeline, accessible to tools, guardrails, and lifecycle hooks.

Summary

Functions

Returns a specification to start this module under a supervisor.

Gets the current context from the server.

Gets the user context.

Creates a new context with default values.

Starts a context server for managing mutable state during execution.

Updates the context in the server.

Updates usage statistics.

Wraps user-provided context.

Types

t()

@type t() :: %OpenAI.Agents.Context{
  metadata: map(),
  usage: map(),
  user_context: any()
}

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get(server)

@spec get(pid()) :: t()

Gets the current context from the server.

get_metadata(server, key, default \\ nil)

@spec get_metadata(pid(), String.t() | atom(), any()) :: any()

Gets metadata.

get_user_context(server)

@spec get_user_context(pid() | t()) :: any()

Gets the user context.

new()

@spec new() :: t()

Creates a new context with default values.

set_metadata(server, key, value)

@spec set_metadata(pid(), String.t() | atom(), any()) :: :ok

Sets metadata.

start_link(initial_context)

@spec start_link(t()) :: {:ok, pid()}

Starts a context server for managing mutable state during execution.

update(server, fun)

@spec update(pid(), (t() -> t())) :: :ok

Updates the context in the server.

update_usage(server, new_usage)

@spec update_usage(pid(), map()) :: :ok

Updates usage statistics.

wrap(user_context)

@spec wrap(any()) :: t()

Wraps user-provided context.