This release is a pre-release and may not be stable for production use.
shieldaai-agent-guard
Preview. New in Agent Guard 1.9.0. The HTTP API it speaks may still change in a minor release, and it has no production users yet. Please open an issue if something does not fit.
Python client for the Agent Guard decision server. Before each tool call, your agent asks the server whether the call may run. On yes, it runs the tool itself with the arguments the server checked, then reports the outcome. The server applies Agent Guard's checks: grants per task and resource, allowed recipients, sensitive and untrusted data, secrets in external calls, approvals by a person, call and cost budgets, and your policies.
No runtime dependencies. Python 3.10 or later. Helpers for LangChain, LangGraph and CrewAI.
pip install shieldaai-agent-guard
Start the server
The server is agent-guard-decide, from the npm package @shieldaai/agent-guard-adapters
(Node.js 22 or later). It reads a JSON file that lists your tools, and you get its admin token
from the environment:
export AGENT_GUARD_ADMIN_TOKEN="$(npx -y -p @shieldaai/agent-guard-adapters@1.9.0 agent-guard-decide --new-token)"
npx -y -p @shieldaai/agent-guard-adapters@1.9.0 agent-guard-decide --config decide.json
{
"version": 1,
"tools": [
{
"name": "ticket_read",
"description": "Read one support ticket",
"inputSchema": {
"type": "object",
"properties": { "id": { "type": "string", "pattern": "^[0-9]+$" } },
"required": ["id"],
"additionalProperties": false
},
"resource": "ticket:{id}",
"readsUntrusted": true
},
{
"name": "ticket_close",
"description": "Close one support ticket",
"inputSchema": { "type": "object", "properties": { "id": { "type": "string" } }, "required": ["id"] },
"resource": "ticket:{id}",
"requiresApproval": true
}
]
}
resource names what the call touches, built from its arguments. A task may only call a tool
on the resources it was granted. Every field is described in
the API reference.
Create a task, then guard the tools
Your backend creates one task per job, for the user it signed in, and gives the agent only the task's token:
from shieldaai.agent_guard import AdminClient, Grant, TaskClient
admin = AdminClient("http://127.0.0.1:8787", admin_token) # your backend only
task = admin.create_task(
principal_id=user.id, # from your own sign-in, never from the model
tenant_id=user.tenant_id,
grants=[Grant("ticket_read", ["ticket:42"]), Grant("ticket_close", ["ticket:42"])],
max_calls=20,
max_concurrent=4, # LangGraph runs one message's tool calls in parallel
ttl_seconds=600,
)
guard = TaskClient("http://127.0.0.1:8787", task.token) # the agent side
@guard.tool()
def ticket_read(id: str) -> dict:
return tickets.get(id)
ticket_read(id="42") asks the server, runs the function and reports the outcome.
ticket_read(id="7") raises ToolDenied, because the task was granted ticket 42 only;
str(error) is a message written for the model. If the function raises, the failure is
reported and the exception propagates.
A tool that needs approval raises ApprovalPending (with action_id). Calling it again with
the same arguments does not queue a second request: it raises ApprovalPending for the same
action until a person approves it, and then runs it. Pass wait_for_approval=120 to wait in the
call instead.
max_concurrent(default 1) is how many calls may run at once. Set it to at least the number of tool calls a model may make in one turn, or the extra ones are denied withCONCURRENCY_EXCEEDED. The server lets one task token have 8 requests in progress (a call waiting for approval counts); raiseserver.maxActiveRequestsPerCredentialin its configuration for more.- The guard sees every argument by name, defaults included (except a default of
None, which is not sent), so the schema must list every parameter. The function runs with the values it checked after a JSON round trip: a tuple arrives as a list, a date as a string. @guard.tooland@guard.tool("name")both work, ondefandasync def. For a method, callguard.run("name", args, call)inside it.cost=lambda result: ...reports what the call cost. A cost that fails or is out of range is logged and the call is charged its maximum.
LangChain and LangGraph
from shieldaai.agent_guard.langchain import guard_tools
from langgraph.prebuilt import create_react_agent
agent = create_react_agent(model, guard_tools(guard, [ticket_read, ticket_close]))
Each guarded tool keeps its name, description and schema. A denial reaches the model as the
tool's error message, so the agent reads why instead of stopping. Arguments the tool marks as
injected (InjectedToolArg, InjectedState, InjectedToolCallId) are filled in by your code
or LangGraph, so they are not sent to the guard and it does not check them; every other
argument is. A tool that returns a LangGraph Command returns it unchanged. config_entry(tool, resource="ticket:{id}") builds the server configuration entry from a LangChain tool, so the
server checks the same schema the model is shown.
CrewAI
from shieldaai.agent_guard.crewai import guard_tools
agent = Agent(role="Support", goal="...", backstory="...", tools=guard_tools(guard, [ReadTicket()]))
The guarded copies never write to CrewAI's result cache: a cached answer would skip the check
and the budget. CrewAI also reads that cache by tool name for the whole crew, so create the crew
with cache=False.
Approvals
for item in admin.pending(tenant_id=reviewer.tenant_id):
if item.state == "pending": # "approved" ones wait for the agent to collect them
# Show item.tool, item.args and item.resource_id to the reviewer, then:
admin.approve(item.action_id, approver_id=reviewer.id) # or admin.reject(item.action_id)
The agent collects the approval by calling the tool again with the same arguments, by calling
guard.wait(action_id, timeout=...), or in the call itself when the decorator was given
wait_for_approval.
Connections
Each call through the decorator, run or the framework helpers sends a fresh callId with its
decision. If the answer is lost to a timeout or a dropped connection, the client asks once more
with the same ID and gets the first answer back, so a retry never starts a second call.
The client never follows a redirect and ignores proxy settings such as HTTP_PROXY, so the
token goes only to the URL you gave. Plain http:// is accepted for this machine
(localhost, 127.0.0.1); for any other host use https://, or pass
allow_insecure_http=True on a network you trust.
What it does not do
- It cannot stop a call that is already running. Revoking a task stops new decisions. A call that was allowed and has started finishes on your side.
- It never sees results. It records what you report. If no report arrives within the server's lease (60 seconds by default), it records the call as failed with an unknown effect and charges its full cost.
- Resource templates cannot look up who owns a resource. Grant the exact resources a task
needs. When the owner has to be checked, write the tool in JavaScript with its own
resolvefunction (guard library). - It does not detect prompt injection. It limits what a misled agent can do.
API
TaskClient(url, token) |
decide(tool, args) returns Allow, Deny or NeedsApproval (the HTTP API's allow, deny and require_approval). Also wait(action_id, timeout), report(action_id, "succeeded" | "failed", actual_cost), status(), run(tool, args, call), arun(...) and the tool() decorator |
AdminClient(url, admin_token) |
create_task(...), revoke_task(task_id), task_status(task_id), pending(task_id=..., tenant_id=...), approve(action_id, approver_id=...) (returns when the approval expires, in clock milliseconds), reject(action_id) |
| Exceptions | ToolDenied (nothing ran), ApprovalPending (nothing ran yet), ServiceError (the server refused the request or could not be reached), all subclasses of GuardError |
Licensed under Apache-2.0.
Metadata
Release files for shieldaai-agent-guard 0.1.0.dev0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| shieldaai_agent_guard-0.1.0.dev0.tar.gz | 20.5 kB | Without provenance | Details for shieldaai_agent_guard-0.1.0.dev0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| shieldaai_agent_guard-0.1.0.dev0-py3-none-any.whl | Python 3 | none | any | Details for shieldaai_agent_guard-0.1.0.dev0-py3-none-any.whl |
Total release size: 44.1 kB
Release files / shieldaai_agent_guard-0.1.0.dev0.tar.gz
| Download URL | shieldaai_agent_guard-0.1.0.dev0.tar.gz |
|---|---|
| Size | 20.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0b9000c9d11767d147d04ee2208c6056eefbc5fcae19f3695f40f0bd2b4c7852
|
|
BLAKE2b-256 checksum How to use checksums |
e6664049a0f22379d360d6ebf0b83c8293aada8b10f6bf27f27e8ce1bc1205b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / shieldaai_agent_guard-0.1.0.dev0-py3-none-any.whl
| Download URL | shieldaai_agent_guard-0.1.0.dev0-py3-none-any.whl |
|---|---|
| Size | 23.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8c135802447c57457ef9be39103d815c7c18967977b31f36049e694eba31f223
|
|
BLAKE2b-256 checksum How to use checksums |
29b22d8592e9a889ac75af1537345cb2d103f7931b526d93a016a787939a6f22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for shieldaai-agent-guard 0.1.0.dev0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.