as_user
The user a call acts for.
with noclick.as_user(user): sets it for everything inside, sync or async:
.aio calls, tasks and asyncio.to_thread. A thread you start yourself
begins without it (a contextvars rule), so pass user= there. A
method's user= argument wins over it.
noclick.as_user(user)Act for user inside the block: a User, your id for the user, or None
for the account itself. Any string is your id; a user id that breaks the id
rules raises InvalidRequest here.
Who the call acts for. Defaults to the user set by noclick.as_user (none: the account itself).
- Works as a context manager:
withorasync with.
Every call inside the block acts for the user: here, Ana's own Gmail and agent:
with noclick.as_user("user_42"):
gmail = noclick.Connection.from_name("gmail", integration="gmail", create_if_missing=True)
assistant = noclick.Agent.from_name(
"assistant", create_if_missing=True, instructions="You help the user with their email.", tools=[gmail],
)It works the same with async with, and follows your code into tasks and
asyncio.to_thread:
async with noclick.as_user(noclick.User.from_id("user_42")):
agents = await noclick.Agent.list.aio()Your ids can take any shape, a UUID or an identity provider's subject:
with noclick.as_user("auth0|6f1c2b7e9a"):
connections = noclick.Connection.list()current_user
noclick.current_user() -> Anywith noclick.as_user("user_42"):
print(noclick.current_user()) # user_42
print(noclick.current_user()) # NoneALL_USERS
noclick.ALL_USERS = 'all'Values for a read's user_filter: every user plus account-level rows, or account-level only.
NO_USER
noclick.NO_USER = 'none'Values for a read's user_filter: every user plus account-level rows, or account-level only.