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
clear_tool_creds_context
clear_tool_creds_context() → NoneClear 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,
) → NoneRestore the tool credential snapshot to the value bound before :func:set_tool_creds_context.
set_tool_creds_context
set_tool_creds_context(
creds: ToolCreds,
) → TokenStore the credential snapshot for the currently executing tool.
Returns
A ContextVar token for use with :func:reset_tool_creds_context so nested tool invocations can restore the previous snapshot.
tool_creds
tool_creds() → ToolCredsReturn 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
The active tool's credential snapshot.
Raises
When called outside an active tool invocation.