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

@ -446,11 +446,16 @@ class GatewayRunner:
tool_progress_callback=progress_callback if tool_progress_enabled else None,
)
# If we have history, we need to restore it
# For now, we pass the message directly
# TODO: Implement proper history restoration
# Convert transcript history to agent format
# Transcript has timestamps; agent expects {"role": ..., "content": ...}
agent_history = []
for msg in history:
role = msg.get("role")
content = msg.get("content")
if role and content:
agent_history.append({"role": role, "content": content})
result = agent.run_conversation(message)
result = agent.run_conversation(message, conversation_history=agent_history)
# Return final response, or a message if something went wrong
final_response = result.get("final_response")