@@ -78,6 +78,68 @@ async function main(): Promise<void> {
7878void main ();
7979```
8080
81+ ## SentienceDebugger: attach to your existing agent framework (sidecar mode)
82+
83+ If you already have an agent loop (LangGraph, custom planner/executor), keep it and attach Sentience as a ** verifier + trace layer** .
84+
85+ Key idea: your agent still executes actions — Sentience ** snapshots and verifies outcomes** .
86+
87+ ``` ts
88+ import type { Page } from ' playwright' ;
89+ import { SentienceDebugger , Tracer , JsonlTraceSink , exists , urlContains } from ' sentienceapi' ;
90+
91+ async function runExistingAgent(page : Page ): Promise <void > {
92+ const tracer = new Tracer (' run-123' , new JsonlTraceSink (' trace.jsonl' ));
93+ const dbg = SentienceDebugger .attach (page , tracer );
94+
95+ await dbg .step (' agent_step: navigate + verify' , async () => {
96+ // 1) Let your framework do whatever it does
97+ await yourAgent .step ();
98+
99+ // 2) Snapshot what the agent produced
100+ await dbg .snapshot ({ limit: 60 });
101+
102+ // 3) Verify outcomes (with bounded retries)
103+ await dbg
104+ .check (urlContains (' example.com' ), ' on_domain' , true )
105+ .eventually ({ timeoutMs: 10_000 });
106+ await dbg .check (exists (' role=heading' ), ' has_heading' ).eventually ({ timeoutMs: 10_000 });
107+ });
108+ }
109+ ```
110+
111+ ## SDK-driven full loop (snapshots + actions)
112+
113+ If you want Sentience to drive the loop end-to-end, you can use the SDK primitives directly: take a snapshot, select elements, act, then verify.
114+
115+ ``` ts
116+ import { SentienceBrowser , snapshot , find , typeText , click , waitFor } from ' sentienceapi' ;
117+
118+ async function loginExample(): Promise <void > {
119+ const browser = new SentienceBrowser ();
120+ await browser .start ();
121+ const page = browser .getPage ();
122+ if (! page ) throw new Error (' no page' );
123+
124+ await page .goto (' https://example.com/login' );
125+
126+ const snap = await snapshot (browser );
127+ const email = find (snap , " role=textbox text~'email'" );
128+ const password = find (snap , " role=textbox text~'password'" );
129+ const submit = find (snap , " role=button text~'sign in'" );
130+ if (! email || ! password || ! submit ) throw new Error (' login form not found' );
131+
132+ await typeText (browser , email .id , ' user@example.com' );
133+ await typeText (browser , password .id , ' password123' );
134+ await click (browser , submit .id );
135+
136+ const ok = await waitFor (browser , " role=heading text~'Dashboard'" , 10_000 );
137+ if (! ok .found ) throw new Error (' login failed' );
138+
139+ await browser .close ();
140+ }
141+ ```
142+
81143## Capabilities (lifecycle guarantees)
82144
83145### Controlled perception
0 commit comments