Skip to main content

sudo for AI agents - allow, deny, or ask before any tool runs

Project description

agentpriv

sudo for AI agents - allow, deny, or ask before any tool runs.

AI agents run tools autonomously, but some calls are too risky to run unchecked. agentpriv gives you a permission layer to control what goes through.

Why

  • One place - guard a tool once, every agent using it gets the same rule
  • Gradual trust - start on "ask", promote to "allow" as you gain confidence
  • Visibility - every blocked or prompted call is printed with full arguments, so you see exactly what the agent is trying to do
  • Framework agnostic - plain wrapper around your functions, so it works with any agent framework or none at all

Install

pip install agentpriv

Quick start

from agentpriv import guard, guard_all, AgentPrivDenied

safe_send = guard(send_message, policy="ask")

tools = guard_all(
    [read_messages, send_message, delete_channel],
    policy={
        "delete_*": "deny",
        "send_*":   "ask",
        "*":        "allow",
    }
)

Three modes

Mode What happens
"allow" Runs normally, no interruption
"deny" Raises AgentPrivDenied immediately, the function never executes
"ask" Pauses, shows the call in your terminal, waits for y/n
agentpriv: send_message(channel='general', text='deploying now')
Allow this call? [y/n]: y   # runs the function
Allow this call? [y/n]: n   # raises AgentPrivDenied

on_deny - raise or return

By default, denied calls raise AgentPrivDenied. When using frameworks, set on_deny="return" so the LLM sees the denial as a tool result instead of crashing:

# Plain Python - raises exception
safe = guard(delete_channel, policy="deny")

# Frameworks - returns error string to the LLM
safe = guard(delete_channel, policy="deny", on_deny="return")

Works with any framework

Guard first, then pass to your framework as usual:

OpenAI Agents SDK

safe_delete = function_tool(guard(delete_db, policy="ask", on_deny="return"))
agent = Agent(name="Demo", tools=[safe_delete])

LangChain / LangGraph

safe_delete = tool(guard(delete_db, policy="ask", on_deny="return"))
agent = create_agent(model=llm, tools=[safe_delete])

PydanticAI

agent = Agent("openai:gpt-4o", tools=[guard(delete_db, policy="ask", on_deny="return")])

CrewAI

safe_delete = tool("Delete DB")(guard(delete_db, policy="ask", on_deny="return"))
agent = Agent(role="DBA", tools=[safe_delete])

Custom prompt

By default, "ask" mode prompts in the terminal. Pass prompt= to use your own approval logic:

# auto-approve in testing
safe = guard(delete_db, policy="ask", prompt=lambda name, args, kwargs: True)

# approve via web UI, Slack, or any custom flow
safe = guard(delete_db, policy="ask", prompt=my_approval_handler)

Policy matching

  • Patterns use glob syntax (fnmatch) against the function's __name__
  • More specific patterns win over wildcards (delete_channel > delete_* > *)
  • If a function doesn't match any pattern, it defaults to "deny" - so forgetting a rule blocks the call rather than silently allowing it. Use "*": "allow" as a catch-all to opt out

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentpriv-0.1.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentpriv-0.1.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file agentpriv-0.1.1.tar.gz.

File metadata

  • Download URL: agentpriv-0.1.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for agentpriv-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7e78fda22f2043c6869390798389c5f7054481ee59667a9c72c9316b9009cb8b
MD5 219e75bbf094cfe770d92e935e7894ec
BLAKE2b-256 6094121e7d93898c941f4073a66a703b383fd4b3fa56dfabd73b264cd77862c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentpriv-0.1.1.tar.gz:

Publisher: publish.yml on nichkej/agentpriv

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agentpriv-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: agentpriv-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for agentpriv-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d144fafdc341099aeffba4a3c757cf4456a89e98abab8dd95c41610cda378b68
MD5 73ead82cf72a29af6e7fb2feee3fa2f8
BLAKE2b-256 414abca4fcb1f965a038a97bb6af0312480eabd12330f6c3252f51b21056e1b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for agentpriv-0.1.1-py3-none-any.whl:

Publisher: publish.yml on nichkej/agentpriv

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page