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 previously bound tool credential snapshot.
Parameters
Context token returned by set_tool_creds_context.
set_tool_creds_context
set_tool_creds_context(
creds: ToolCreds,
) → TokenStore the credential snapshot for the currently executing tool.
Parameters
Credential snapshot to expose to the current tool invocation.
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
Read a credential declared by the currently executing tool:
import yera as yr
@yr.tool(creds="weather")
def weather_headers() -> dict[str, str]:
api_key = yr.tool_creds().require("weather.api_key")
return {"Authorization": f"Bearer {api_key}"}
Returns
The active tool's credential snapshot.
Raises
When called outside an active tool invocation.