Skip to content
Closed
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
12 changes: 12 additions & 0 deletions Sources/AnyLanguageModel/LanguageModelSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@ public final class LanguageModelSession: @unchecked Sendable {
}
}

// MARK: - Transcript Manipulation

extension LanguageModelSession {
/// Allows manual injection of Transcript entries to resume dropped sessions
/// without busting the MLX ObjectIdentifier KV-cache.
public func appendTranscriptEntry(_ entry: Transcript.Entry) {
withMutation(keyPath: \.transcript) {
state.withLock { $0.transcript.append(entry) }
}
}
}

// MARK: - String Response Convenience Methods

extension LanguageModelSession {
Expand Down
8 changes: 6 additions & 2 deletions Sources/AnyLanguageModel/Models/MLXLanguageModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,12 @@ import Foundation
chat.append(.tool(toolResultJSON))
}

// Continue loop to generate with tool results
continue
// Return response with appended tool outputs rather than looping to regenerate
return LanguageModelSession.Response(
content: assistantText as! Content,
rawContent: GeneratedContent(assistantText),
transcriptEntries: ArraySlice(allEntries)
)
}
}
}
Expand Down