Refactor message handling and error logging in agent and gateway

- Updated the AIAgent class to extract the first user message for trajectory formatting, improving the accuracy of user queries in the trajectory format.
- Enhanced the GatewayRunner to convert transcript history into the agent format, ensuring proper handling of message roles and content.
- Adjusted the typing indicator refresh rate to every 2 seconds for better responsiveness.
- Improved error handling in the message sending process for the Telegram adapter, implementing a fallback mechanism for Markdown parsing failures, and logging send failures for better debugging.
This commit is contained in:
teknium1 2026-02-03 15:42:54 -08:00
parent 212460289b
commit beeb7896e0
4 changed files with 56 additions and 16 deletions

View file

@ -1272,9 +1272,16 @@ class AIAgent:
return
try:
# Convert to trajectory format (reuse existing method)
# Use empty string as user_query since it's embedded in messages
trajectory = self._convert_to_trajectory_format(messages, "", True)
# Extract the first user message for the trajectory format
# The first message should be the user's initial query
first_user_query = ""
for msg in messages:
if msg.get("role") == "user":
first_user_query = msg.get("content", "")
break
# Convert to trajectory format
trajectory = self._convert_to_trajectory_format(messages, first_user_query, True)
# Build the session log entry
entry = {