Skip to content

Commit 17befc7

Browse files
authored
Merge pull request #11 from PredicateSystems/demo3
Demo3 - complete openclaw agent loop: pre- and post-execution loop
2 parents 8fed1a4 + 72afc29 commit 17befc7

14 files changed

+3768
-301
lines changed

README.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,58 @@ npm install predicate-claw
4747

4848
**Right pane:** The integration demo using the real `createSecureClawPlugin()` SDK—legitimate file reads succeed, while sensitive file access, dangerous shell commands, and prompt injection attacks are blocked before execution.
4949

50-
### Real Claude Code Integration
50+
### Zero-Trust AI Agent Playground
51+
#### Complete Agent Loop: Pre-execution authorization + Post-execution deterministic verification
52+
53+
![Zero-Trust Agent Demo](docs/images/openclaw_complete_loop_demo_s.gif)
54+
55+
The **Market Research Agent** demo showcases the complete **Zero-Trust architecture**:
56+
57+
```
58+
┌─────────────────────────────────────────────────────────────────────────┐
59+
│ ZERO-TRUST AI AGENT ARCHITECTURE │
60+
│ │
61+
│ ┌───────────────┐ ┌─────────────────┐ ┌───────────────────────┐ │
62+
│ │ LLM/Agent │───▶│ PRE-EXECUTION │───▶│ POST-EXECUTION │ │
63+
│ │ (Claude) │ │ GATE │ │ VERIFICATION │ │
64+
│ └───────────────┘ │ (Sidecar) │ │ (SDK Predicates) │ │
65+
│ │ ALLOW / DENY │ │ PASS / FAIL │ │
66+
│ └─────────────────┘ └───────────────────────┘ │
67+
└─────────────────────────────────────────────────────────────────────────┘
68+
```
69+
70+
- **Pre-Execution Gate:** Policy-based authorization before any action executes
71+
- **Post-Execution Verification:** Deterministic predicates verify state after execution
72+
- **Cloud Tracing:** Full observability with screenshots in [Predicate Studio](https://www.predicatesystems.ai/studio)
73+
74+
```bash
75+
cd examples/real-openclaw-demo
76+
export ANTHROPIC_API_KEY="sk-ant-..."
77+
./run-playground.sh
78+
```
79+
80+
See [Zero-Trust Agent Demo](examples/real-openclaw-demo/README.md) for full instructions.
81+
82+
### Token-Saving Snapshot Skill
83+
84+
The `predicate-snapshot` skill is a **game-changer for token efficiency**. Instead of sending full page HTML or full accessbility tree (A11y) to the LLM (tens of thousands of tokens), it captures structured DOM snapshots with only actionable elements:
85+
86+
```typescript
87+
// Traditional approach: 50,000+ tokens of raw HTML
88+
const html = await page.content();
89+
90+
// With predicate-snapshot: ~500 tokens of structured data
91+
const snapshot = await agentRuntime.snapshot({
92+
screenshot: { format: "jpeg", quality: 80 },
93+
use_api: true,
94+
limit: 50, // Top 50 interactive elements
95+
});
96+
// Returns: { elements: [...], text: "...", screenshot: "base64..." }
97+
```
98+
99+
**Token savings: 90-99%** while maintaining all information the LLM needs to act.
100+
101+
### Legacy Claude Code Integration
51102

52103
We also provide a **real Claude Code demo** that uses actual Anthropic API calls with SecureClaw hooks intercepting every tool call. See the [Real OpenClaw Demo](examples/real-openclaw-demo/README.md) for instructions.
53104

@@ -348,6 +399,7 @@ However, when deploying a fleet of AI agents in regulated environments (FinTech,
348399

349400
| Project | Description |
350401
|---------|-------------|
402+
| [@predicatesystems/runtime](https://www.npmjs.com/package/@predicatesystems/runtime) | Runtime SDK with snapshot, predicates, and cloud tracing |
351403
| [predicate-authority-sidecar](https://github.com/PredicateSystems/predicate-authority-sidecar) | Rust policy engine |
352404
| [predicate-authority-ts](https://github.com/PredicateSystems/predicate-authority-ts) | TypeScript SDK |
353405
| [predicate-authority](https://github.com/PredicateSystems/predicate-authority) | Python SDK |
10.3 MB
Loading
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Agent Runtime Container for AI Agent Playground
2+
#
3+
# Ubuntu 24.04 LTS with:
4+
# - Node.js 22.x
5+
# - Playwright with browser binaries (Chromium, Firefox, WebKit)
6+
# - @predicatesystems/runtime SDK
7+
# - Python 3.12 (optional, for webbench agents)
8+
# - Non-root user: agentuser
9+
#
10+
# Usage:
11+
# docker build -f Dockerfile.playground -t agent-runtime .
12+
# docker run -it --rm agent-runtime bash
13+
14+
FROM ubuntu:24.04
15+
16+
# Prevent interactive prompts during package installation
17+
ENV DEBIAN_FRONTEND=noninteractive
18+
19+
# Install base dependencies and Node.js 22.x
20+
RUN apt-get update && apt-get install -y \
21+
curl \
22+
ca-certificates \
23+
gnupg \
24+
git \
25+
jq \
26+
# Python 3.12 for webbench agents (optional)
27+
python3.12 \
28+
python3-pip \
29+
python3-venv \
30+
&& rm -rf /var/lib/apt/lists/*
31+
32+
# Install Node.js 22.x from NodeSource
33+
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
34+
&& apt-get install -y nodejs \
35+
&& rm -rf /var/lib/apt/lists/*
36+
37+
# Install Playwright system dependencies
38+
# These are required for Chromium, Firefox, and WebKit browsers
39+
RUN apt-get update && apt-get install -y \
40+
# Core libraries
41+
libnss3 \
42+
libnspr4 \
43+
libatk1.0-0 \
44+
libatk-bridge2.0-0 \
45+
libcups2 \
46+
libdrm2 \
47+
libxkbcommon0 \
48+
libxcomposite1 \
49+
libxdamage1 \
50+
libxfixes3 \
51+
libxrandr2 \
52+
libgbm1 \
53+
libasound2t64 \
54+
libpango-1.0-0 \
55+
libcairo2 \
56+
# Firefox dependencies
57+
libdbus-glib-1-2 \
58+
# WebKit dependencies
59+
libwoff1 \
60+
libharfbuzz-icu0 \
61+
libgstreamer-plugins-base1.0-0 \
62+
libgstreamer-gl1.0-0 \
63+
libgstreamer-plugins-bad1.0-0 \
64+
libenchant-2-2 \
65+
libsecret-1-0 \
66+
libhyphen0 \
67+
libmanette-0.2-0 \
68+
libgles2 \
69+
# Fonts for rendering
70+
fonts-noto-color-emoji \
71+
fonts-noto-cjk \
72+
fonts-freefont-ttf \
73+
# X11 virtual framebuffer for headless
74+
xvfb \
75+
&& rm -rf /var/lib/apt/lists/*
76+
77+
# Create non-root user for security
78+
# This is required for Playwright and Claude Code's --dangerously-skip-permissions
79+
# Use UID 1001 to avoid conflict with existing ubuntu user (UID 1000)
80+
RUN useradd -m -s /bin/bash -u 1001 agentuser
81+
82+
# Create directories with proper permissions
83+
RUN mkdir -p /app /data /workspace \
84+
&& chown -R agentuser:agentuser /app /data /workspace
85+
86+
WORKDIR /app
87+
88+
# Copy SDK source for building (as root for npm install)
89+
COPY --chown=agentuser:agentuser package*.json ./
90+
COPY --chown=agentuser:agentuser tsconfig.json ./
91+
COPY --chown=agentuser:agentuser src/ ./src/
92+
93+
# Install dependencies and build SDK
94+
RUN npm install && npm run build
95+
96+
# Install Playwright CLI and browsers as agentuser
97+
USER agentuser
98+
99+
# Set Playwright browser path
100+
ENV PLAYWRIGHT_BROWSERS_PATH=/home/agentuser/.cache/ms-playwright
101+
102+
# Install Playwright browsers (Chromium only by default for faster builds)
103+
# Add firefox and webkit if needed: npx playwright install firefox webkit
104+
RUN npx playwright install chromium
105+
106+
# Switch back to root temporarily to set up remaining items
107+
USER root
108+
109+
# Copy demo workspace files
110+
COPY --chown=agentuser:agentuser examples/real-openclaw-demo/workspace/ /workspace/
111+
112+
# Copy agent source files (market research agent)
113+
COPY --chown=agentuser:agentuser examples/real-openclaw-demo/src/ /app/examples/real-openclaw-demo/src/
114+
115+
# Copy SecureClaw hook script (if using Claude Code integration)
116+
COPY --chown=agentuser:agentuser examples/real-openclaw-demo/secureclaw-hook.sh /app/secureclaw-hook.sh
117+
RUN chmod +x /app/secureclaw-hook.sh
118+
119+
# Install tsx for running TypeScript directly
120+
RUN npm install -g tsx
121+
122+
# Create data directory with proper permissions
123+
RUN mkdir -p /data && chown -R agentuser:agentuser /data
124+
125+
# Switch to non-root user for execution
126+
USER agentuser
127+
128+
# Set working directory
129+
WORKDIR /app
130+
131+
# Environment variables
132+
ENV HOME=/home/agentuser
133+
ENV NODE_ENV=production
134+
ENV PREDICATE_SIDECAR_URL=http://predicate-sidecar:8000
135+
ENV SECURECLAW_PRINCIPAL=agent:market-research
136+
ENV SECURECLAW_VERBOSE=true
137+
138+
# Health check
139+
HEALTHCHECK --interval=10s --timeout=5s --retries=3 \
140+
CMD node -e "console.log('ok')" || exit 1
141+
142+
# Default: run the market research agent
143+
CMD ["npx", "tsx", "/app/examples/real-openclaw-demo/src/market-research-agent.ts"]

0 commit comments

Comments
 (0)