Initializing session with transcript ignores tools

When I initialize a session with an existing transcript using this initializer:

public convenience init(model: SystemLanguageModel = .default, guardrails: LanguageModelSession.Guardrails = .default, tools: [any Tool] = [], transcript: Transcript)

The tools get ignored. I noticed that when doing that, the model never use the tools. When inspecting the transcript, I can see that the instruction entry does not have any tools available to it.

I tried this for both transcripts that already include an instruction entry and ones that don't - both yielding the same result..

Is this the intended behavior / am I missing something here?

Answered by Frameworks Engineer in 847644022

Hi @iddogino, thanks for the report! This is a bug tracked under 154904647.

Here's a workaround: Before creating a new session, you can manually modify the instructions entry of the original transcript and add tool definitions for the new tools. Then when you create a new session with this modified transcript, make sure to include all tool instances (old and new) in the tools: argument.

Here's an example:

var transcript = oldSession.transcript
guard case .instructions(var instructions) = transcript.first else {
    // Error handling
}
// Append definitions of your new tools.
instructions.toolDefinitions.append(
    Transcript.ToolDefinition(
        name: newTool.name,
        description: newTool.description,
        parameters: newTool.parameters))
transcript[0] = .instructions(instructions)
let newSession = LanguageModelSession(tools: [/*old tools + new tools*/], transcript: transcript)
Accepted Answer

Hi @iddogino, thanks for the report! This is a bug tracked under 154904647.

Here's a workaround: Before creating a new session, you can manually modify the instructions entry of the original transcript and add tool definitions for the new tools. Then when you create a new session with this modified transcript, make sure to include all tool instances (old and new) in the tools: argument.

Here's an example:

var transcript = oldSession.transcript
guard case .instructions(var instructions) = transcript.first else {
    // Error handling
}
// Append definitions of your new tools.
instructions.toolDefinitions.append(
    Transcript.ToolDefinition(
        name: newTool.name,
        description: newTool.description,
        parameters: newTool.parameters))
transcript[0] = .instructions(instructions)
let newSession = LanguageModelSession(tools: [/*old tools + new tools*/], transcript: transcript)
Initializing session with transcript ignores tools
 
 
Q