AgentShield
AgentShield is a Python runtime-protection SDK for AI agents. It actively blocks unsafe next operations when configured budget, duration, step, circuit, or behavioral limits are reached.
Its goal is to help developers control AI-agent execution by enforcing runtime limits such as budgets, execution steps, latency limits, and anomaly-detection policies.
Installation
AgentShield requires Python 3.12 or newer.
python -m pip install agentshield-1-sdk
For local development, install the test dependencies with:
python -m pip install -e ".[dev]"
Quick Start
Decorate an agent function and check the control gateway before each operation. Record completed steps, tool calls, and responses when the corresponding protections are enabled.
from agentshield import current_shield, shield
@shield(
budget_limit=5.0,
max_duration_seconds=60.0,
max_steps=20,
max_loops=3,
cycle_length=2,
max_tool_repetitions=6,
max_stagnation_steps=20,
)
def agent():
control = current_shield()
control.check_before_step()
control.record_tool("search")
control.record_response("The latest agent response")
control.record_step("search")
return "done"
@shield supports synchronous and asynchronous functions. Protection errors
are raised from the public control path and are available from the package
root, for example BudgetExceededError, DurationLimitExceededError,
LoopDetectedError, ToolRepetitionError, and StagnationDetectedError.
Features
- configurable budget, duration, and step limits
- token usage and estimated model cost tracking
- exact cycle, tool repetition, and response stagnation detection
- circuit-breaker enforcement with structured protection decisions
- optional bounded telemetry with failure isolation
- synchronous, asynchronous, nested, and concurrent session isolation
Who It Is For
AgentShield is for developers building Python agents that call language models, tools, or other external services and need explicit runtime limits. It is a library-level control surface. It does not execute agents, replace provider safety controls, or provide a hosted monitoring service.
Protection Controls
budget_limitblocks the next operation after recorded estimated cost reaches the configured amount.max_duration_secondslimits elapsed session time.max_stepslimits completed agent steps.max_loopsandcycle_lengthdetect exact repeated step cycles.max_tool_repetitionsdetects consecutive calls to the same tool.max_stagnation_stepsandstagnation_similaritydetect similar responses.- The circuit breaker blocks operations after a protection trip and supports cooldown and half-open probing.
The SDK can only block an operation before the caller sends it to an external
service. Call check_before_step() at that boundary and record completed
usage with record_llm_call() or record_step().
Async Usage
The same decorator works with async functions and preserves the active session across awaits:
from agentshield import current_shield, shield
@shield(budget_limit=2.0, max_duration_seconds=30.0)
async def async_agent():
control = current_shield()
control.check_before_step()
# await the external operation here
control.record_step("external-operation")
return "done"
Telemetry and Privacy
Pass an object implementing EventSink.emit(event) to receive bounded,
metadata-only events. Telemetry is disabled by default, and sink failures are
isolated from agent execution. The built-in events do not record prompts, raw
responses, tool arguments, or model outputs.
Exceptions and Support
Protection failures derive from AgentShieldError, including budget,
duration, step, loop, tool-repetition, and stagnation errors. There is no
separate support service or hosted dashboard at this time. Use the repository
issue tracker for project questions and bug reports.
Project Status
This is an early public library release. The API and model pricing table may
change as real-world use informs future releases. See CHANGELOG.md for
release history and SECURITY.md for vulnerability reporting guidance.
Commercial / Enterprise
The core SDK remains free and open source. Potential paid work is described in
COMMERCIAL.md and is intentionally limited to professional implementation,
support, policy design, security reviews, and future enterprise integrations.
No paid service, hosted dashboard, or payment system is currently represented
as active in this repository.
Telemetry is disabled unless an EventSink is supplied. By default, events
record metadata and counters rather than prompts, raw responses, tool
arguments, or model outputs.
Initial Architecture
AgentShield
│
├── src/agentshield/ Core Python SDK
└── tests/ Automated tests
Design Goal
AgentShield is designed around a simple principle:
AI agents should have enforceable runtime boundaries.
The system should make it possible for developers to define limits before an agent starts executing.
Examples include maximum estimated spend, execution steps, runtime duration, anomaly thresholds, and circuit-breaker policies.
Safety Principle
AgentShield should fail safely.
A protection mechanism must never claim that an operation was stopped if that operation has already been sent to an external service.
The SDK will therefore distinguish between:
- a decision to block the next operation
- an operation that has already started
- an operation that has completed
This distinction is important for accurate cost and execution reporting.
License
AgentShield is released under the MIT License. See LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentshield_1_sdk-0.2.3.tar.gz.
File metadata
- Download URL: agentshield_1_sdk-0.2.3.tar.gz
- Upload date:
- Size: 25.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbe8ea926f609206f72f3a0bb1f06e17dfe517b516e7650c3dce24312648907a
|
|
| MD5 |
63d6032ce73888950cb035f53019566a
|
|
| BLAKE2b-256 |
3b71c6caa92b430a6b9d4d1e817ccb33515ddcb4c6fb874d0b4b13b02257a5eb
|
Provenance
The following attestation bundles were made for agentshield_1_sdk-0.2.3.tar.gz:
Publisher:
release.yml on SnapNutri/agentshield-1-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agentshield_1_sdk-0.2.3.tar.gz -
Subject digest:
fbe8ea926f609206f72f3a0bb1f06e17dfe517b516e7650c3dce24312648907a - Sigstore transparency entry: 2584182490
- Sigstore integration time:
-
Permalink:
SnapNutri/agentshield-1-sdk@cb7b7bd1bb5e41819da156b8728d9e51e5772097 -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/SnapNutri
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cb7b7bd1bb5e41819da156b8728d9e51e5772097 -
Trigger Event:
push
-
Statement type:
File details
Details for the file agentshield_1_sdk-0.2.3-py3-none-any.whl.
File metadata
- Download URL: agentshield_1_sdk-0.2.3-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00b74e7770a3083704b85b01638a69ddbdb2be691cb77b0ee803223da707b065
|
|
| MD5 |
e979cb416eab026ffc49eec4f55e514b
|
|
| BLAKE2b-256 |
4de9b5e54a0d3e0da3060a8a06feabed97ef2c4849914f59bec3ee65ff061ed0
|
Provenance
The following attestation bundles were made for agentshield_1_sdk-0.2.3-py3-none-any.whl:
Publisher:
release.yml on SnapNutri/agentshield-1-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agentshield_1_sdk-0.2.3-py3-none-any.whl -
Subject digest:
00b74e7770a3083704b85b01638a69ddbdb2be691cb77b0ee803223da707b065 - Sigstore transparency entry: 2584182806
- Sigstore integration time:
-
Permalink:
SnapNutri/agentshield-1-sdk@cb7b7bd1bb5e41819da156b8728d9e51e5772097 -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/SnapNutri
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cb7b7bd1bb5e41819da156b8728d9e51e5772097 -
Trigger Event:
push
-
Statement type: