feat: Support Agent tool call tracing for AI SDK v5/v6#1575
feat: Support Agent tool call tracing for AI SDK v5/v6#1575Luca Forstner (lforst) merged 9 commits intomainfrom
Conversation
# Conflicts: # e2e/helpers/ai-sdk.ts # e2e/scenarios/wrap-ai-sdk-generation-traces/scenario.test.ts
# Conflicts: # e2e/scenarios/wrap-ai-sdk-generation-traces/scenario.test.ts
|
I worked on #1582 that also adds v5/v6 e2e tests - but looks like we can merge that in after this PR gets merged in |
|
|
||
| context.result = result; | ||
| asyncStart?.publish(context); | ||
| asyncEnd?.publish(context); |
There was a problem hiding this comment.
why do we have to do this?
There was a problem hiding this comment.
So in general we did this change because our patching is buggy because if the wrapped function returns a non-promise or null we would crash accessing .then. So it's effectively just a compat change.
The event publishing and context setting is just necessary to be in line with the resolve/reject behavior above.
|
|
||
| const REMOVE_NORMALIZED_VALUE = Symbol("braintrust.ai-sdk.remove-normalized"); | ||
|
|
||
| function normalizeAISDKLoggedOutput( |
There was a problem hiding this comment.
This function is defined here and in the wrapper. We can prob DRY.
|
|
||
| // Agent.generate - async method (v3-v5 only, Agent structure changed in v6) | ||
| // Agent.generate - async method (v5 only) | ||
| // The compiled AI SDK bundle emits this as an anonymous class method, so we |
There was a problem hiding this comment.
I did add support for export aliases to orchestrion (https://github.com/nodejs/orchestrion-js?tab=readme-ov-file#export-aliases). Can we maybe patch orchestrion to make this better somehow?
There was a problem hiding this comment.
It's not a blocker per se right now but we can definitely improve that in orchestrion.
^ vast majority of this is snapshots
Agent.generate/Agent.streamfor v5 andToolLoopAgent.generate/ToolLoopAgent.streamfor v6.doGenerate,doStream, and tool execution emit the same nested traces.