Repository navigation
Commit c5f4e8f
fix(gemini): normalize tool call/response parts in captured input (#823)
Gemini's native `function_call`/`function_response` parts were passed
through to `$ai_input` verbatim, in a shape no PostHog consumer
recognizes. The trace renderer matches tool results against Anthropic
`tool_result`, Vercel `tool-result`, OpenAI Responses
`function_call_output`, and `{type: "function", tool_name, content}` —
none of which match — so tool responses never rendered, and the eval
formatter fell through to a raw `repr()` dump instead of a labeled tool
result.
The same SDK already normalized tool calls on the response path to
`{type: "function", function: {...}}`, which is why a call rendered in
the output but vanished once it appeared in the next request's history.
Normalize both part kinds in `_format_part`. Tool results use
`tool_name`/`content` rather than an id-carrying shape because Gemini
matches responses to calls by name and has no call ids to thread.
`$ai_output_choices` is unaffected: `format_gemini_response` hits its
explicit `function_call` branch before the `_format_part` fallback and
already emitted the normalized shape.
Fixes #725
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>1 parent 902bc44 commit c5f4e8f
3 files changed
Lines changed: 26 additions & 7 deletions
File tree
- .sampo/changesets
- posthog
- ai/gemini
- test/ai/gemini
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
58 | 61 | | |
| 62 | + | |
59 | 63 | | |
60 | | - | |
61 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
62 | 69 | | |
63 | 70 | | |
| 71 | + | |
64 | 72 | | |
65 | | - | |
66 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
67 | 76 | | |
68 | 77 | | |
69 | 78 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
87 | | - | |
88 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
89 | 94 | | |
90 | 95 | | |
91 | 96 | | |
| |||
0 commit comments