@@ -26,6 +26,10 @@ def create_tracer(
2626 api_url : str | None = None ,
2727 logger : SentienceLogger | None = None ,
2828 upload_trace : bool = False ,
29+ goal : str | None = None ,
30+ agent_type : str | None = None ,
31+ llm_model : str | None = None ,
32+ start_url : str | None = None ,
2933) -> Tracer :
3034 """
3135 Create tracer with automatic tier detection.
@@ -44,13 +48,26 @@ def create_tracer(
4448 upload_trace: Enable cloud trace upload (default: False). When True and api_key
4549 is provided, traces will be uploaded to cloud. When False, traces
4650 are saved locally only.
51+ goal: User's goal/objective for this trace run. This will be displayed as the
52+ trace name in the frontend. Should be descriptive and action-oriented.
53+ Example: "Add wireless headphones to cart on Amazon"
54+ agent_type: Type of agent running (e.g., "SentienceAgent", "CustomAgent")
55+ llm_model: LLM model used (e.g., "gpt-4-turbo", "claude-3-5-sonnet")
56+ start_url: Starting URL of the agent run (e.g., "https://amazon.com")
4757
4858 Returns:
4959 Tracer configured with appropriate sink
5060
5161 Example:
52- >>> # Pro tier user
53- >>> tracer = create_tracer(api_key="sk_pro_xyz", run_id="demo")
62+ >>> # Pro tier user with goal
63+ >>> tracer = create_tracer(
64+ ... api_key="sk_pro_xyz",
65+ ... run_id="demo",
66+ ... goal="Add headphones to cart",
67+ ... agent_type="SentienceAgent",
68+ ... llm_model="gpt-4-turbo",
69+ ... start_url="https://amazon.com"
70+ ... )
5471 >>> # Returns: Tracer with CloudTraceSink
5572 >>>
5673 >>> # Free tier user
@@ -75,11 +92,28 @@ def create_tracer(
7592 # 1. Try to initialize Cloud Sink (Pro/Enterprise tier) if upload enabled
7693 if api_key and upload_trace :
7794 try :
95+ # Build metadata object for trace initialization
96+ # Only include non-empty fields to avoid sending empty strings
97+ metadata : dict [str , str ] = {}
98+ if goal and goal .strip ():
99+ metadata ["goal" ] = goal .strip ()
100+ if agent_type and agent_type .strip ():
101+ metadata ["agent_type" ] = agent_type .strip ()
102+ if llm_model and llm_model .strip ():
103+ metadata ["llm_model" ] = llm_model .strip ()
104+ if start_url and start_url .strip ():
105+ metadata ["start_url" ] = start_url .strip ()
106+
107+ # Build request payload
108+ payload : dict [str , Any ] = {"run_id" : run_id }
109+ if metadata :
110+ payload ["metadata" ] = metadata
111+
78112 # Request pre-signed upload URL from backend
79113 response = requests .post (
80114 f"{ api_url } /v1/traces/init" ,
81115 headers = {"Authorization" : f"Bearer { api_key } " },
82- json = { "run_id" : run_id } ,
116+ json = payload ,
83117 timeout = 10 ,
84118 )
85119
0 commit comments