AI agents can generate actions. But they do not understand consequences.
Without a validation layer, an agent can break invariants, corrupt system state, or execute operations it was never supposed to run.
TrustLayer sits between the agent and execution. Every action is checked before it happens.
How it works
AI Agent --> Proposal --> TrustLayer --> Execution
^
Constraints
Every update passes through four gates:
- Auth - is the token valid and unexpired?
- Locks - is the target key frozen?
- Constraints - does the new state pass all rules?
- Rollback - if anything fails, state is fully restored
Quick example
The agent tries to set C = 100. The system enforces C = B + 5. TrustLayer rejects the action before any state changes. The agent retries with C = 25. Accepted.
--- Agent Attempt 1 ---
Goal: Force C = 100
REJECTED: Would break constraint (C must equal B + 5)
System prevented invalid state.
--- Agent Attempt 2 ---
Adjusting strategy...
ACCEPTED: State remains consistent
Final State: {A: 10, B: 20, C: 25}
Code
from trustlayer import (
Agent, AuthorityLevel, AuthToken, Cathedral,
LambdaConstraint, RetryConfig, State, Validator,
)
SECRET = b'my-secret'
score_ok = LambdaConstraint('score_ok', lambda v: 0 <= v.get('score', 0) <= 100)
state = State(values={'score': 50})
validator = Validator(state, [score_ok], SECRET)
token = AuthToken.issue(AuthorityLevel.SYSTEM, 'agent', ttl_seconds=60, secret=SECRET)
async def model(prompt):
return json.dumps({'type': 'update', 'target': 'score', 'value': 75})
async def main():
cathedral = Cathedral(validator, Agent(model), retry=RetryConfig(max_attempts=3))
event = await cathedral.step('raise the score', token)
print(state.values)
asyncio.run(main())
Features
- Constraint-based validation with composable logic
- HMAC-signed authority tokens with TTL
- Atomic rollback on any failure
- Async agent loop with exponential backoff retry
- Zero dependencies
Run it
git clone https://github.com/AILIFE1/trustlayer
python examples/demo.py
Top comments (0)