fix: make toolset switching atomic to prevent tool desync race (#648)

Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
Charles Packer
2026-01-22 17:33:14 -08:00
committed by GitHub
parent ebe3a344f1
commit e32b10f931
3 changed files with 260 additions and 116 deletions

View File

@@ -8,7 +8,10 @@ import type {
ApprovalCreate,
LettaStreamingResponse,
} from "@letta-ai/letta-client/resources/agents/messages";
import { getClientToolsFromRegistry } from "../tools/manager";
import {
getClientToolsFromRegistry,
waitForToolsetReady,
} from "../tools/manager";
import { isTimingsEnabled } from "../utils/timing";
import { getClient } from "./client";
@@ -42,6 +45,10 @@ export async function sendMessageStream(
const client = await getClient();
// Wait for any in-progress toolset switch to complete before reading tools
// This prevents sending messages with stale tools during a switch
await waitForToolsetReady();
let stream: Stream<LettaStreamingResponse>;
if (process.env.DEBUG) {