How sriram687/agent_lease works
Agent Leash is a sandbox payment-safety gateway between autonomous agents and PayPal. Its principal flow is: an agent searches for products and requests a purchase through MCP; Leash resolves the agent’s mandate, evaluates policy, then denies, escalates for human review, or authorizes payment. Delivery events govern capture or voiding, while the cockpit provides escalation, mandate-control, and ledger views. The graph preserves documented policy and settlement stages; several integrations and handlers are TODOs or unsampled, so those links are shown only where documentation supports them.
Main entry points: server.ts MCP tools · mandates.ts Postgres data · engine.ts Policy evaluation · payment-orchestrator.ts Payment orchestration
Components 26
Gateway and access
- MCP tools
apps/gateway/src/mcp/server.ts - Mandate resolution
apps/gateway/src/auth/resolve-mandate.ts - Product search
apps/gateway/src/integrations/channel3.ts
Purchase policy
- Policy evaluation
packages/policy-engine/src/engine.ts - Rule checks
packages/policy-engine/src/layers/deterministic.ts - Semantic dedup
packages/policy-engine/src/layers/semantic-dedup.ts - Intent judge
packages/policy-engine/src/layers/llm-judge.ts - Injection screen
packages/policy-engine/src/layers/injection-screen.ts
Payment lifecycle
- Payment orchestration
apps/gateway/src/orchestrator/payment-orchestrator.ts - Webhook handling
apps/gateway/src/routes/webhooks.ts - Escalation API
apps/gateway/src/routes/escalations.ts - Mandate controls
apps/gateway/src/routes/mandates.ts
Human cockpit
- Escalation inbox
apps/cockpit/src/components/escalations/EscalationInbox.tsx - Mandate kill switch
apps/cockpit/src/components/mandates/KillSwitch.tsx - Ledger view
apps/cockpit/src/app/ledger/page.tsx - Ledger grid
apps/cockpit/src/components/ledger/LedgerGrid.tsx
Persistence and audit
- Ledger service
apps/gateway/src/ledger/ledger-service.ts - Postgres data
packages/db/src/schema/mandates.ts - Mandate records
packages/db/src/schema/mandates.ts - Purchase records
packages/db/src/schema/purchase-requests.ts
Other components
- AI agent
- Channel3
- OpenAI
- PayPal sandbox
- Demo store
apps/demo-store/src/server.ts - Human owner
Connections 30
- AI agent → MCP tools: requests via MCP
- MCP tools → Mandate resolution: resolves mandate
apps/gateway/src/mcp/server.ts - MCP tools → Product search: searches products
apps/gateway/src/mcp/server.ts - Product search → Channel3: fetches products
- MCP tools → Policy evaluation: evaluates purchase
apps/gateway/src/mcp/server.ts - Policy evaluation → Rule checks: runs rules
packages/policy-engine/src/engine.ts - Policy evaluation → Semantic dedup: checks similarity
packages/policy-engine/src/engine.ts - Policy evaluation → Intent judge: judges intent
packages/policy-engine/src/engine.ts - Policy evaluation → Injection screen: screens output
packages/policy-engine/src/engine.ts - Intent judge → OpenAI: requests judgment
packages/policy-engine/src/layers/llm-judge.ts - Semantic dedup → OpenAI: generates embeddings
packages/policy-engine/src/layers/semantic-dedup.ts - Rule checks → Postgres data: reads purchase history
packages/policy-engine/src/layers/deterministic.ts - Semantic dedup → Postgres data: queries similar items
packages/policy-engine/src/layers/semantic-dedup.ts - MCP tools → Payment orchestration: records and settles
apps/gateway/src/mcp/server.ts - Payment orchestration → PayPal sandbox: authorizes then captures
- PayPal sandbox → Webhook handling: sends payment events
- Demo store → Webhook handling: sends delivery events
- Webhook handling → Payment orchestration: triggers settlement
- MCP tools → Ledger service: appends decision
apps/gateway/src/mcp/server.ts - Ledger service → Postgres data: writes ledger entries
- Human owner → Escalation inbox: reviews requests
- Escalation inbox → Escalation API: approves or rejects
- Escalation API → Payment orchestration: resolves escalation
- Human owner → Mandate kill switch: revokes mandate
- Mandate kill switch → Mandate controls: requests revocation
- Mandate controls → Payment orchestration: voids open authorizations
- Ledger view → Ledger grid: renders entries
apps/cockpit/src/app/ledger/page.tsx - Ledger view → Postgres data: loads ledger data
apps/cockpit/src/app/ledger/page.tsx - Mandate records → Postgres data: defines mandate table
packages/db/src/schema/mandates.ts - Purchase records → Postgres data: defines request table
packages/db/src/schema/purchase-requests.ts