1- from typing import Optional
2-
31"""
42Tracer factory with automatic tier detection.
53
108import os
119import uuid
1210from pathlib import Path
13- from typing import Any
11+ from typing import Any , Optional
12+ from collections .abc import Callable
1413
1514import requests
1615
@@ -31,6 +30,7 @@ def create_tracer(
3130 agent_type : str | None = None ,
3231 llm_model : str | None = None ,
3332 start_url : str | None = None ,
33+ screenshot_processor : Callable [[str ], str ] | None = None ,
3434) -> Tracer :
3535 """
3636 Create tracer with automatic tier detection.
@@ -55,6 +55,9 @@ def create_tracer(
5555 agent_type: Type of agent running (e.g., "SentienceAgent", "CustomAgent")
5656 llm_model: LLM model used (e.g., "gpt-4-turbo", "claude-3-5-sonnet")
5757 start_url: Starting URL of the agent run (e.g., "https://amazon.com")
58+ screenshot_processor: Optional function to process screenshots before upload.
59+ Takes base64 string, returns processed base64 string.
60+ Useful for PII redaction or custom image processing.
5861
5962 Returns:
6063 Tracer configured with appropriate sink
@@ -71,6 +74,17 @@ def create_tracer(
7174 ... )
7275 >>> # Returns: Tracer with CloudTraceSink
7376 >>>
77+ >>> # With screenshot processor for PII redaction
78+ >>> def redact_pii(screenshot_base64: str) -> str:
79+ ... # Your custom redaction logic
80+ ... return redacted_screenshot
81+ >>>
82+ >>> tracer = create_tracer(
83+ ... api_key="sk_pro_xyz",
84+ ... screenshot_processor=redact_pii
85+ ... )
86+ >>> # Screenshots will be processed before upload
87+ >>>
7488 >>> # Free tier user
7589 >>> tracer = create_tracer(run_id="demo")
7690 >>> # Returns: Tracer with JsonlTraceSink (local-only)
@@ -133,6 +147,7 @@ def create_tracer(
133147 api_url = api_url ,
134148 logger = logger ,
135149 ),
150+ screenshot_processor = screenshot_processor ,
136151 )
137152 else :
138153 print ("⚠️ [Sentience] Cloud init response missing upload_url" )
@@ -191,7 +206,11 @@ def create_tracer(
191206 local_path = traces_dir / f"{ run_id } .jsonl"
192207 print (f"💾 [Sentience] Local tracing: { local_path } " )
193208
194- return Tracer (run_id = run_id , sink = JsonlTraceSink (str (local_path )))
209+ return Tracer (
210+ run_id = run_id ,
211+ sink = JsonlTraceSink (str (local_path )),
212+ screenshot_processor = screenshot_processor ,
213+ )
195214
196215
197216def _recover_orphaned_traces (api_key : str , api_url : str = SENTIENCE_API_URL ) -> None :
0 commit comments