Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions Sources/AnyLanguageModel/LanguageModelSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ public final class LanguageModelSession: @unchecked Sendable {
)
)
session.withMutation(keyPath: \.transcript) {
session.state.withLock { $0.transcript.append(responseEntry) }
session.state.withLock {
$0.transcript.append(contentsOf: lastSnapshot.transcriptEntries)
$0.transcript.append(responseEntry)
}
}
}
} catch {
Expand Down Expand Up @@ -834,13 +837,23 @@ extension LanguageModelSession {
public var content: Content.PartiallyGenerated
public var rawContent: GeneratedContent

/// Transcript entries (tool calls and outputs) produced so far while streaming.
/// Cumulative across tool rounds; empty for providers that don't stream tool activity.
public var transcriptEntries: ArraySlice<Transcript.Entry>

/// Creates a snapshot from partially generated content and raw content.
/// - Parameters:
/// - content: The partially generated content.
/// - rawContent: The raw content produced by the model.
public init(content: Content.PartiallyGenerated, rawContent: GeneratedContent) {
/// - transcriptEntries: Transcript entries accumulated so far (tool calls/outputs).
public init(
content: Content.PartiallyGenerated,
rawContent: GeneratedContent,
transcriptEntries: ArraySlice<Transcript.Entry> = []
) {
self.content = content
self.rawContent = rawContent
self.transcriptEntries = transcriptEntries
}
}
}
Expand Down Expand Up @@ -903,7 +916,7 @@ extension LanguageModelSession.ResponseStream: AsyncSequence {
return LanguageModelSession.Response(
content: finalContent,
rawContent: last.rawContent,
transcriptEntries: []
transcriptEntries: last.transcriptEntries
)
}
}
Expand All @@ -918,7 +931,7 @@ extension LanguageModelSession.ResponseStream: AsyncSequence {
return LanguageModelSession.Response(
content: finalContent,
rawContent: fallbackSnapshot.rawContent,
transcriptEntries: []
transcriptEntries: fallbackSnapshot.transcriptEntries
)
}

Expand Down
Loading