Skip to content
Merged
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
2 changes: 1 addition & 1 deletion scripts/source-file-size-baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"src/cli/mods/local-mod-loader.test.ts": 1043,
"src/cli/reflection-transcript.test.ts": 1084,
"src/cli/subcommands/skills.ts": 1264,
"src/headless.ts": 5043,
"src/headless.ts": 5042,
"src/hooks/integration.test.ts": 1147,
"src/index.ts": 2775,
"src/mods/learning-harness.ts": 2434,
Expand Down
100 changes: 100 additions & 0 deletions src/headless-ephemeral-toolset.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { createLocalEphemeralConversation } from "@/agent/ephemeral-conversation";
import {
configureBackendMode,
configureEphemeralLocalBackend,
getBackend,
} from "@/backend";
import { releaseToolExecutionContext } from "@/tools/manager";
import { __headlessTestUtils } from "./headless";

const REPRESENTATIVE_MODELS = [
"openai/gpt-5.6-luna",
"anthropic/claude-sonnet-4-6",
"google_ai/gemini-3.1-flash-lite",
];

describe("ephemeral headless toolset selection", () => {
let storageDir: string;
let originalStorageDir: string | undefined;

beforeEach(() => {
storageDir = mkdtempSync(join(tmpdir(), "letta-ephemeral-toolset-"));
originalStorageDir = process.env.LETTA_LOCAL_BACKEND_DIR;
process.env.LETTA_LOCAL_BACKEND_DIR = storageDir;
configureBackendMode("local");
configureEphemeralLocalBackend();
});

afterEach(() => {
configureBackendMode("api");
if (originalStorageDir === undefined) {
delete process.env.LETTA_LOCAL_BACKEND_DIR;
} else {
process.env.LETTA_LOCAL_BACKEND_DIR = originalStorageDir;
}
rmSync(storageDir, { recursive: true, force: true });
});

for (const model of REPRESENTATIVE_MODELS) {
test(`matches an agent-backed conversation for ${model}`, async () => {
const backend = getBackend();
const ephemeral = await createLocalEphemeralConversation({
model,
systemPromptCustom: "ephemeral toolset test",
});
const agent = await backend.createAgent({
agent_type: "letta_v1_agent",
name: "Agent-backed toolset test",
model,
system: "agent-backed toolset test",
memory_blocks: [],
tags: [],
tools: [],
include_base_tools: false,
include_base_tool_rules: false,
initial_message_sequence: [],
parallel_tool_calls: true,
});
const conversation = await backend.createConversation({
agent_id: agent.id,
model,
});

const ephemeralPrepared =
await __headlessTestUtils.prepareHeadlessToolExecutionContext({
agentId: ephemeral.agent.id,
conversationId: ephemeral.conversationId,
cachedAgent: ephemeral.agent,
});
const agentPrepared =
await __headlessTestUtils.prepareHeadlessToolExecutionContext({
agentId: agent.id,
conversationId: conversation.id,
cachedAgent: agent,
});

try {
expect(ephemeralPrepared.preparedToolContext.effectiveModel).toBe(
model,
);
expect(ephemeralPrepared.preparedToolContext.toolset).toBe(
agentPrepared.preparedToolContext.toolset,
);
expect(ephemeralPrepared.availableTools).toEqual(
agentPrepared.availableTools,
);
} finally {
releaseToolExecutionContext(
ephemeralPrepared.preparedToolContext.preparedToolContext.contextId,
);
releaseToolExecutionContext(
agentPrepared.preparedToolContext.preparedToolContext.contextId,
);
}
});
}
});
1 change: 0 additions & 1 deletion src/headless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,6 @@ export async function handleHeadlessCommand(
const initialToolContext = await prepareHeadlessToolExecutionContext({
agentId: agent.id,
conversationId,
overrideModel: ephemeralFlag ? agent.llm_config?.model : undefined,
cachedAgent: agent as AgentState,
modContext: initialHeadlessModContext,
modEvents: headlessModAdapter.events,
Expand Down
Loading