Skip to content

Commit d4973a9

Browse files
authored
fix: switch proactive tool logging to print for Cloud Logging visibility (#4739)
2 parents 6d69ea0 + 2332a6d commit d4973a9

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

backend/utils/app_integrations.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import logging
21
import threading
32
from typing import List, Any
43
from datetime import datetime
@@ -29,8 +28,6 @@
2928
from database.vector_db import query_vectors_by_metadata
3029
import database.conversations as conversations_db
3130

32-
logger = logging.getLogger(__name__)
33-
3431

3532
def _json_serialize_datetime(obj: Any) -> Any:
3633
"""Helper function to recursively convert datetime objects to ISO format strings for JSON serialization"""
@@ -247,7 +244,7 @@ def _process_tools(
247244
resp = llm_with_tools.invoke(llm_messages)
248245

249246
if not resp.tool_calls:
250-
logger.info(f"proactive_tool_decision uid={uid} triggered=false")
247+
print(f"proactive_tool_decision triggered=false", uid)
251248
return []
252249

253250
results = []
@@ -257,18 +254,14 @@ def _process_tools(
257254
confidence = tool_args.get("confidence", 0)
258255
notification_text = tool_args.get("notification_text", "")
259256

260-
logger.info(
261-
f"proactive_tool_decision uid={uid} triggered=true "
262-
f"tool={tool_name} confidence={confidence:.2f} "
263-
f"rationale={tool_args.get('rationale', tool_args.get('conflict_description', ''))[:100]}"
264-
)
257+
print(f"proactive_tool_decision triggered=true tool={tool_name} confidence={confidence:.2f}", uid)
265258

266259
if confidence < confidence_threshold:
267-
logger.info(f"proactive_tool_below_threshold uid={uid} tool={tool_name} confidence={confidence:.2f}")
260+
print(f"proactive_tool_below_threshold tool={tool_name} confidence={confidence:.2f}", uid)
268261
continue
269262

270263
if not notification_text or len(notification_text) < 5:
271-
logger.warning(f"proactive_tool_empty_text uid={uid} tool={tool_name}")
264+
print(f"proactive_tool_empty_text tool={tool_name}", uid)
272265
continue
273266

274267
if len(notification_text) > 300:
@@ -282,11 +275,11 @@ def _process_tools(
282275
}
283276
)
284277

285-
logger.info(f"proactive_tool_results uid={uid} total_calls={len(resp.tool_calls)} accepted={len(results)}")
278+
print(f"proactive_tool_results total_calls={len(resp.tool_calls)} accepted={len(results)}", uid)
286279
return results
287280

288281
except Exception as e:
289-
logger.error(f"proactive_tool_error uid={uid} error={e}")
282+
print(f"proactive_tool_error error={e}", uid)
290283
return []
291284

292285

@@ -327,7 +320,7 @@ def _build_tool_context(
327320
goals_text = "\n".join(f"- {g.get('title', g.get('description', 'Unnamed goal'))}" for g in goals)
328321
context_parts.append(f"{user_name}'s active goals:\n{goals_text}")
329322
except Exception as e:
330-
logger.warning(f"Failed to fetch goals for uid={uid}: {e}")
323+
print(f"proactive_tool_goals_fetch_failed error={e}", uid)
331324

332325
# Substitute template placeholders.
333326
# Mentor prompt uses {{x}} in source, but .format(text=...) converts {{x}} to {x},
@@ -401,7 +394,7 @@ def _process_proactive_notification(uid: str, app: App, data, tools: list = None
401394
tool_results = _process_tools(uid, system_prompt, user_message, tools, PROACTIVE_CONFIDENCE_THRESHOLD)
402395
for noti in tool_results:
403396
send_app_notification(uid, app.name, app.id, noti['notification_text'])
404-
logger.info(f"Sent proactive tool notification to user {uid} (tool: {noti.get('tool_name')})")
397+
print(f"proactive_tool_sent tool={noti.get('tool_name')}", uid)
405398

406399
# Main prompt-based notification
407400
message = get_proactive_message(uid, prompt, filter_scopes, context, chat_messages, user_name, user_facts)

0 commit comments

Comments
 (0)