feat: add provider_item_id to ai-gateway tool usage recording - #24562
feat: add provider_item_id to ai-gateway tool usage recording#24562dannykopping wants to merge 5 commits into
provider_item_id to ai-gateway tool usage recording#24562Conversation
dannykopping
left a comment
There was a problem hiding this comment.
Self-review ✅
| github.com/brianvoe/gofakeit/v7 v7.14.0 | ||
| github.com/coder/agentapi-sdk-go v0.0.0-20250505131810-560d1d88d225 | ||
| github.com/coder/aibridge v1.1.3-0.20260420072253-d474d6813420 | ||
| github.com/coder/aibridge v1.1.3-0.20260421115004-34c9a190da9a |
There was a problem hiding this comment.
TODO: replace with merge commit from coder/aibridge#273
provider_item_id to ai-gateway tool usage recording
Adds a separate provider_item_id column to aibridge_tool_usages to capture the output item's unique ID independently from the provider_tool_call_id (which is the correlation ID for agentic tools). This avoids conflating two semantically different identifiers: - provider_item_id: the output item's unique id (always present) - provider_tool_call_id: the call_id used to correlate tool output (empty for hosted tools like web_search_call) Changes: - Migration 000472: adds provider_item_id column - Proto: adds item_id field (field 11) to RecordToolUsageRequest - Server handler: plumbs item_id through to DB insert - Translator: TODO placeholder until aibridge dep is bumped Depends on: coder/aibridge#273
- Bump github.com/coder/aibridge to 34c9a190 which adds ItemID to ToolUsageRecord. - Wire req.ItemID in the translator (replaces TODO placeholder). - Remove Responses API-specific wording from migration comment.
The aibridge code was moved into coder/coder (PR #24190), so the external go.mod dependency is no longer needed. The ItemID field on ToolUsageRecord is added here since it is required by the translator and server handler. Migration renumbered from 000472 to 000475 to avoid conflicts with migrations added since the original PR was created.
d5f1b68 to
902891b
Compare
What makes you think it's not? |
I don't see any changes to |
Oh, that kind of tested. Yeah I can add a test to validate that the field is persisted. |
Inserts a tool usage with both ProviderItemID and ProviderToolCallID set, then reads it back via GetAIBridgeToolUsagesByInterceptionID to confirm both fields round-trip through the database.
| InitiatorID: user.ID, | ||
| }, nil) | ||
|
|
||
| tool := dbgen.AIBridgeToolUsage(t, db, database.InsertAIBridgeToolUsageParams{ |
There was a problem hiding this comment.
I think RecordToolUsage function should be tested that it properly stores the ItemID field.
I don't think checking dbgen.AIBridgeToolUsage is needed.
There was a problem hiding this comment.
Fair. I'm juggling too many topics. Let me get to this when I have a chance to spend some brain tokens.
Disclaimer: implemented by a Coder Agent using Claude Opus 4.6
Summary
Adds a separate
provider_item_idcolumn toaibridge_tool_usagesto capture the output item's unique ID independently fromprovider_tool_call_id.This addresses review feedback from coder/aibridge#273 — conflating the item
idandcall_idinto a single field causes data consistency issues when other sources record these fields correctly.Why two IDs?
Provider tool call output items can have two distinct identifiers:
idcall_idHosted tools (
web_search_call,file_search_call,code_interpreter_call,image_generation_call,mcp_call) only haveid— nocall_id— because the server executes them internally.For
/v1/chat/completionsand Anthropic/v1/messages, onlyToolCallIDis populated (it's the correlation ID in both APIs).ItemIDstays empty since those APIs don't have a separate item ID concept.Changes
provider_item_idcolumn toaibridge_tool_usagesitem_idfield (field 11) toRecordToolUsageRequestitem_idthrough to DB insert + structured loggingToolUsageRecord.ItemID→ protoItemIdcoder/aibridgeto34c9a190(addsItemIDfield)Dependencies
Depends on coder/aibridge#273 being merged first (the go.mod points at the branch commit).
Linear: AIGOV-96