Integrate trace storage into tool execution

t-272.4·WorkTask·
·
·
Parent:t-272·Created2 months ago·Updated2 months ago

Dependencies

Description

Edit

Modify the Telegram agent to store traces when tools are executed.

Context

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

Key Files to Modify

Omni/Agent/Telegram.hs

This is where tool calls are processed. Look for where Engine.toolExecute is called.

Omni/Agent/Engine.hs

The tool execution engine. May need to modify the execution wrapper here instead.

Implementation Approach

Option A: Wrap at Telegram level

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)

Option B: Wrap at Engine level

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.

Data Flow

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)

Considerations

  • DB connection: Need access to SQLite connection in the tool execution context
  • Error handling: Store traces even for failed tool calls (capture error in output)
  • Large outputs: Consider truncating very large outputs (>1MB) to prevent DB bloat

Testing

  • Unit test: mock tool execution, verify trace is stored
  • Integration test: execute real tool, query trace from DB

Timeline (1)

🔄[human]Open → Done2 months ago