noclick
Python client for the NoClick Platform API: act for your users (the people and
companies your product acts for, each known by your own id for them), connect
their accounts, give your LLM tools, reach a human, run hosted agents,
and give them inboxes, phone numbers and sandboxes.
It works with NoClick's hosted platform; a self-hosted instance doesn't serve this API yet.
From 0.2 the noclick package is this client; the workflow client it replaces stays at 0.1.x.
pip install noclick
export NOCLICK_API_KEY=nk_live_... # a platform key with the scopes you need
# NOCLICK_API_URL defaults to https://api.noclick.com
Quick tour
import noclick
user = noclick.User.from_id("user_42", create_if_missing=True, email="ana@example.com")
with noclick.as_user(user):
# A named connection: pending until Ana connects her Gmail at connect_url
gmail = noclick.Connection.from_name("gmail", integration="gmail", create_if_missing=True,
redirect_url="https://acme.ai/done")
print(gmail.connect_url) # send your user here
gmail.wait() # blocks until they've connected
toolkit = noclick.Toolkit(["search", "gmail.send_email_message"]) # the connection named gmail
ok = user.human.approve("Send the weekly summary to your team?").wait() # True / False
# Ana's own agent: uses her connections; may ask her for a calendar when it needs one
assistant = noclick.Agent.from_name("assistant", create_if_missing=True, instructions="You run Ana's day.",
tools=[gmail, "search"], can_request=["google_calendar"])
print(assistant.message("What's on today?").text)
Ideas
- Lazy objects.
User.from_id(...), Connection.from_name(...),
Agent.from_name(...), Operation.from_id(...) send nothing until used;
create_if_missing=True creates on first use (a concurrent create is
adopted, not duplicated). Given fields, Agent.from_name (and the others
that take them) sets them on the one it finds, on every run, with or without
create_if_missing: one you leave out is never changed, one it can't set on
an existing agent, like ttl_s, raises Conflict, and the grants its user
gave the agent are kept.
create(..., allow_existing=True) makes one once and returns it untouched after.
- Named connections. Code, toolkits and agents name a connection
(
"gmail", or a Connection), so they always act in exactly that account;
two accounts on one service are two names. An agent's connections are its
own scope's: a user's agent uses the user's, an account agent the
account's. A name that is no connection there names an integration's
operations that need no account, on NoClick's key: tools=["exa.search"]
and noclick.run("exa.search", {...}) work for every user with nothing
connected, and a connection named exa holding your own key takes over
the same refs.
- Blocking or async, same method. Every method blocks;
.aio is the
coroutine: await agent.message.aio("hi"). Blocking calls run on a private
loop thread, so they also work in Jupyter and inside running event loops.
- Users, by your id. A user's id is your own id for them: 1 to 255
printable ASCII characters, without spaces or
/, other than all and
none. with noclick.as_user(user_or_id): (or async with) scopes every
call inside it, sending the id as is in the NoClick-User header; any
method's user= wins. Objects a user owns (its connections and agents)
always act for that user; shared objects (Toolkit, Human(),
account-level agents) follow the user current at each call, so
one module-level toolkit serves every user (its connection names resolve
among each call's user's).
- Operations. Anything that waits on the world returns an
Operation;
.wait(timeout=) long-polls and returns the typed outcome (Connection,
Answer, bool, AgentReply) or raises the typed error. .events() yields
status changes, .cancel() cancels.
- Errors carry
.type, .message, .next_step and .details (read as
attributes): noclick.NeedsConnection and noclick.CredentialDisconnected have
.connection and .connect_url, noclick.Conflict has
.existing_id, noclick.PaymentRequired has .balance_usd and .required_usd
(dollars), plus noclick.ApprovalRequired,
noclick.PermissionDenied, noclick.NotFound, noclick.RateLimited, ...
- Safe retries. 408/429/5xx and connection errors retry with backoff
(honouring
Retry-After); each write carries one Idempotency-Key for all
its attempts. A POST's 500 is not retried, nor an answer the server replays
for that key (Idempotent-Replayed); an error says how many times the call
was sent (err.attempts).
Tools for your LLM
import anthropic
toolkit = noclick.Toolkit(["gmail", "search"])
messages = [{"role": "user", "content": "Email Ana the lemon cake recipe"}]
with noclick.as_user("user_42"):
while True:
response = anthropic.Anthropic().messages.create(
model=MODEL, max_tokens=1024, tools=toolkit.definitions(), messages=messages)
if response.stop_reason != "tool_use":
break
messages += [{"role": "assistant", "content": response.content},
{"role": "user", "content": toolkit.handle(response)}]
OpenAI: toolkit.definitions("openai") and messages += toolkit.handle_openai(completion)
(Responses API function_call items work too). Connection tools are named
{connection}__{operation}. A tool whose connection has no account yet returns a
normal result telling the model so, with the link; toolkit.call(...) exposes it
as result.needs_connection / result.connect_url.
A tool call never raises for policy: a denied call, or one held for approval,
comes back as an error result the model reads. A hold's details are kept out
of the model's view, in result.approval_required (approval_id,
request_id, approve_url, operation, approver: "user" or "owner").
request_id (the request a person answers), approve_url and operation (the
approval's operation object) are None unless the request is addressed to
you; the approver is emailed either way. The handle helpers hand each held
call to on_approval:
blocks = toolkit.handle(response, on_approval=lambda r: notify(r.approval_required))
Once the person approves, the model's retry of the identical call goes through.
No model key of your own? noclick.AI runs chat, embeddings, images and transcription paid
from your NoClick balance, and noclick.AI.base_url is an OpenAI-compatible endpoint (chat
completions, responses, embeddings, models) for any OpenAI client, where your agents are models too:
reply = noclick.AI.chat(messages, tools=toolkit.definitions("openai")) # OpenRouter ids: openrouter/...
answer = noclick.AI.chat("Where's my refund?", model="agent:support") # conversation=answer.conversation continues it
More
slack = noclick.Connection.from_name("slack", user="user_42")
slack.lookup("channel", search="gen") # options for an ID field
gmail.run("send_email_message", {"to": ["a@b.c"], "subject": "Hi", "body": "..."})
slack.operations(search="message"); slack.operation("send_message_to_channel").parameters # what it can do
noclick.Connection.integrations("mail") # find a service: name, label, connect_with
noclick.run("exa.search", {"query": "..."}) # needs no account: no connection, NoClick's key
noclick.run("gmail.send_email_message", {...}, user="user_42") # the same ref runs through a connection named gmail
gmail.request(reason="to send your summaries").wait() # emails a fresh link to the user
gmail.token().access_token # OAuth only, credentials:token scope
noclick.Connection.create("crm", credential_type="affinity_api_key", data={"api_key": "..."}) # a key you hold
for grant in assistant.grants(): # connections its user gave it
print(grant.connection, grant.status) # assistant.revoke_grant(grant)
noclick.Human(email="ops@acme.ai").ask("Ship it?", options=["Yes", "No"]).wait().choice
reply = agent.message("Any lemon cake?")
agent.message("Two slices please", conversation=reply.conversation) # same thread
agent.wake(reply.conversation, after=3600, note="Check the order shipped.") # a turn later; agent.wakeups(), its wake_me tool
agent.memory.save("menu", "Lemon cake on Fridays.", description="What we bake when") # it sees the line every turn
coder = noclick.Agent.create("coder", instructions="...", harness="claude_code", model_connection="claude") # Agent.harnesses() lists them
run = noclick.Workflow.from_name("order-intake").run({"order_id": "o1"}).wait() # one built in the app
print(run.outputs)
client = noclick.Client(api_key="nk_live_other", base_url="https://api.noclick.com")
noclick.User.list(client=client) # or noclick.configure(api_key=...)
Spend, policy, channels and sandboxes
# Spend and caps
noclick.usage(group_by="user")["user_42"].usd # this month, per user / key / agent
# any call can raise noclick.SpendCapExceeded (402) with .cap, .spent, .scope
est = noclick.estimate([{"kind": "project", "runtime": "edge", "usage": {"requests": 100_000}}, {"kind": "bucket"}])
print(est.monthly_usd, est.lines) # priced before anything is made; nothing is charged
# Policy: deny wins, a user policy narrows the account's
noclick.Policy.set(deny=["*.delete_*"], require_approval=["gmail.send_email_message"])
noclick.Policy.set(allow=["search", "gmail.*"], user="user_42")
try:
gmail.run("send_email_message", args)
except noclick.ApprovalRequired as pending: # a Human.approve went out
if pending.operation.wait(): # True once approved
gmail.run("send_email_message", args, approval_id=pending.approval_id)
# a Toolkit never raises: a denied or held tool is an error result (see "Tools for your LLM")
noclick.Brand.set(name="Acme", logo_url="https://acme.ai/logo.png", color="#ff5500") # /h/ pages + emails
user.verify_phone(); user.check_phone("123456") # True; a wrong code raises noclick.InvalidRequest
# Agents with tools, children and A2A
planner = noclick.Agent.create("planner", instructions="...", tools=["gmail", "slack.send_message_to_channel"],
budget_usd_per_month=20) # the account's gmail and slack connections
child = noclick.Agent.create("inbox-helper", instructions="Summarize the inbox.", parent_id=planner,
tools=["gmail.fetch_emails_from_inbox"], ttl_s=900, budget_usd_per_month=0.5)
planner.children() # child too; expired past its ttl_s, readable 30 days
researcher = planner.spawn("Find three launches.", tools=["gmail"], conversation="launch",
updates=["blocked", noclick.Before("gmail.*"), noclick.Every(900)]) # starts at once
researcher.job.wait(); researcher.job.updates(); planner.jobs(status="live") # each update wakes planner in "launch"
researcher.ask("Where are you?"); researcher.ask("Skip B.", interject=True) # a snapshot, or into its running turn
planner.a2a_card(); planner.a2a_url # JSON-RPC endpoint, platform key as bearer
# Channels: agents, the user and remote A2A agents in one room (closed on exit)
with noclick.Channel.create("launch", members=[planner, user, "https://remote.ai/a2a"],
mode="mentions", max_agent_turns=20, budget_usd=2) as room:
room.post("@planner draft the announcement", as_=user)
for message in room.stream(): # long-polls until the channel closes
print(message.author.name, message.text) # async: `async for m in room.stream.aio()`
if message.author.name == "planner":
break
# Sandboxes (terminated on exit, billed per second)
with noclick.Sandbox.create(image="python", timeout_s=600) as sb:
sb.files.write("/tmp/data.csv", csv_bytes)
result = sb.exec("python -c 'print(open(\"/tmp/data.csv\").read()[:80])'")
print(result.exit_code, result.stdout, result.stderr) # a non-zero exit is a result, not an error
Sessions, inboxes and phone numbers