sentienceapi 0.90.17__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of sentienceapi might be problematic. Click here for more details.

Files changed (50) hide show
  1. sentience/__init__.py +153 -0
  2. sentience/_extension_loader.py +40 -0
  3. sentience/actions.py +837 -0
  4. sentience/agent.py +1246 -0
  5. sentience/agent_config.py +43 -0
  6. sentience/async_api.py +101 -0
  7. sentience/base_agent.py +194 -0
  8. sentience/browser.py +1037 -0
  9. sentience/cli.py +130 -0
  10. sentience/cloud_tracing.py +382 -0
  11. sentience/conversational_agent.py +509 -0
  12. sentience/expect.py +188 -0
  13. sentience/extension/background.js +233 -0
  14. sentience/extension/content.js +298 -0
  15. sentience/extension/injected_api.js +1473 -0
  16. sentience/extension/manifest.json +36 -0
  17. sentience/extension/pkg/sentience_core.d.ts +51 -0
  18. sentience/extension/pkg/sentience_core.js +529 -0
  19. sentience/extension/pkg/sentience_core_bg.wasm +0 -0
  20. sentience/extension/pkg/sentience_core_bg.wasm.d.ts +10 -0
  21. sentience/extension/release.json +115 -0
  22. sentience/extension/test-content.js +4 -0
  23. sentience/formatting.py +59 -0
  24. sentience/generator.py +202 -0
  25. sentience/inspector.py +365 -0
  26. sentience/llm_provider.py +637 -0
  27. sentience/models.py +412 -0
  28. sentience/overlay.py +222 -0
  29. sentience/query.py +303 -0
  30. sentience/read.py +185 -0
  31. sentience/recorder.py +589 -0
  32. sentience/schemas/trace_v1.json +216 -0
  33. sentience/screenshot.py +100 -0
  34. sentience/snapshot.py +516 -0
  35. sentience/text_search.py +290 -0
  36. sentience/trace_indexing/__init__.py +27 -0
  37. sentience/trace_indexing/index_schema.py +111 -0
  38. sentience/trace_indexing/indexer.py +357 -0
  39. sentience/tracer_factory.py +211 -0
  40. sentience/tracing.py +285 -0
  41. sentience/utils.py +296 -0
  42. sentience/wait.py +137 -0
  43. sentienceapi-0.90.17.dist-info/METADATA +917 -0
  44. sentienceapi-0.90.17.dist-info/RECORD +50 -0
  45. sentienceapi-0.90.17.dist-info/WHEEL +5 -0
  46. sentienceapi-0.90.17.dist-info/entry_points.txt +2 -0
  47. sentienceapi-0.90.17.dist-info/licenses/LICENSE +24 -0
  48. sentienceapi-0.90.17.dist-info/licenses/LICENSE-APACHE +201 -0
  49. sentienceapi-0.90.17.dist-info/licenses/LICENSE-MIT +21 -0
  50. sentienceapi-0.90.17.dist-info/top_level.txt +1 -0
@@ -0,0 +1,43 @@
1
+ """
2
+ Configuration classes for Sentience agents.
3
+ """
4
+
5
+ from dataclasses import dataclass
6
+
7
+
8
+ @dataclass
9
+ class AgentConfig:
10
+ """
11
+ Configuration for Sentience Agent execution.
12
+
13
+ This dataclass provides centralized configuration for agent behavior,
14
+ including snapshot limits, retry logic, verification, and screenshot capture.
15
+
16
+ Attributes:
17
+ snapshot_limit: Maximum elements to include in LLM context (default: 50)
18
+ temperature: LLM temperature 0.0-1.0 for response generation (default: 0.0)
19
+ max_retries: Number of retries on action failure (default: 1)
20
+ verify: Whether to run verification step after actions (default: True)
21
+ capture_screenshots: Whether to capture screenshots during execution (default: True)
22
+ screenshot_format: Screenshot format 'png' or 'jpeg' (default: 'jpeg')
23
+ screenshot_quality: JPEG quality 1-100, ignored for PNG (default: 80)
24
+
25
+ Example:
26
+ >>> from sentience import AgentConfig, SentienceAgent
27
+ >>> config = AgentConfig(
28
+ ... snapshot_limit=100,
29
+ ... max_retries=2,
30
+ ... verify=True
31
+ ... )
32
+ >>> agent = SentienceAgent(browser, llm, config=config)
33
+ """
34
+
35
+ snapshot_limit: int = 50
36
+ temperature: float = 0.0
37
+ max_retries: int = 1
38
+ verify: bool = True
39
+
40
+ # Screenshot options
41
+ capture_screenshots: bool = True
42
+ screenshot_format: str = "jpeg" # "png" or "jpeg"
43
+ screenshot_quality: int = 80 # 1-100 (for JPEG only)
sentience/async_api.py ADDED
@@ -0,0 +1,101 @@
1
+ """
2
+ Async API for Sentience SDK - Convenience re-exports
3
+
4
+ This module re-exports all async functions for backward compatibility and developer convenience.
5
+ You can also import directly from their respective modules:
6
+
7
+ # Option 1: From async_api (recommended for convenience)
8
+ from sentience.async_api import (
9
+ AsyncSentienceBrowser,
10
+ snapshot_async,
11
+ click_async,
12
+ wait_for_async,
13
+ screenshot_async,
14
+ find_text_rect_async,
15
+ # ... all async functions in one place
16
+ )
17
+
18
+ # Option 2: From respective modules (also works)
19
+ from sentience.browser import AsyncSentienceBrowser
20
+ from sentience.snapshot import snapshot_async
21
+ from sentience.actions import click_async
22
+ """
23
+
24
+ # ========== Actions (Phase 1) ==========
25
+ # Re-export async action functions from actions.py
26
+ from sentience.actions import click_async, click_rect_async, press_async, type_text_async
27
+
28
+ # ========== Phase 2C: Agent Layer ==========
29
+ # Re-export async agent classes from agent.py and base_agent.py
30
+ from sentience.agent import SentienceAgentAsync
31
+ from sentience.base_agent import BaseAgentAsync
32
+
33
+ # ========== Browser ==========
34
+ # Re-export AsyncSentienceBrowser from browser.py (moved there for better organization)
35
+ from sentience.browser import AsyncSentienceBrowser
36
+
37
+ # Re-export async expect functions from expect.py
38
+ from sentience.expect import ExpectationAsync, expect_async
39
+ from sentience.inspector import InspectorAsync, inspect_async
40
+
41
+ # Re-export async overlay functions from overlay.py
42
+ from sentience.overlay import clear_overlay_async, show_overlay_async
43
+
44
+ # ========== Query Functions (Pure Functions - No Async Needed) ==========
45
+ # Re-export query functions (pure functions, no async needed)
46
+ from sentience.query import find, query
47
+
48
+ # ========== Phase 2B: Supporting Utilities ==========
49
+ # Re-export async read function from read.py
50
+ from sentience.read import read_async
51
+
52
+ # ========== Phase 2D: Developer Tools ==========
53
+ # Re-export async recorder and inspector from their modules
54
+ from sentience.recorder import RecorderAsync, record_async
55
+
56
+ # Re-export async screenshot function from screenshot.py
57
+ from sentience.screenshot import screenshot_async
58
+
59
+ # ========== Snapshot (Phase 1) ==========
60
+ # Re-export async snapshot functions from snapshot.py
61
+ from sentience.snapshot import snapshot_async
62
+
63
+ # Re-export async text search function from text_search.py
64
+ from sentience.text_search import find_text_rect_async
65
+
66
+ # ========== Phase 2A: Core Utilities ==========
67
+ # Re-export async wait function from wait.py
68
+ from sentience.wait import wait_for_async
69
+
70
+ __all__ = [
71
+ # Browser
72
+ "AsyncSentienceBrowser", # Re-exported from browser.py
73
+ # Snapshot (Phase 1)
74
+ "snapshot_async", # Re-exported from snapshot.py
75
+ # Actions (Phase 1)
76
+ "click_async", # Re-exported from actions.py
77
+ "type_text_async", # Re-exported from actions.py
78
+ "press_async", # Re-exported from actions.py
79
+ "click_rect_async", # Re-exported from actions.py
80
+ # Phase 2A: Core Utilities
81
+ "wait_for_async", # Re-exported from wait.py
82
+ "screenshot_async", # Re-exported from screenshot.py
83
+ "find_text_rect_async", # Re-exported from text_search.py
84
+ # Phase 2B: Supporting Utilities
85
+ "read_async", # Re-exported from read.py
86
+ "show_overlay_async", # Re-exported from overlay.py
87
+ "clear_overlay_async", # Re-exported from overlay.py
88
+ "expect_async", # Re-exported from expect.py
89
+ "ExpectationAsync", # Re-exported from expect.py
90
+ # Phase 2C: Agent Layer
91
+ "SentienceAgentAsync", # Re-exported from agent.py
92
+ "BaseAgentAsync", # Re-exported from base_agent.py
93
+ # Phase 2D: Developer Tools
94
+ "RecorderAsync", # Re-exported from recorder.py
95
+ "record_async", # Re-exported from recorder.py
96
+ "InspectorAsync", # Re-exported from inspector.py
97
+ "inspect_async", # Re-exported from inspector.py
98
+ # Query Functions
99
+ "find", # Re-exported from query.py
100
+ "query", # Re-exported from query.py
101
+ ]
@@ -0,0 +1,194 @@
1
+ """
2
+ BaseAgent: Abstract base class for all Sentience agents
3
+ Defines the interface that all agent implementations must follow
4
+ """
5
+
6
+ from abc import ABC, abstractmethod
7
+
8
+ from .models import ActionHistory, AgentActionResult, Element, Snapshot, TokenStats
9
+
10
+
11
+ class BaseAgent(ABC):
12
+ """
13
+ Abstract base class for all Sentience agents.
14
+
15
+ Provides a standard interface for:
16
+ - Executing natural language goals (act)
17
+ - Tracking execution history
18
+ - Monitoring token usage
19
+ - Filtering elements based on goals
20
+
21
+ Subclasses must implement:
22
+ - act(): Execute a natural language goal
23
+ - get_history(): Return execution history
24
+ - get_token_stats(): Return token usage statistics
25
+ - clear_history(): Reset history and token counters
26
+
27
+ Subclasses can override:
28
+ - filter_elements(): Customize element filtering logic
29
+ """
30
+
31
+ @abstractmethod
32
+ def act(self, goal: str, **kwargs) -> AgentActionResult:
33
+ """
34
+ Execute a natural language goal using the agent.
35
+
36
+ Args:
37
+ goal: Natural language instruction (e.g., "Click the login button")
38
+ **kwargs: Additional parameters (implementation-specific)
39
+
40
+ Returns:
41
+ AgentActionResult with execution details
42
+
43
+ Raises:
44
+ RuntimeError: If execution fails after retries
45
+ """
46
+ pass
47
+
48
+ @abstractmethod
49
+ def get_history(self) -> list[ActionHistory]:
50
+ """
51
+ Get the execution history of all actions taken.
52
+
53
+ Returns:
54
+ List of ActionHistory entries
55
+ """
56
+ pass
57
+
58
+ @abstractmethod
59
+ def get_token_stats(self) -> TokenStats:
60
+ """
61
+ Get token usage statistics for the agent session.
62
+
63
+ Returns:
64
+ TokenStats with cumulative token counts
65
+ """
66
+ pass
67
+
68
+ @abstractmethod
69
+ def clear_history(self) -> None:
70
+ """
71
+ Clear execution history and reset token counters.
72
+
73
+ This resets the agent to a clean state.
74
+ """
75
+ pass
76
+
77
+ def filter_elements(self, snapshot: Snapshot, goal: str | None = None) -> list[Element]:
78
+ """
79
+ Filter elements from a snapshot based on goal context.
80
+
81
+ Default implementation returns all elements unchanged.
82
+ Subclasses can override to implement custom filtering logic
83
+ such as:
84
+ - Removing irrelevant elements based on goal keywords
85
+ - Boosting importance of matching elements
86
+ - Filtering by role, size, or visual properties
87
+
88
+ Args:
89
+ snapshot: Current page snapshot
90
+ goal: User's goal (can inform filtering strategy)
91
+
92
+ Returns:
93
+ Filtered list of elements (default: all elements)
94
+
95
+ Example:
96
+ >>> agent = SentienceAgent(browser, llm)
97
+ >>> snap = snapshot(browser)
98
+ >>> filtered = agent.filter_elements(snap, goal="Click login")
99
+ >>> # filtered now contains only relevant elements
100
+ """
101
+ return snapshot.elements
102
+
103
+
104
+ class BaseAgentAsync(ABC):
105
+ """
106
+ Abstract base class for all async Sentience agents.
107
+
108
+ Provides a standard interface for:
109
+ - Executing natural language goals (act)
110
+ - Tracking execution history
111
+ - Monitoring token usage
112
+ - Filtering elements based on goals
113
+
114
+ Subclasses must implement:
115
+ - act(): Execute a natural language goal (async)
116
+ - get_history(): Return execution history
117
+ - get_token_stats(): Return token usage statistics
118
+ - clear_history(): Reset history and token counters
119
+
120
+ Subclasses can override:
121
+ - filter_elements(): Customize element filtering logic
122
+ """
123
+
124
+ @abstractmethod
125
+ async def act(self, goal: str, **kwargs) -> AgentActionResult:
126
+ """
127
+ Execute a natural language goal using the agent (async).
128
+
129
+ Args:
130
+ goal: Natural language instruction (e.g., "Click the login button")
131
+ **kwargs: Additional parameters (implementation-specific)
132
+
133
+ Returns:
134
+ AgentActionResult with execution details
135
+
136
+ Raises:
137
+ RuntimeError: If execution fails after retries
138
+ """
139
+ pass
140
+
141
+ @abstractmethod
142
+ def get_history(self) -> list[ActionHistory]:
143
+ """
144
+ Get the execution history of all actions taken.
145
+
146
+ Returns:
147
+ List of ActionHistory entries
148
+ """
149
+ pass
150
+
151
+ @abstractmethod
152
+ def get_token_stats(self) -> TokenStats:
153
+ """
154
+ Get token usage statistics for the agent session.
155
+
156
+ Returns:
157
+ TokenStats with cumulative token counts
158
+ """
159
+ pass
160
+
161
+ @abstractmethod
162
+ def clear_history(self) -> None:
163
+ """
164
+ Clear execution history and reset token counters.
165
+
166
+ This resets the agent to a clean state.
167
+ """
168
+ pass
169
+
170
+ def filter_elements(self, snapshot: Snapshot, goal: str | None = None) -> list[Element]:
171
+ """
172
+ Filter elements from a snapshot based on goal context.
173
+
174
+ Default implementation returns all elements unchanged.
175
+ Subclasses can override to implement custom filtering logic
176
+ such as:
177
+ - Removing irrelevant elements based on goal keywords
178
+ - Boosting importance of matching elements
179
+ - Filtering by role, size, or visual properties
180
+
181
+ Args:
182
+ snapshot: Current page snapshot
183
+ goal: User's goal (can inform filtering strategy)
184
+
185
+ Returns:
186
+ Filtered list of elements (default: all elements)
187
+
188
+ Example:
189
+ >>> agent = SentienceAgentAsync(browser, llm)
190
+ >>> snap = await snapshot_async(browser)
191
+ >>> filtered = agent.filter_elements(snap, goal="Click login")
192
+ >>> # filtered now contains only relevant elements
193
+ """
194
+ return snapshot.elements