Modify the Telegram agent to store traces when tools are executed.
When Ava executes a tool (python_exec, run_bash, read_file, etc.), we need to: 1. Record the start time 2. Execute the tool 3. Store the trace with input, output, and duration 4. Return the trace ID for use in response messages
This is where tool calls are processed. Look for where Engine.toolExecute is called.
The tool execution engine. May need to modify the execution wrapper here instead.
In the Telegram message handler, wrap tool execution:
executeToolWithTrace :: Connection -> Tool -> Value -> IO (Value, Text) executeToolWithTrace conn tool input = do startTime <- getCurrentTime result <- Engine.toolExecute tool input endTime <- getCurrentTime let durationMs = round (diffUTCTime endTime startTime * 1000) traceId <- insertTrace conn TraceRecord { traceToolName = Engine.toolName tool , traceInput = input , traceOutput = result , traceDurationMs = durationMs , traceUserId = ... -- from message context , traceChatId = ... -- from message context } pure (result, traceId)
Add tracing to the Engine module itself. This captures all tool executions but loses Telegram context (user_id, chat_id).
Recommend Option A for richer context.
1. User sends message to Ava 2. Ava decides to use a tool 3. Tool execution is wrapped with timing 4. Trace stored to SQLite, get trace ID 5. Trace ID passed to response formatting 6. Response includes trace link (handled in t-272.5)