AG-UI TOOL_CALL_RESULT metadata is dropped in the live stream reducer

Aperta
#2,068 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@c446984928 ci sta già lavorando.

Dal 6/11/2026.

  • #2069 di @c446984928 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
typescript
Ambito
api, backend

Direzione di ricerca

Read packages/ai/src/activities/chat/stream/processor.ts and packages/ai/src/activities/chat/stream/message-updaters.ts, then compare with the snapshot conversion in packages/ai/src/activities/chat/messages.ts. Check the existing tests for live tool result events and add coverage for metadata preservation on creation and update; done means live results retain metadata consistently with hydrated snapshots. An open linked pull request already covers this issue.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

The live AG-UI TOOL_CALL_RESULT handling path drops the event's metadata when constructing the ToolResultPart.

This makes metadata behave inconsistently between live streaming and message snapshot/history hydration: a ToolMessage.metadata received in a MESSAGES_SNAPSHOT can be preserved, but the same metadata delivered on a live TOOL_CALL_RESULT is not available on the resulting UIMessage.parts entry.

Expected behavior

When a TOOL_CALL_RESULT event contains metadata, the resulting ToolResultPart should retain it:

{
  type: 'tool-result',
  toolCallId: 'call-123',
  content: '...',
  state: 'complete',
  metadata: {
    displayType: 'account-assets',
  },
}

Actual behavior

In packages/ai/src/activities/chat/stream/processor.ts, handleToolCallResultEvent() receives the full event, but calls updateToolResultPart() without forwarding chunk.metadata.

In packages/ai/src/activities/chat/stream/message-updaters.ts, updateToolResultPart() constructs a ToolResultPart containing content, state, error, and outcome, but does not set metadata.

The public ToolResultPart type in packages/ai/src/types.ts already declares metadata?: Record<string, unknown>, and the snapshot conversion path in packages/ai/src/activities/chat/messages.ts preserves metadata from tool messages. So the type and snapshot path support this field, but the live event reducer currently drops it.

Reproduction

  1. Stream an AG-UI TOOL_CALL_RESULT event with a metadata object:

    {
      "type": "TOOL_CALL_RESULT",
      "messageId": "assistant-1",
      "toolCallId": "call-123",
      "content": "{\"ok\":true}",
      "metadata": {
        "displayType": "account-assets"
      }
    }
    
  2. Observe the resulting UIMessage.parts entry with type === 'tool-result'.

  3. The content is present, but metadata is missing.

Suggested fix

Forward the event metadata into updateToolResultPart() and persist it on the created ToolResultPart. Please also consider how metadata should be merged when an existing tool-result part is updated, so an update does not accidentally discard previously stored metadata.

Add a regression test covering:

  • Live TOOL_CALL_RESULT.metadata is retained in ToolResultPart.metadata.
  • Snapshot/history hydration and live streaming produce consistent metadata.
  • Updating an existing tool-result part does not unintentionally lose metadata.

Relevant code

Thanks!

Lingua principale
TypeScript
Stelle
3.3k
Fork
378
Merge medio
1g 2h
PR unite (30g)
254

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TanStack/ai

Tutte le issue di TanStack/ai

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.