yera.tools.creds.context

Credential context for tool invocations.

When a @tool-decorated function runs, its credentials are resolved and bound to a ContextVar before the function body executes. The tool body reads them back via tool_creds.

Symbols

def clear_tool_creds_context — Clear the current tool credential snapshot (tests and explicit teardown).
def reset_tool_creds_context — Restore the tool credential snapshot to the value bound before :func:`set_tool_creds_context`.
def set_tool_creds_context — Store the credential snapshot for the currently executing tool.
def tool_creds — Return the active tool's credentials.

clear_tool_creds_context

clear_tool_creds_context() → None

Clear the current tool credential snapshot (tests and explicit teardown).

This sets the context to None without using a prior token. Prefer :func:reset_tool_creds_context when unwinding a paired :func:set_tool_creds_context.

reset_tool_creds_context

reset_tool_creds_context(
    token: Token,
) → None

Restore the tool credential snapshot to the value bound before :func:set_tool_creds_context.

set_tool_creds_context

set_tool_creds_context(
    creds: ToolCreds,
) → Token

Store the credential snapshot for the currently executing tool.

Returns

type: Token

A ContextVar token for use with :func:reset_tool_creds_context so nested tool invocations can restore the previous snapshot.

tool_creds

tool_creds() → ToolCreds

Return the active tool's credentials.

Call from inside a @tool-decorated function to read the credentials the tool declared with creds=.... The returned ToolCreds is a read-only snapshot of the configured credential groups, flattened to dotted keys.

Examples

@yr.tool(creds=["my_api"])
def call_api(prompt: str) -> str:
    api_key = yr.tool_creds().require("my_api.api_key")
    ...

Returns

type: ToolCreds

The active tool's credential snapshot.

Raises

RuntimeError

When called outside an active tool invocation.