Skip to content

Commit 059a75e

Browse files
authored
Merge pull request #139 from SentienceAPI/enrich_asserts
Enrich asserts2
2 parents cd5c683 + e54f6c0 commit 059a75e

File tree

18 files changed

+1898
-56
lines changed

18 files changed

+1898
-56
lines changed

.github/workflows/test.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,34 @@ jobs:
4141
run: |
4242
echo "=== Installed sentience location ==="
4343
python -c "import sentience; print(sentience.__file__)"
44-
echo "=== Check assert_done source code ==="
44+
echo "=== Check assert_done in installed package ==="
4545
python -c "
4646
import inspect
4747
from sentience.agent_runtime import AgentRuntime
4848
source = inspect.getsource(AgentRuntime.assert_done)
49-
print(source[:500])
49+
print(source)
5050
if 'assertTrue' in source:
5151
print('ERROR: assertTrue found in installed package!')
5252
exit(1)
5353
else:
5454
print('Good: assert_ is correctly used')
5555
"
5656
57+
- name: Verify source code
58+
shell: bash
59+
run: |
60+
echo "=== Checking agent_runtime.py line 345 ==="
61+
sed -n '340,350p' sentience/agent_runtime.py
62+
echo "=== Verifying assert_ method exists ==="
63+
grep -n "def assert_" sentience/agent_runtime.py
64+
echo "=== Checking for assertTrue (should NOT exist) ==="
65+
if grep -n "assertTrue" sentience/agent_runtime.py; then
66+
echo "ERROR: Found assertTrue - this should have been removed!"
67+
exit 1
68+
else
69+
echo "Good: no assertTrue found"
70+
fi
71+
5772
- name: Lint with pre-commit
5873
continue-on-error: true
5974
run: |

examples/agent_runtime_verification.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
The AgentRuntime provides assertion predicates to verify browser state during execution.
66
77
Key features:
8-
- BrowserBackendV0 protocol: Framework-agnostic browser integration
8+
- BrowserBackend protocol: Framework-agnostic browser integration
99
- Predicate helpers: url_matches, url_contains, exists, not_exists, element_count
1010
- Combinators: all_of, any_of for complex conditions
1111
- Task completion: assert_done() for goal verification
@@ -44,7 +44,7 @@ async def main():
4444
page = await browser.new_page()
4545

4646
# 3. Create AgentRuntime using from_sentience_browser factory
47-
# This wraps the browser/page into the new BrowserBackendV0 architecture
47+
# This wraps the browser/page into the new BrowserBackend architecture
4848
runtime = await AgentRuntime.from_sentience_browser(
4949
browser=browser,
5050
page=page,

examples/browser-use/agent_runtime_browser_use.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""
22
Example: Agent Runtime with browser-use Integration
33
4-
Demonstrates how to use AgentRuntime with browser-use library via BrowserBackendV0 protocol.
4+
Demonstrates how to use AgentRuntime with browser-use library via BrowserBackend protocol.
55
This pattern enables framework-agnostic browser integration for agent verification loops.
66
77
Key features:
88
- BrowserUseAdapter: Wraps browser-use BrowserSession into CDPBackendV0
9-
- BrowserBackendV0 protocol: Minimal interface for browser operations
9+
- BrowserBackend protocol: Minimal interface for browser operations
1010
- Direct AgentRuntime construction: No need for from_sentience_browser factory
1111
1212
Requirements:
@@ -58,7 +58,7 @@ async def main():
5858
await session.start()
5959

6060
try:
61-
# 3. Create BrowserBackendV0 using BrowserUseAdapter
61+
# 3. Create BrowserBackend using BrowserUseAdapter
6262
# This wraps the browser-use session into the standard backend protocol
6363
adapter = BrowserUseAdapter(session)
6464
backend = await adapter.create_backend()

sentience/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# Backend-agnostic actions (aliased to avoid conflict with existing actions)
2020
# Browser backends (for browser-use integration)
2121
from .backends import (
22-
BrowserBackendV0,
22+
BrowserBackend,
2323
BrowserUseAdapter,
2424
BrowserUseCDPTransport,
2525
CachedSnapshot,
@@ -132,7 +132,7 @@
132132
"verify_extension_version",
133133
"verify_extension_version_async",
134134
# Browser backends (for browser-use integration)
135-
"BrowserBackendV0",
135+
"BrowserBackend",
136136
"CDPTransport",
137137
"CDPBackendV0",
138138
"PlaywrightBackend",

sentience/agent_runtime.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Agent runtime for verification loop support.
33
44
This module provides a thin runtime wrapper that combines:
5-
1. Browser session management (via BrowserBackendV0 protocol)
5+
1. Browser session management (via BrowserBackend protocol)
66
2. Snapshot/query helpers
77
3. Tracer for event emission
88
4. Assertion/verification methods
@@ -72,7 +72,7 @@
7272
if TYPE_CHECKING:
7373
from playwright.async_api import Page
7474

75-
from .backends.protocol_v0 import BrowserBackendV0
75+
from .backends.protocol import BrowserBackend
7676
from .browser import AsyncSentienceBrowser
7777
from .tracing import Tracer
7878

@@ -90,7 +90,7 @@ class AgentRuntime:
9090
to the tracer for Studio timeline display.
9191
9292
Attributes:
93-
backend: BrowserBackendV0 instance for browser operations
93+
backend: BrowserBackend instance for browser operations
9494
tracer: Tracer for event emission
9595
step_id: Current step identifier
9696
step_index: Current step index (0-based)
@@ -99,16 +99,16 @@ class AgentRuntime:
9999

100100
def __init__(
101101
self,
102-
backend: BrowserBackendV0,
102+
backend: BrowserBackend,
103103
tracer: Tracer,
104104
snapshot_options: SnapshotOptions | None = None,
105105
sentience_api_key: str | None = None,
106106
):
107107
"""
108-
Initialize agent runtime with any BrowserBackendV0-compatible browser.
108+
Initialize agent runtime with any BrowserBackend-compatible browser.
109109
110110
Args:
111-
backend: Any browser implementing BrowserBackendV0 protocol.
111+
backend: Any browser implementing BrowserBackend protocol.
112112
Examples:
113113
- CDPBackendV0 (for browser-use via BrowserUseAdapter)
114114
- PlaywrightBackend (future, for direct Playwright)
@@ -157,7 +157,7 @@ async def from_sentience_browser(
157157
Create AgentRuntime from AsyncSentienceBrowser (backward compatibility).
158158
159159
This factory method wraps an AsyncSentienceBrowser + Page combination
160-
into the new BrowserBackendV0-based AgentRuntime.
160+
into the new BrowserBackend-based AgentRuntime.
161161
162162
Args:
163163
browser: AsyncSentienceBrowser instance

sentience/asserts/__init__.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"""
2+
Assertion DSL for Sentience SDK.
3+
4+
This module provides a Playwright/Cypress-like assertion API for verifying
5+
browser state in agent verification loops.
6+
7+
Main exports:
8+
- E: Element query builder (filters elements by role, text, href, etc.)
9+
- expect: Expectation builder (creates predicates from queries)
10+
- in_dominant_list: Query over dominant group elements (ordinal access)
11+
12+
Example usage:
13+
from sentience.asserts import E, expect, in_dominant_list
14+
15+
# Basic presence assertions
16+
runtime.assert_(
17+
expect(E(role="button", text_contains="Save")).to_exist(),
18+
label="save_button_visible"
19+
)
20+
21+
# Visibility assertions
22+
runtime.assert_(
23+
expect(E(text_contains="Checkout")).to_be_visible(),
24+
label="checkout_visible"
25+
)
26+
27+
# Global text assertions
28+
runtime.assert_(
29+
expect.text_present("Welcome back"),
30+
label="user_logged_in"
31+
)
32+
runtime.assert_(
33+
expect.no_text("Error"),
34+
label="no_error_message"
35+
)
36+
37+
# Ordinal assertions on dominant group
38+
runtime.assert_(
39+
expect(in_dominant_list().nth(0)).to_have_text_contains("Show HN"),
40+
label="first_item_is_show_hn"
41+
)
42+
43+
# Task completion
44+
runtime.assert_done(
45+
expect.text_present("Order confirmed"),
46+
label="checkout_complete"
47+
)
48+
49+
The DSL compiles to existing Predicate functions, so it works seamlessly
50+
with AgentRuntime.assert_() and assert_done().
51+
"""
52+
53+
from .expect import EventuallyConfig, EventuallyWrapper, ExpectBuilder, expect, with_eventually
54+
from .query import E, ElementQuery, ListQuery, MultiQuery, in_dominant_list
55+
56+
__all__ = [
57+
# Query builders
58+
"E",
59+
"ElementQuery",
60+
"ListQuery",
61+
"MultiQuery",
62+
"in_dominant_list",
63+
# Expectation builders
64+
"expect",
65+
"ExpectBuilder",
66+
# Eventually helpers
67+
"with_eventually",
68+
"EventuallyWrapper",
69+
"EventuallyConfig",
70+
]

0 commit comments

Comments
 (0)