🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(in-app-agent): Revert "Foundation to make in-app agent available in OSS" (#16310)
Lysander Kiesel9337f61ec488
diff --git a/.env.dev.example b/.env.dev.exampleindex 0381ecf79c..7a377d2916 100644--- a/.env.dev.example+++ b/.env.dev.example@@ -201,9 +201,6 @@ LANGFUSE_AWS_BEDROCK_REGION="eu-west-1"LANGFUSE_AWS_BEDROCK_MODEL="eu.anthropic.claude-opus-4-8"LANGFUSE_AWS_BEDROCK_SMALL_MODEL="eu.anthropic.claude-haiku-4-5-20251001-v1:0"LANGFUSE_IN_APP_AGENT_AWS_PROFILE="playground"-# Self-hosted Assistant instance switch. Unset or "false" hides Assistant.-# Cloud is on unless this is "false".-# LANGFUSE_IN_APP_AGENT_ENABLED="true"# In-app agent sandbox. Local development defaults to the dangerous docker provider.# Set to enable sandboxing locally. Leave unset to disable sandbox tools entirely.diff --git a/docker-compose.build.yml b/docker-compose.build.ymlindex 822f82b65f..9f6439f9d1 100644--- a/docker-compose.build.yml+++ b/docker-compose.build.yml@@ -54,19 +54,6 @@ services:REDIS_TLS_CA: ${REDIS_TLS_CA:-/certs/ca.crt}REDIS_TLS_CERT: ${REDIS_TLS_CERT:-/certs/redis.crt}REDIS_TLS_KEY: ${REDIS_TLS_KEY:-/certs/redis.key}- # Shared AI features configuration. These apply to AI features that run- # in both web and worker.- LANGFUSE_AWS_BEDROCK_MODEL: ${LANGFUSE_AWS_BEDROCK_MODEL:-}- LANGFUSE_AWS_BEDROCK_SMALL_MODEL: ${LANGFUSE_AWS_BEDROCK_SMALL_MODEL:-}- LANGFUSE_AWS_BEDROCK_REGION: ${LANGFUSE_AWS_BEDROCK_REGION:-}- LANGFUSE_IN_APP_AGENT_ENABLED: ${LANGFUSE_IN_APP_AGENT_ENABLED:-}- AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID:-}- AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY:-}- AWS_SESSION_TOKEN: ${AWS_SESSION_TOKEN:-}- AWS_PROFILE: ${AWS_PROFILE:-}- # In-app agent settings.- LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER: ${LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER:-}- LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_ORG: ${LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_ORG:-}restart: alwayshealthcheck:test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:3000/api/public/health"]@@ -89,17 +76,6 @@ services:- "3030:3030"environment:<<: *langfuse-web-env- # In-app agent worker settings (ignored by the web service).- # Compose defaults the queue consumer on; the worker schema defaults it- # off so ingestion-only processes do not consume agent jobs.- QUEUE_CONSUMER_IN_APP_AGENT_RUN_QUEUE_IS_ENABLED: ${QUEUE_CONSUMER_IN_APP_AGENT_RUN_QUEUE_IS_ENABLED:-true}- LANGFUSE_IN_APP_AGENT_RUN_QUEUE_PROCESSING_CONCURRENCY: ${LANGFUSE_IN_APP_AGENT_RUN_QUEUE_PROCESSING_CONCURRENCY:-}- LANGFUSE_IN_APP_AGENT_AWS_PROFILE: ${LANGFUSE_IN_APP_AGENT_AWS_PROFILE:-}- LANGFUSE_IN_APP_AGENT_SANDBOX_PROVIDER: ${LANGFUSE_IN_APP_AGENT_SANDBOX_PROVIDER:-}- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_IMAGE_IDENTIFIER: ${LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_IMAGE_IDENTIFIER:-}- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EXECUTION_ROLE_ARN: ${LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EXECUTION_ROLE_ARN:-}- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EGRESS_NETWORK_CONNECTOR_ARN: ${LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EGRESS_NETWORK_CONNECTOR_ARN:-}- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_REGION: ${LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_REGION:-}restart: alwayshealthcheck:test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:3030/api/health"]diff --git a/docker-compose.yml b/docker-compose.ymlindex 8657364684..028eddf772 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -73,27 +73,6 @@ services:REDIS_TLS_KEY: ${REDIS_TLS_KEY:-/certs/redis.key}EMAIL_FROM_ADDRESS: ${EMAIL_FROM_ADDRESS:-}SMTP_CONNECTION_URL: ${SMTP_CONNECTION_URL:-}- # Shared AI features configuration. These apply to AI features that run- # in both web and worker.- LANGFUSE_IN_APP_AGENT_ENABLED: ${LANGFUSE_IN_APP_AGENT_ENABLED:-}- LANGFUSE_AWS_BEDROCK_MODEL: ${LANGFUSE_AWS_BEDROCK_MODEL:-}- LANGFUSE_AWS_BEDROCK_SMALL_MODEL: ${LANGFUSE_AWS_BEDROCK_SMALL_MODEL:-}- LANGFUSE_AWS_BEDROCK_REGION: ${LANGFUSE_AWS_BEDROCK_REGION:-}- AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID:-}- AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY:-}- AWS_SESSION_TOKEN: ${AWS_SESSION_TOKEN:-}- AWS_PROFILE: ${AWS_PROFILE:-}- # In-app agent worker settings (ignored by the web service).- # Compose defaults the queue consumer on; the worker schema defaults it- # off so ingestion-only processes do not consume agent jobs.- QUEUE_CONSUMER_IN_APP_AGENT_RUN_QUEUE_IS_ENABLED: ${QUEUE_CONSUMER_IN_APP_AGENT_RUN_QUEUE_IS_ENABLED:-true}- LANGFUSE_IN_APP_AGENT_RUN_QUEUE_PROCESSING_CONCURRENCY: ${LANGFUSE_IN_APP_AGENT_RUN_QUEUE_PROCESSING_CONCURRENCY:-}- LANGFUSE_IN_APP_AGENT_AWS_PROFILE: ${LANGFUSE_IN_APP_AGENT_AWS_PROFILE:-}- LANGFUSE_IN_APP_AGENT_SANDBOX_PROVIDER: ${LANGFUSE_IN_APP_AGENT_SANDBOX_PROVIDER:-}- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_IMAGE_IDENTIFIER: ${LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_IMAGE_IDENTIFIER:-}- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EXECUTION_ROLE_ARN: ${LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EXECUTION_ROLE_ARN:-}- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EGRESS_NETWORK_CONNECTOR_ARN: ${LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EGRESS_NETWORK_CONNECTOR_ARN:-}- LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_REGION: ${LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_REGION:-}langfuse-web:image: docker.langfuse.com/langfuse/langfuse:4@@ -114,9 +93,6 @@ services:LANGFUSE_INIT_USER_EMAIL: ${LANGFUSE_INIT_USER_EMAIL:-}LANGFUSE_INIT_USER_NAME: ${LANGFUSE_INIT_USER_NAME:-}LANGFUSE_INIT_USER_PASSWORD: ${LANGFUSE_INIT_USER_PASSWORD:-}- # In-app agent settings.- LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER: ${LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER:-}- LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_ORG: ${LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_ORG:-}clickhouse:image: docker.io/clickhouse/clickhouse-server:25.12diff --git a/packages/shared/AGENTS.md b/packages/shared/AGENTS.mdindex fb10de4923..2beb3cf771 100644--- a/packages/shared/AGENTS.md+++ b/packages/shared/AGENTS.md@@ -46,8 +46,7 @@for shared backend services, repositories, queue helpers/contracts, Redis andClickHouse helpers, auth helpers, logger/instrumentation, ingestion helpers,AI SDK-native LLM execution helpers (`generateLLMText` and- `streamLLMText`), Bedrock default-credential provider auth- (`createDefaultBedrockProviderAuth`), and server test utilities.+ `streamLLMText`), and server test utilities.- `@langfuse/shared/src/db` via `src/db.ts`: Prisma client singleton plusPrisma namespace/types for direct database access. Never route this intofrontend-safe code.@@ -62,13 +61,12 @@and interrupt parsing. Never re-export server code here.- In-app-agent server contracts use explicit subpaths only:`persistence`, `runLifecycle`, `tunables`, `eventCompaction`, `mcpPolicy`,- `toolResults`, `toolErrors`, `systemPrompt`, and `modelProvider`. These are- storage/lifecycle, durable cross-process policy, or instance-model contracts;- the Mastra runtime and sandbox belong to the worker.+ `toolResults`, `toolErrors`, and `systemPrompt`. These are storage/lifecycle or durable+ cross-process policy contracts; the Mastra runtime and sandbox belong to the+ worker.- Narrower exported subpaths also exist for targeted imports:`@langfuse/shared/src/server/auth/apiKeys`,- `@langfuse/shared/src/server/ee/ingestionMasking`,- `@langfuse/shared/src/server/llm/llmText`, and+ `@langfuse/shared/src/server/ee/ingestionMasking`, and`@langfuse/shared/src/utils/chatml`.When changing export surfaces, keep `package.json#exports`, the relevant barreldiff --git a/packages/shared/package.json b/packages/shared/package.jsonindex 7d0fd39cce..91538fab2e 100644--- a/packages/shared/package.json+++ b/packages/shared/package.json@@ -31,10 +31,6 @@"import": "./dist/src/server/index.js","require": "./dist/src/server/index.js"},- "./src/server/llm/llmText": {- "import": "./dist/src/server/llm/llmText.js",- "require": "./dist/src/server/llm/llmText.js"- },"./src/server/auth/apiKeys": {"import": "./dist/src/server/auth/apiKeys.js","require": "./dist/src/server/auth/apiKeys.js"@@ -102,10 +98,6 @@"./in-app-agent/server/systemPrompt": {"import": "./dist/src/in-app-agent/server/systemPrompt.js","require": "./dist/src/in-app-agent/server/systemPrompt.js"- },- "./in-app-agent/server/modelProvider": {- "import": "./dist/src/in-app-agent/server/modelProvider.js",- "require": "./dist/src/in-app-agent/server/modelProvider.js"}},"scripts": {diff --git a/packages/shared/src/env.ts b/packages/shared/src/env.tsindex 53ec693f3d..8fd573c109 100644--- a/packages/shared/src/env.ts+++ b/packages/shared/src/env.ts@@ -522,7 +522,6 @@ const EnvSchema = z.object({LANGFUSE_AWS_BEDROCK_REGION: z.string().optional(),LANGFUSE_AWS_BEDROCK_MODEL: z.string().optional(),LANGFUSE_AWS_BEDROCK_SMALL_MODEL: z.string().optional(),- LANGFUSE_IN_APP_AGENT_ENABLED: z.enum(["true", "false"]).optional(),// API Performance Flags// Whether to add a `FINAL` modifier to the observations CTE in GET /api/public/traces.diff --git a/packages/shared/src/in-app-agent/server/modelProvider.ts b/packages/shared/src/in-app-agent/server/modelProvider.tsdeleted file mode 100644index 557a12f0ec..0000000000--- a/packages/shared/src/in-app-agent/server/modelProvider.ts+++ /dev/null@@ -1,54 +0,0 @@-import { env } from "../../env";-import { assertValidBedrockRegion } from "../../server/llm/ai-sdk/providers/bedrock";--export type InAppAgentModelConfig = {- provider: "bedrock";- modelId: string;- titleModelId: string;- region: string;-};--/**- * Resolves the instance-wide in-app agent model configuration.- *- * The discriminated provider contract is intentionally narrower than the- * generic LLM connection model: in-app agent execution currently supports- * Bedrock only, but callers do not need to know which provider supplies the- * model. A future provider can add another branch here without changing the- * worker or title-generation call sites.- */-export function getInAppAgentModelConfig(params?: {- modelId?: string | null;-}): InAppAgentModelConfig | undefined {- const modelId = params?.modelId ?? env.LANGFUSE_AWS_BEDROCK_MODEL;- const region = env.LANGFUSE_AWS_BEDROCK_REGION;-- if (!modelId || !region) {- return undefined;- }-- assertValidBedrockRegion(region);-- return {- provider: "bedrock",- modelId,- titleModelId: env.LANGFUSE_AWS_BEDROCK_SMALL_MODEL ?? modelId,- region,- };-}--/**- * Instance-wide in-app agent switch.- *- * Cloud is on unless LANGFUSE_IN_APP_AGENT_ENABLED is "false". Self-hosted is- * on only when the var is "true".- */-export function isInAppAgentInstanceEnabled(): boolean {- const enabled = env.LANGFUSE_IN_APP_AGENT_ENABLED;-- if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION) {- return enabled !== "false";- }-- return enabled === "true";-}diff --git a/packages/shared/src/in-app-agent/server/persistence.ts b/packages/shared/src/in-app-agent/server/persistence.tsindex a2b9646e87..b6ee67cf6a 100644--- a/packages/shared/src/in-app-agent/server/persistence.ts+++ b/packages/shared/src/in-app-agent/server/persistence.ts@@ -15,11 +15,11 @@ import {import { Prisma } from "../../db";import type { InAppAgentConversation, PrismaClient } from "../../db";+import { env } from "../../env";import {generateLangfuseAIText,getLangfuseAITraceSinkParams,} from "../../server/llm/langfuseAiCompletion";-import { getInAppAgentModelConfig } from "./modelProvider";import { getProductBaseUrl } from "../../server/utils/baseUrl";import { truncate } from "../../utils/stringChecks";import { assertUnreachable } from "../../utils/typeChecks";@@ -431,9 +431,10 @@ export async function maybeInferAndPersistConversationTitle(params: {userId: string;aiTelemetryEnabled: boolean;}) {- const modelConfig = getInAppAgentModelConfig();+ const model =+ env.LANGFUSE_AWS_BEDROCK_SMALL_MODEL ?? env.LANGFUSE_AWS_BEDROCK_MODEL;- if (!modelConfig) {+ if (!model) {return;}@@ -522,7 +523,7 @@ ${JSON.stringify(transcript, null, 2)}`.trim(),},],- model: modelConfig.titleModelId,+ model,maxTokens: 1000,traceSinkParams: params.aiTelemetryEnabled? getLangfuseAITraceSinkParams({diff --git a/packages/shared/src/server/index.ts b/packages/shared/src/server/index.tsindex 7ec6aacff3..b3308bb988 100644--- a/packages/shared/src/server/index.ts+++ b/packages/shared/src/server/index.ts@@ -57,7 +57,6 @@ export * from "./utils/productUrl";export * from "./llm/compileChatMessages";export * from "./llm/testModelCall";export * from "./llm/baseUrlValidation";-export * from "./llm/ai-sdk/providers/bedrock";export * from "./outbound-url";export * from "./services/blobStorageEndpointValidation";export * from "./llm/getInternalTracingHandler";diff --git a/packages/shared/src/server/llm/ai-sdk/providers/bedrock.ts b/packages/shared/src/server/llm/ai-sdk/providers/bedrock.tsindex 5940830a56..84f234b669 100644--- a/packages/shared/src/server/llm/ai-sdk/providers/bedrock.ts+++ b/packages/shared/src/server/llm/ai-sdk/providers/bedrock.ts@@ -80,28 +80,6 @@ export function translateBedrockProviderOptions(// requestShape.test.ts.const SUPPRESS_BEARER_TOKEN_ENV_FALLBACK = { apiKey: "" };-/**- * Returns the Bedrock auth options for the AWS default credential chain.- *- * The empty API key deliberately prevents the AI SDK from selecting an- * ambient AWS_BEARER_TOKEN_BEDROCK value ahead of the configured AWS- * credentials. An optional profile is useful for local worker development;- * production workloads should normally rely on the default AWS role chain.- */-export function createDefaultBedrockProviderAuth(params?: {- profile?: string;-}): Pick<- Parameters<typeof createAmazonBedrock>[0] & object,- "apiKey" | "credentialProvider"-> {- return {- credentialProvider: fromNodeProviderChain(- params?.profile ? { profile: params.profile } : {},- ),- ...SUPPRESS_BEARER_TOKEN_ENV_FALLBACK,- };-}-/*** Resolves the persisted Bedrock credential contract: the decrypted secret is* either the default-credentials sentinel (allowed only self-hosted or for@@ -123,7 +101,10 @@ export function resolveBedrockProviderAuth(params: {) {// Unlike the AI SDK's built-in env-only fallback, the node provider chain// includes env, profile, IMDS, IRSA, and the remaining AWS defaults.- return createDefaultBedrockProviderAuth();+ return {+ credentialProvider: fromNodeProviderChain(),+ ...SUPPRESS_BEARER_TOKEN_ENV_FALLBACK,+ };}try {diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex b2e2fb3f12..257829c883 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -1021,6 +1021,9 @@ importers:'@aws-sdk/client-lambda-microvms':specifier: 'catalog:'version: 3.1074.0+ '@aws-sdk/credential-providers':+ specifier: 'catalog:'+ version: 3.1074.0'@langfuse/shared':specifier: workspace:*version: link:../packages/shareddiff --git a/web/.structure-baseline.json b/web/.structure-baseline.jsonindex 25fbf4973e..de4afebda5 100644--- a/web/.structure-baseline.json+++ b/web/.structure-baseline.json@@ -233,7 +233,7 @@"src/features/evals/components/evaluation-prompt-preview.tsx: extra exports: getVariableColor","src/features/experiments/components/table/ExperimentItemsTable.tsx: extra exports: getDefaultExperimentFilterTarget, shouldEnableExperimentPeek","src/features/in-app-agent/components/InAppAgentWindowShell.tsx: extra exports: useInAppAgentWindowShellPanelControl",- "src/features/in-app-agent/components/InAppAiAgentProvider.tsx: extra exports: useInAppAiAgent, useCanUseInAppAgent, useIsInAppAgentLauncherVisible",+ "src/features/in-app-agent/components/InAppAiAgentProvider.tsx: extra exports: useInAppAiAgent, useCanUseInAppAgent","src/features/monitors/components/MonitorChartPreview.tsx: extra exports: __test","src/features/monitors/components/MonitorForm.tsx: extra exports: __test","src/features/monitors/components/MonitorsTable.tsx: extra exports: __test",diff --git a/web/src/__tests__/server/in-app-agent-background-run.servertest.ts b/web/src/__tests__/server/in-app-agent-background-run.servertest.tsindex dcecd86182..d7cc088b89 100644--- a/web/src/__tests__/server/in-app-agent-background-run.servertest.ts+++ b/web/src/__tests__/server/in-app-agent-background-run.servertest.ts@@ -12,7 +12,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import { type Plan } from "@langfuse/shared";import { prisma } from "@langfuse/shared/src/db";-import { env as sharedEnv } from "@langfuse/shared/src/env";import { createOrgProjectAndApiKey } from "@langfuse/shared/src/server";import {IN_APP_AGENT_APPROVAL_DECISION_EVENT_NAME,@@ -97,11 +96,6 @@ vi.mock("@/src/server/auth", () => ({describe("in-app agent background runs", () => {const originalCloudRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;const originalBedrockModel = env.LANGFUSE_AWS_BEDROCK_MODEL;- const originalSharedCloudRegion = sharedEnv.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;- const originalSharedBedrockModel = sharedEnv.LANGFUSE_AWS_BEDROCK_MODEL;- const originalSharedBedrockRegion = sharedEnv.LANGFUSE_AWS_BEDROCK_REGION;- const originalSharedInAppAgentEnabled =- sharedEnv.LANGFUSE_IN_APP_AGENT_ENABLED;const originalMaxActiveRunsPerUser =env.LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER;const originalMaxActiveRunsPerOrg =@@ -110,10 +104,6 @@ describe("in-app agent background runs", () => {beforeEach(() => {(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "DEV";(env as any).LANGFUSE_AWS_BEDROCK_MODEL = "test-model";- (sharedEnv as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "DEV";- (sharedEnv as any).LANGFUSE_AWS_BEDROCK_MODEL = "test-model";- (sharedEnv as any).LANGFUSE_AWS_BEDROCK_REGION = "eu-central-1";- (sharedEnv as any).LANGFUSE_IN_APP_AGENT_ENABLED = undefined;enqueuedJobs.length = 0;enqueueShouldFail = false;persistenceMocks.maybeInferAndPersistConversationTitle.mockClear();@@ -127,13 +117,6 @@ describe("in-app agent background runs", () => {vi.useRealTimers();(env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = originalCloudRegion;(env as any).LANGFUSE_AWS_BEDROCK_MODEL = originalBedrockModel;- (sharedEnv as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION =- originalSharedCloudRegion;- (sharedEnv as any).LANGFUSE_AWS_BEDROCK_MODEL = originalSharedBedrockModel;- (sharedEnv as any).LANGFUSE_AWS_BEDROCK_REGION =- originalSharedBedrockRegion;- (sharedEnv as any).LANGFUSE_IN_APP_AGENT_ENABLED =- originalSharedInAppAgentEnabled;(env as any).LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_USER =originalMaxActiveRunsPerUser;(env as any).LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_ORG =@@ -211,103 +194,6 @@ describe("in-app agent background runs", () => {userId: params.userId,});- it.each([- {- name: "starts a self-hosted run when LANGFUSE_IN_APP_AGENT_ENABLED is true",- cloudRegion: undefined,- enabled: "true" as const,- plan: "self-hosted:enterprise" as const,- expected: "queued" as const,- },- {- name: "rejects a self-hosted run when LANGFUSE_IN_APP_AGENT_ENABLED is unset",- cloudRegion: undefined,- enabled: undefined,- plan: "self-hosted:enterprise" as const,- expected: "rejected" as const,- },- {- name: "rejects a self-hosted run when LANGFUSE_IN_APP_AGENT_ENABLED is false",- cloudRegion: undefined,- enabled: "false" as const,- plan: "self-hosted:enterprise" as const,- expected: "rejected" as const,- },- {- name: "starts a Cloud run when LANGFUSE_IN_APP_AGENT_ENABLED is unset",- cloudRegion: "DEV" as const,- enabled: undefined,- plan: "cloud:hobby" as const,- expected: "queued" as const,- },- {- name: "rejects a Cloud run when LANGFUSE_IN_APP_AGENT_ENABLED is false",- cloudRegion: "DEV" as const,- enabled: "false" as const,- plan: "cloud:hobby" as const,- expected: "rejected" as const,- },- ])("$name", async ({ cloudRegion, enabled, plan, expected }) => {- (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = cloudRegion;- (sharedEnv as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = cloudRegion;- (sharedEnv as any).LANGFUSE_IN_APP_AGENT_ENABLED = enabled;- const { caller, projectId, userId } = await createCaller(undefined, plan);- const conversation = await createConversation({ projectId, userId });-- const startRun = caller.startRun({- projectId,- conversationId: conversation.id,- message: "Inspect a trace",- });-- if (expected === "queued") {- await expect(startRun).resolves.toMatchObject({- conversationId: conversation.id,- });- expect(enqueuedJobs).toHaveLength(1);- return;- }-- await expect(startRun).rejects.toMatchObject({- code: "PRECONDITION_FAILED",- message: "In-app agent is not enabled on this instance.",- });- expect(enqueuedJobs).toHaveLength(0);- });-- it("lists conversations when the in-app agent model is not configured", async () => {- const { caller, projectId, userId } = await createCaller();- const conversation = await createConversation({ projectId, userId });- (sharedEnv as any).LANGFUSE_AWS_BEDROCK_MODEL = undefined;- (sharedEnv as any).LANGFUSE_AWS_BEDROCK_REGION = undefined;-- const listed = await caller.listConversations({ projectId, limit: 50 });-- expect(listed.conversations.map((item) => item.id)).toEqual([- conversation.id,- ]);- });-- it("rejects requests before queueing when the in-app agent model is not configured", async () => {- const { caller, projectId } = await createCaller();- (sharedEnv as any).LANGFUSE_AWS_BEDROCK_MODEL = undefined;- (sharedEnv as any).LANGFUSE_AWS_BEDROCK_REGION = undefined;-- await expect(- caller.startRun({- projectId,- conversationId: createInAppAgentConversationId(),- message: "Do not queue this",- }),- ).rejects.toMatchObject({- code: "PRECONDITION_FAILED",- message:- "In-app agent Bedrock model is not configured. Set LANGFUSE_AWS_BEDROCK_MODEL and LANGFUSE_AWS_BEDROCK_REGION.",- });-- expect(enqueuedJobs).toHaveLength(0);- });-/** Park a run for approval the way the worker does: interrupt event, then CAS. */const parkRunForApproval = async (params: {projectId: string;diff --git a/web/src/__tests__/server/in-app-agent-persistence.servertest.ts b/web/src/__tests__/server/in-app-agent-persistence.servertest.tsindex a2345f9693..c74171bac6 100644--- a/web/src/__tests__/server/in-app-agent-persistence.servertest.ts+++ b/web/src/__tests__/server/in-app-agent-persistence.servertest.ts@@ -1,7 +1,5 @@-vi.mock("@langfuse/shared/src/server/llm/llmText", async () => {- const actual = await vi.importActual(- "@langfuse/shared/src/server/llm/llmText",- );+vi.mock("@langfuse/shared/src/server", async () => {+ const actual = await vi.importActual("@langfuse/shared/src/server");return {...actual,generateLLMText: vi.fn(),@@ -19,9 +17,9 @@ import { type Plan } from "@langfuse/shared";import { prisma } from "@langfuse/shared/src/db";import {createOrgProjectAndApiKey,+ generateLLMText,getScoreById,} from "@langfuse/shared/src/server";-import { generateLLMText } from "@langfuse/shared/src/server/llm/llmText";import { env } from "@/src/env.mjs";import {InAppAgentRunErrorCode,@@ -246,16 +244,18 @@ describe("in-app agent persistence", () => {});});- it("allows oss-plan users to list conversations", async () => {+ it("rejects users without the in-app agent entitlement", async () => {const { caller, projectId } = await createCaller(`user-${randomUUID()}`,"oss",);- await expect(caller.listConversations({ projectId })).resolves.toEqual({- conversations: [],- nextCursor: undefined,- });+ await expect(caller.listConversations({ projectId })).rejects.toMatchObject(+ {+ code: "FORBIDDEN",+ message: expect.stringContaining("in-app-agent"),+ },+ );});const startCompactRun = async (params: {diff --git a/web/src/__tests__/server/organization-ai-features.servertest.ts b/web/src/__tests__/server/organization-ai-features.servertest.tsdeleted file mode 100644index 1f24c25c50..0000000000--- a/web/src/__tests__/server/organization-ai-features.servertest.ts+++ /dev/null@@ -1,154 +0,0 @@-import { randomUUID } from "crypto";-import type { Session } from "next-auth";-import { afterEach, beforeEach, describe, expect, it } from "vitest";--import { prisma } from "@langfuse/shared/src/db";-import { env as sharedEnv } from "@langfuse/shared/src/env";-import { env } from "@/src/env.mjs";-import { appRouter } from "@/src/server/api/root";-import { createInnerTRPCContext } from "@/src/server/api/trpc";--describe("organization AI feature settings", () => {- const originalCloudRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;- const originalSharedInAppAgentEnabled =- sharedEnv.LANGFUSE_IN_APP_AGENT_ENABLED;-- beforeEach(() => {- (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;- });-- afterEach(() => {- (env as any).NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = originalCloudRegion;- (sharedEnv as any).LANGFUSE_IN_APP_AGENT_ENABLED =- originalSharedInAppAgentEnabled;- });-- it("allows a self-hosted organization administrator to opt in to AI features", async () => {- const { caller, orgId } = await createCaller();-- await caller.organizations.update({- orgId,- aiFeaturesEnabled: true,- });-- await expect(- prisma.organization.findUniqueOrThrow({- where: { id: orgId },- select: { aiFeaturesEnabled: true },- }),- ).resolves.toEqual({ aiFeaturesEnabled: true });- });-- it("allows a self-hosted organization administrator to opt in to AI features when in-app agent is instance-disabled", async () => {- (sharedEnv as any).LANGFUSE_IN_APP_AGENT_ENABLED = "false";- const { caller, orgId } = await createCaller();-- await caller.organizations.update({- orgId,- aiFeaturesEnabled: true,- });-- await expect(- prisma.organization.findUniqueOrThrow({- where: { id: orgId },- select: { aiFeaturesEnabled: true },- }),- ).resolves.toEqual({ aiFeaturesEnabled: true });- });-- it("keeps AI telemetry controls Cloud-only", async () => {- const { caller, orgId } = await createCaller();-- await expect(- caller.organizations.update({- orgId,- aiTelemetryEnabled: false,- }),- ).rejects.toMatchObject({- code: "PRECONDITION_FAILED",- message: "AI telemetry controls are only available on Langfuse Cloud.",- });- });-});--async function createCaller() {- const id = randomUUID();- const orgId = `org-${id}`;- const projectId = `project-${id}`;- const userId = `user-${id}`;-- const organization = await prisma.organization.create({- data: {- id: orgId,- name: `Organization AI Features Test ${id}`,- },- });- const project = await prisma.project.create({- data: {- id: projectId,- orgId,- name: "Organization AI Features Test Project",- },- });- const user = await prisma.user.create({- data: {- id: userId,- email: `${userId}@example.com`,- name: "Organization AI Features Test User",- },- });-- const session: Session = {- expires: "1",- user: {- id: user.id,- email: user.email,- name: user.name,- canCreateOrganizations: true,- organizations: [- {- id: organization.id,- name: organization.name,- role: "OWNER",- plan: "self-hosted:enterprise",- cloudConfig: undefined,- metadata: {},- aiFeaturesEnabled: false,- aiTelemetryEnabled: true,- projects: [- {- id: project.id,- name: project.name,- role: "ADMIN",- deletedAt: null,- retentionDays: null,- hasTraces: false,- metadata: {},- createdAt: project.createdAt.toISOString(),- },- ],- },- ],- featureFlags: {- searchBar: false,- templateFlag: false,- excludeClickhouseRead: false,- observationEvals: false,- v4BetaToggleVisible: false,- experimentsV4Enabled: false,- },- admin: false,- },- environment: {- enableExperimentalFeatures: false,- selfHostedInstancePlan: "self-hosted:enterprise",- },- };-- const ctx = createInnerTRPCContext({ session, headers: {} });-- return {- orgId,- caller: appRouter.createCaller({ ...ctx, prisma }),- };-}diff --git a/web/src/components/nav/in-app-ai-agent-button.clienttest.tsx b/web/src/components/nav/in-app-ai-agent-button.clienttest.tsxindex 2c75d6b7da..10c23105e1 100644--- a/web/src/components/nav/in-app-ai-agent-button.clienttest.tsx+++ b/web/src/components/nav/in-app-ai-agent-button.clienttest.tsx@@ -10,7 +10,7 @@ const mocks = vi.hoisted(() => ({}));vi.mock("@/src/features/in-app-agent/components/InAppAiAgentProvider", () => ({- useIsInAppAgentLauncherVisible: () => true,+ useCanUseInAppAgent: () => true,useInAppAiAgent: () => ({open: mocks.open,attentionCount: mocks.attentionCount,diff --git a/web/src/components/nav/in-app-ai-agent-button.tsx b/web/src/components/nav/in-app-ai-agent-button.tsxindex 6ac1e2d737..bdf7ca677a 100644--- a/web/src/components/nav/in-app-ai-agent-button.tsx+++ b/web/src/components/nav/in-app-ai-agent-button.tsx@@ -4,7 +4,7 @@ import { BotMessageSquare } from "lucide-react";import { Button } from "@/src/components/ui/button";import { KeyboardShortcut } from "@/src/components/ui/keyboard-shortcut";import {- useIsInAppAgentLauncherVisible,+ useCanUseInAppAgent,useInAppAiAgent,type InAppAgentEntryPoint,} from "@/src/features/in-app-agent/components/InAppAiAgentProvider";@@ -24,7 +24,7 @@ export const InAppAiAgentButton = ({prominent?: boolean;} = {}) => {const { open, setOpen, openAssistant, attentionCount } = useInAppAiAgent();- const isInAppAgentLauncherVisible = useIsInAppAgentLauncherVisible();+ const canUseAssistant = useCanUseInAppAgent();const toggleAssistant = useCallback((source: InAppAgentEntryPoint) => {@@ -39,7 +39,7 @@ export const InAppAiAgentButton = ({);useEffect(() => {- if (!isInAppAgentLauncherVisible) {+ if (!canUseAssistant) {return;}@@ -60,9 +60,9 @@ export const InAppAiAgentButton = ({document.addEventListener("keydown", handleKeyDown);return () => document.removeEventListener("keydown", handleKeyDown);- }, [isInAppAgentLauncherVisible, toggleAssistant]);+ }, [canUseAssistant, toggleAssistant]);- if (!isInAppAgentLauncherVisible) {+ if (!canUseAssistant) {return null;}diff --git a/web/src/env.mjs b/web/src/env.mjsindex 0d907139bf..05d95b2243 100644--- a/web/src/env.mjs+++ b/web/src/env.mjs@@ -452,7 +452,6 @@ export const env = createEnv({// AWS Bedrock for langfuse native AI feature such as natural language filtersLANGFUSE_AWS_BEDROCK_MODEL: z.string().optional(),LANGFUSE_AWS_BEDROCK_SMALL_MODEL: z.string().optional(),- LANGFUSE_IN_APP_AGENT_ENABLED: z.enum(["true", "false"]).optional(),// Tracing for Langfuse AI FeaturesLANGFUSE_AI_FEATURES_HOST: z.string().optional(),@@ -978,7 +977,6 @@ export const env = createEnv({LANGFUSE_AWS_BEDROCK_MODEL: process.env.LANGFUSE_AWS_BEDROCK_MODEL,LANGFUSE_AWS_BEDROCK_SMALL_MODEL:process.env.LANGFUSE_AWS_BEDROCK_SMALL_MODEL,- LANGFUSE_IN_APP_AGENT_ENABLED: process.env.LANGFUSE_IN_APP_AGENT_ENABLED,// Langfuse Tracing AI FeaturesLANGFUSE_AI_FEATURES_HOST: process.env.LANGFUSE_AI_FEATURES_HOST,diff --git a/web/src/features/entitlements/constants/entitlements.ts b/web/src/features/entitlements/constants/entitlements.tsindex 39e880d326..1bac2d9c86 100644--- a/web/src/features/entitlements/constants/entitlements.ts+++ b/web/src/features/entitlements/constants/entitlements.ts@@ -30,7 +30,6 @@ const cloudAllPlansEntitlements: Entitlement[] = [const selfHostedAllPlansEntitlements: Entitlement[] = ["trace-deletion","scheduled-blob-exports",- "in-app-agent",];// Entitlement Limits: Limits on the number of resources that can be created/useddiff --git a/web/src/features/evals/pages/remap-evaluator.tsx b/web/src/features/evals/pages/remap-evaluator.tsxindex 629494a47a..2fa3f844a2 100644--- a/web/src/features/evals/pages/remap-evaluator.tsx+++ b/web/src/features/evals/pages/remap-evaluator.tsx@@ -22,7 +22,7 @@ import {import { BotMessageSquare, ChevronDown, Zap } from "lucide-react";import { useEvalCapabilities } from "@/src/features/evals/hooks/useEvalCapabilities";import {- useIsInAppAgentLauncherVisible,+ useCanUseInAppAgent,useInAppAiAgent,} from "@/src/features/in-app-agent/components/InAppAiAgentProvider";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";@@ -48,7 +48,7 @@ export default function RemapEvaluatorPage() {const evalConfigId = router.query.evaluator as string;const v4UpgradeUiEnabled = useV4UpgradeUiEnabled(projectId);const capture = usePostHogClientCapture();- const isInAppAgentLauncherVisible = useIsInAppAgentLauncherVisible();+ const canUseAssistant = useCanUseInAppAgent();const { openAssistant, submit } = useInAppAiAgent();const sdk = useProjectV4SdkData({projectId,@@ -231,7 +231,7 @@ export default function RemapEvaluatorPage() {align="top"actions={() => (<>- {isInAppAgentLauncherVisible ? (+ {canUseAssistant ? (<Buttonsize="sm"variant="secondary"diff --git a/web/src/features/in-app-agent/components/InAppAgentExecution.clienttest.tsx b/web/src/features/in-app-agent/components/InAppAgentExecution.clienttest.tsxindex 6e55f721a1..42d3f37f6a 100644--- a/web/src/features/in-app-agent/components/InAppAgentExecution.clienttest.tsx+++ b/web/src/features/in-app-agent/components/InAppAgentExecution.clienttest.tsx@@ -112,7 +112,6 @@ vi.mock("next/router", () => ({const sessionMocks = vi.hoisted(() => ({userId: "user-1" as string | undefined,aiFeaturesEnabled: true,- inAppAgentEnabled: true,isLangfuseCloud: true,}));@@ -120,7 +119,6 @@ vi.mock("next-auth/react", () => ({useSession: () => ({data: {user: { id: sessionMocks.userId, name: "Test User" },- environment: { inAppAgentEnabled: sessionMocks.inAppAgentEnabled },},}),}));@@ -281,7 +279,6 @@ describe("in-app agent execution", () => {beforeEach(() => {sessionMocks.userId = "user-1";sessionMocks.aiFeaturesEnabled = true;- sessionMocks.inAppAgentEnabled = true;sessionMocks.isLangfuseCloud = true;providerMocks.activityUseQuery.mockImplementation(() => providerMocks.activityQuery,@@ -304,10 +301,9 @@ describe("in-app agent execution", () => {window.sessionStorage.clear();});- // Polling uses useCanUseInAppAgent (org AI Features on). Entry points use- // useIsInAppAgentLauncherVisible, which still shows when AI Features are off- // so clicking can open the enable dialog. Polling with it off turns every- // page load and window focus into a Forbidden toast.+ // Gated more strictly than useCanUseInAppAgent, which ignores the org AI+ // toggle so the entry points can offer to turn it on. Polling with it off+ // turns every page load and window focus into a Forbidden toast.it("polls for activity only once AI features are on", () => {sessionMocks.aiFeaturesEnabled = false;@@ -334,20 +330,6 @@ describe("in-app agent execution", () => {);});- it("does not poll for activity when in-app agent is instance-disabled", () => {- sessionMocks.inAppAgentEnabled = false;-- render(- <InAppAiAgentProvider defaultOpen={false}>- <div />- </InAppAiAgentProvider>,- );-- expect(providerMocks.activityUseQuery.mock.calls.at(-1)?.[1]?.enabled).toBe(- false,- );- });-it("always allows a persisted background tool for the conversation", async () => {const approvedSnapshot = {conversation: {diff --git a/web/src/features/in-app-agent/components/InAppAgentWindowHost.clienttest.tsx b/web/src/features/in-app-agent/components/InAppAgentWindowHost.clienttest.tsxindex de813dc264..18055ef292 100644--- a/web/src/features/in-app-agent/components/InAppAgentWindowHost.clienttest.tsx+++ b/web/src/features/in-app-agent/components/InAppAgentWindowHost.clienttest.tsx@@ -8,7 +8,7 @@ const mocks = vi.hoisted(() => ({}));vi.mock("@/src/features/in-app-agent/components/InAppAiAgentProvider", () => ({- useIsInAppAgentLauncherVisible: () => true,+ useCanUseInAppAgent: () => true,useInAppAiAgent: () => ({deleteConversation: vi.fn(),isExpanded: false,diff --git a/web/src/features/in-app-agent/components/InAppAgentWindowHost.tsx b/web/src/features/in-app-agent/components/InAppAgentWindowHost.tsxindex 0ea0783a02..f4c626aa8c 100644--- a/web/src/features/in-app-agent/components/InAppAgentWindowHost.tsx+++ b/web/src/features/in-app-agent/components/InAppAgentWindowHost.tsx@@ -12,7 +12,7 @@ import {useInAppAgentWindowShellPanelControl,} from "@/src/features/in-app-agent/components/InAppAgentWindowShell";import {- useIsInAppAgentLauncherVisible,+ useCanUseInAppAgent,useInAppAiAgent,} from "@/src/features/in-app-agent/components/InAppAiAgentProvider";import { useWatchedPromiseCallback } from "@/src/hooks/useWatchedPromiseCallback";@@ -64,7 +64,7 @@ function DeleteConversationDialog({* window unmounts and its geometry resets on every navigation.*/export function InAppAgentWindowHost() {- const isInAppAgentLauncherVisible = useIsInAppAgentLauncherVisible();+ const canUseAgent = useCanUseInAppAgent();const { deleteConversation, open, setOpen, isExpanded, setIsExpanded } =useInAppAiAgent();const panelRef = useRef<HTMLDivElement>(null);@@ -121,9 +121,9 @@ export function InAppAgentWindowHost() {floatingPanelHandle.initializeGeometry();}, [floatingPanelHandle, isExpanded, open]);- // Only `isInAppAgentLauncherVisible` gates the tree: the shell owns the `open` guard- // so the handheld drawer stays mounted and can animate itself closed.- if (!isInAppAgentLauncherVisible) {+ // Only `canUseAgent` gates the tree: the shell owns the `open` guard so the+ // handheld drawer stays mounted and can animate itself closed.+ if (!canUseAgent) {return null;}diff --git a/web/src/features/in-app-agent/components/InAppAiAgentProvider.tsx b/web/src/features/in-app-agent/components/InAppAiAgentProvider.tsxindex c31ca99378..9b5d96a962 100644--- a/web/src/features/in-app-agent/components/InAppAiAgentProvider.tsx+++ b/web/src/features/in-app-agent/components/InAppAiAgentProvider.tsx@@ -54,6 +54,7 @@ import {import type { InAppAgentError } from "@/src/features/in-app-agent/components/utils/utils";import { useHasEntitlement } from "@/src/features/entitlements/hooks";import { showErrorToast } from "@/src/features/notifications/showErrorToast";+import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";import { useQueryProjectOrOrganization } from "@/src/features/projects/hooks";import { api } from "@/src/utils/api";import {@@ -292,7 +293,7 @@ function InAppAiAgentProviderInner({const utils = api.useUtils();const capture = usePostHogClientCapture();const session = useSession();- const canUseAssistant = useCanUseInAppAgent();+ const isInAppAgentEnabled = useIsInAppAgentEnabled();const { organization } = useQueryProjectOrOrganization();const [enableDialogOpen, setEnableDialogOpen] = useState(false);const [_selectedConversationId, setSelectedConversationId] =@@ -434,7 +435,7 @@ function InAppAiAgentProviderInner({userId,// Polling a project the server will reject turns every page load and// window focus into a Forbidden toast.- enabled: canUseAssistant,+ enabled: isInAppAgentEnabled,// Only what the user can actually see counts as looked at; a selected// conversation behind a closed window has not been read.visibleConversationId: open ? selectedConversationId : null,@@ -1590,39 +1591,34 @@ export function useInAppAiAgent() {return ctx;}-/** Whether a run would be admitted for this project. Client mirror of- * assertInAppAgentAvailable: instance switch, entitlement, and org AI- * Features. Use this for polling and other paths that must not hit the- * server when org AI Features is off. More restrictive than- * useIsInAppAgentLauncherVisible. */-export function useCanUseInAppAgent() {+/** Client mirror of the server's assertInAppAgentAvailable: whether a request+ * for this project would be served, so callers can skip ones it would reject. */+export function useIsInAppAgentEnabled() {const hasInAppAgentEntitlement = useHasEntitlement("in-app-agent");+ const { isLangfuseCloud } = useLangfuseCloudRegion();const { organization } = useQueryProjectOrOrganization();- const session = useSession();- const instanceEnabled = session.data?.environment.inAppAgentEnabled ?? false;return (- instanceEnabled &&+ isLangfuseCloud &&hasInAppAgentEntitlement &&Boolean(organization?.aiFeaturesEnabled));}-/** Whether to show Assistant entry points (nav launcher, v4/eval CTAs).- * Looser than useCanUseInAppAgent: with org AI Features off they still- * show, and clicking opens the dialog that turns it on. Hidden entirely- * when the instance-wide switch is off. */-export function useIsInAppAgentLauncherVisible() {+/** Whether the current user/context may use the in-app assistant at all. Shared+ * gate for the launcher button and the window host. Deliberately looser than+ * useIsInAppAgentEnabled: with the org AI toggle off the entry points still+ * show, and clicking one opens the dialog that turns it on. */+export function useCanUseInAppAgent() {const { isAvailable } = useInAppAiAgent();const hasInAppAgentEntitlement = useHasEntitlement("in-app-agent");+ const { isLangfuseCloud } = useLangfuseCloudRegion();const { organization } = useQueryProjectOrOrganization();- const session = useSession();- const instanceEnabled = session.data?.environment.inAppAgentEnabled ?? false;return (- instanceEnabled &&isAvailable &&hasInAppAgentEntitlement &&+ isLangfuseCloud &&Boolean(organization));}diff --git a/web/src/features/in-app-agent/server/availability.ts b/web/src/features/in-app-agent/server/availability.tsindex 0daa31993e..9544b74949 100644--- a/web/src/features/in-app-agent/server/availability.ts+++ b/web/src/features/in-app-agent/server/availability.ts@@ -2,11 +2,8 @@ import type { Session } from "next-auth";import { BaseError, ForbiddenError } from "@langfuse/shared";import type { PrismaClient } from "@langfuse/shared/src/db";-import {- getInAppAgentModelConfig,- isInAppAgentInstanceEnabled,-} from "@langfuse/shared/in-app-agent/server/modelProvider";+import { env } from "@/src/env.mjs";import { hasEntitlement } from "@/src/features/entitlements/server/hasEntitlement";export async function assertInAppAgentAvailable({@@ -18,11 +15,12 @@ export async function assertInAppAgentAvailable({projectId: string;user: NonNullable<Session["user"]>;}) {- if (!isInAppAgentInstanceEnabled()) {+ // TODO(LFE-14555): Remove this guard once the OSS release strategy is ready.+ if (!env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION) {throw new BaseError("PreconditionFailedError",412,- "In-app agent is not enabled on this instance.",+ "In-app agent is not available in this environment yet.",true,);}@@ -54,22 +52,8 @@ export async function assertInAppAgentAvailable({});if (!project?.organization.aiFeaturesEnabled) {- throw new ForbiddenError(- "In-app agent is not enabled for this organization",- );+ throw new ForbiddenError("Assistant is not enabled for this organization");}return project.organization;}--/** Only startRun and approval continuation dispatch to the model. */-export function assertInAppAgentModelConfigured() {- if (!getInAppAgentModelConfig()) {- throw new BaseError(- "PreconditionFailedError",- 412,- "In-app agent Bedrock model is not configured. Set LANGFUSE_AWS_BEDROCK_MODEL and LANGFUSE_AWS_BEDROCK_REGION.",- true,- );- }-}diff --git a/web/src/features/in-app-agent/server/router.ts b/web/src/features/in-app-agent/server/router.tsindex 92a2a40e05..da0a695968 100644--- a/web/src/features/in-app-agent/server/router.ts+++ b/web/src/features/in-app-agent/server/router.ts@@ -18,10 +18,7 @@ import {getInAppAgentInstrumentationTraceId,} from "@langfuse/shared/in-app-agent";import { InAppAgentMessageFeedbackValueSchema } from "../schema";-import {- assertInAppAgentAvailable,- assertInAppAgentModelConfigured,-} from "@/src/features/in-app-agent/server/availability";+import { assertInAppAgentAvailable } from "@/src/features/in-app-agent/server/availability";import {createTRPCRouter,protectedProjectProcedure,@@ -212,7 +209,6 @@ export const inAppAgentRouter = createTRPCRouter({projectId: input.projectId,user: ctx.session.user,});- assertInAppAgentModelConfigured();const rateLimitScope = getInAppAgentApiAccessScope(ctx.session.user,@@ -272,7 +268,6 @@ export const inAppAgentRouter = createTRPCRouter({projectId: input.projectId,user: ctx.session.user,});- assertInAppAgentModelConfigured();const rateLimitScope = getInAppAgentApiAccessScope(ctx.session.user,diff --git a/web/src/features/organizations/components/AIFeatureSwitch.tsx b/web/src/features/organizations/components/AIFeatureSwitch.tsxindex 72d1efd02d..ebd76261cc 100644--- a/web/src/features/organizations/components/AIFeatureSwitch.tsx+++ b/web/src/features/organizations/components/AIFeatureSwitch.tsx@@ -114,6 +114,8 @@ export default function AIFeatureSwitch() {});}+ if (!isLangfuseCloud) return null;+return (<div><Header title="AI Features" />@@ -123,30 +125,22 @@ export default function AIFeatureSwitch() {<h4 className="font-bold">Enable AI powered features for your organization</h4>- {isLangfuseCloud ? (- <p className="text-sm">- This setting applies to all users and projects. Any data{" "}- <i>can</i> be sent to AWS Bedrock within the Langfuse data- region. Traces are sent to Langfuse Cloud in your data region.- Your data will not be used for training models. Applicable- HIPAA, SOC2, GDPR, and ISO 27001 compliance remains intact.{" "}- <a- href="https://langfuse.com/security/ai-features"- target="_blank"- rel="noopener noreferrer"- className="text-primary inline-flex items-center gap-1 hover:underline"- >- More details in the docs here.- <ExternalLink className="h-3 w-3" />- </a>- </p>- ) : (- <p className="text-sm">- This setting applies to all users and projects. When enabled,- the assistant can send relevant project data to the model- provider configured by your instance administrator.- </p>- )}+ <p className="text-sm">+ This setting applies to all users and projects. Any data{" "}+ <i>can</i> be sent to AWS Bedrock within the Langfuse data region.+ Traces are sent to Langfuse Cloud in your data region. Your data+ will not be used for training models. Applicable HIPAA, SOC2,+ GDPR, and ISO 27001 compliance remains intact.{" "}+ <a+ href="https://langfuse.com/security/ai-features"+ target="_blank"+ rel="noopener noreferrer"+ className="text-primary inline-flex items-center gap-1 hover:underline"+ >+ More details in the docs here.+ <ExternalLink className="h-3 w-3" />+ </a>+ </p></div><div className="relative"><Switch@@ -161,7 +155,7 @@ export default function AIFeatureSwitch() {)}</div></div>- {isLangfuseCloud && isAIFeatureSwitchEnabled && (+ {isAIFeatureSwitchEnabled && (<div className="mt-4 flex flex-row items-center justify-between border-t pt-4"><div className="flex flex-col gap-1"><h4 className="font-bold">@@ -206,27 +200,20 @@ export default function AIFeatureSwitch() {<strong>{isAIFeatureSwitchEnabled ? "enable " : "disable"}</strong>{" "}- AI features for your organization. When enabled, relevant data can- be sent{" "}- {isLangfuseCloud- ? "to AWS Bedrock in your data region"- : "to the model provider configured by your instance administrator"}{" "}- for processing.- {isLangfuseCloud && (- <>- <br />- <br />{" "}- <a- href="https://langfuse.com/security/ai-features"- target="_blank"- rel="noopener noreferrer"- className="text-primary inline-flex items-center gap-1 hover:underline"- >- Learn more in the docs.- <ExternalLink className="h-3 w-3" />- </a>- </>- )}+ AI features for your organization. When enabled, any data{" "}+ <i>can</i> be sent to AWS Bedrock in your data region for+ processing.+ <br />+ <br />{" "}+ <a+ href="https://langfuse.com/security/ai-features"+ target="_blank"+ rel="noopener noreferrer"+ className="text-primary inline-flex items-center gap-1 hover:underline"+ >+ Learn more in the docs.+ <ExternalLink className="h-3 w-3" />+ </a></span><p className="text-muted-foreground mt-3 text-sm">Are you sure you want to proceed?diff --git a/web/src/features/organizations/server/organizationRouter.ts b/web/src/features/organizations/server/organizationRouter.tsindex 9c457f296c..fc77a204e6 100644--- a/web/src/features/organizations/server/organizationRouter.ts+++ b/web/src/features/organizations/server/organizationRouter.ts@@ -194,13 +194,13 @@ export const organizationsRouter = createTRPCRouter({});if (- input.aiTelemetryEnabled !== undefined &&+ (input.aiFeaturesEnabled !== undefined ||+ input.aiTelemetryEnabled !== undefined) &&!env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION) {throw new TRPCError({code: "PRECONDITION_FAILED",- message:- "AI telemetry controls are only available on Langfuse Cloud.",+ message: "AI features are not available in self-hosted deployments.",});}diff --git a/web/src/features/v4-migration/EvaluatorMigrationDialog.tsx b/web/src/features/v4-migration/EvaluatorMigrationDialog.tsxindex 511e5279b0..c26d682266 100644--- a/web/src/features/v4-migration/EvaluatorMigrationDialog.tsx+++ b/web/src/features/v4-migration/EvaluatorMigrationDialog.tsx@@ -11,7 +11,7 @@ import {import { Button } from "@/src/components/ui/button";import { CodeBlock } from "@/src/components/design-system/Codeblock/Codeblock";import {- useIsInAppAgentLauncherVisible,+ useCanUseInAppAgent,useInAppAiAgent,} from "@/src/features/in-app-agent/components/InAppAiAgentProvider";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";@@ -47,7 +47,7 @@ export function EvaluatorMigrationDialog({onAssistantStarted,initialAction,}: EvaluatorMigrationDialogProps) {- const isInAppAgentLauncherVisible = useIsInAppAgentLauncherVisible();+ const canUseAssistant = useCanUseInAppAgent();const { organization } = useQueryProjectOrOrganization();const { openAssistant, submit } = useInAppAiAgent();const canUpdateOrgSettings = useHasOrganizationAccess({@@ -60,7 +60,7 @@ export function EvaluatorMigrationDialog({const aiFeaturesEnabled = Boolean(organization?.aiFeaturesEnabled);const isSingleEvaluator = scope.type === "single";- const showAssistantOption = isInAppAgentLauncherVisible;+ const showAssistantOption = canUseAssistant;// With AI features disabled, the choice screen's assistant option owns the// enable-AI and admin-handoff side effects, so the preselect only applies// once the assistant can actually start.diff --git a/web/src/features/v4-migration/V4MigrationContent.clienttest.tsx b/web/src/features/v4-migration/V4MigrationContent.clienttest.tsxindex 0e95dddaea..a1ed32e399 100644--- a/web/src/features/v4-migration/V4MigrationContent.clienttest.tsx+++ b/web/src/features/v4-migration/V4MigrationContent.clienttest.tsx@@ -226,7 +226,7 @@ vi.mock("@/src/features/v4-migration/useV4UpgradeAssistantSupport", () => ({}));vi.mock("@/src/features/in-app-agent/components/InAppAiAgentProvider", () => ({- useIsInAppAgentLauncherVisible: () => true,+ useCanUseInAppAgent: () => true,useInAppAiAgent: () => ({openAssistant: mocks.openAssistant,submit: mocks.submitAgentMessage,diff --git a/web/src/features/v4-migration/V4MigrationContent.tsx b/web/src/features/v4-migration/V4MigrationContent.tsxindex 572967d785..c9381e62f5 100644--- a/web/src/features/v4-migration/V4MigrationContent.tsx+++ b/web/src/features/v4-migration/V4MigrationContent.tsx@@ -10,7 +10,7 @@ import {Info,} from "lucide-react";import { env } from "@/src/env.mjs";-import { useIsInAppAgentLauncherVisible } from "@/src/features/in-app-agent/components/InAppAiAgentProvider";+import { useCanUseInAppAgent } from "@/src/features/in-app-agent/components/InAppAiAgentProvider";import { useSupportDrawer } from "@/src/features/support-chat/SupportDrawerProvider";import { Button } from "@/src/components/ui/button";import {@@ -1401,7 +1401,7 @@ export function V4MigrationDetailsContent({onNavigate?.();openSupportDrawerWithMode("form", { topic: "V4 Migration" });};- const isInAppAgentLauncherVisible = useIsInAppAgentLauncherVisible();+ const canUseAssistant = useCanUseInAppAgent();// Same org source as EvaluatorMigrationDialog's gating, so the button// branding and the dialog's preselect can't disagree.const { organization: routeOrganization } = useQueryProjectOrOrganization();@@ -1461,7 +1461,7 @@ export function V4MigrationDetailsContent({<V4MigrationEvalsSectionstate={migrationData.evals}assistant={- isInAppAgentLauncherVisible+ canUseAssistant? {onMigrate: handleMigrateEvalsWithAgent,aiFeaturesEnabled,diff --git a/web/src/features/v4-migration/V4MigrationDelayBadge.clienttest.tsx b/web/src/features/v4-migration/V4MigrationDelayBadge.clienttest.tsxindex 06ae234eea..a1b42a26fc 100644--- a/web/src/features/v4-migration/V4MigrationDelayBadge.clienttest.tsx+++ b/web/src/features/v4-migration/V4MigrationDelayBadge.clienttest.tsx@@ -161,7 +161,7 @@ vi.mock("@/src/features/v4-migration/hooks/useV4MigrationData", () => ({}));vi.mock("@/src/features/in-app-agent/components/InAppAiAgentProvider", () => ({- useIsInAppAgentLauncherVisible: () => false,+ useCanUseInAppAgent: () => false,useInAppAiAgent: () => ({ setOpen: vi.fn(), submit: vi.fn() }),}));diff --git a/web/src/features/v4-migration/useV4UpgradeAssistantSupport.clienttest.ts b/web/src/features/v4-migration/useV4UpgradeAssistantSupport.clienttest.tsindex cbd794e037..6436f6efa1 100644--- a/web/src/features/v4-migration/useV4UpgradeAssistantSupport.clienttest.ts+++ b/web/src/features/v4-migration/useV4UpgradeAssistantSupport.clienttest.ts@@ -5,7 +5,7 @@ import { describe, expect, it, vi } from "vitest";import { V4_CODING_AGENT_PROMPT } from "./useV4UpgradeAssistantSupport";vi.mock("@/src/features/in-app-agent/components/InAppAiAgentProvider", () => ({- useIsInAppAgentLauncherVisible: () => true,+ useCanUseInAppAgent: () => true,}));describe("V4_CODING_AGENT_PROMPT", () => {diff --git a/web/src/features/v4-migration/useV4UpgradeAssistantSupport.ts b/web/src/features/v4-migration/useV4UpgradeAssistantSupport.tsindex 4bcb953318..79afb8ef60 100644--- a/web/src/features/v4-migration/useV4UpgradeAssistantSupport.ts+++ b/web/src/features/v4-migration/useV4UpgradeAssistantSupport.ts@@ -1,4 +1,4 @@-import { useIsInAppAgentLauncherVisible } from "@/src/features/in-app-agent/components/InAppAiAgentProvider";+import { useCanUseInAppAgent } from "@/src/features/in-app-agent/components/InAppAiAgentProvider";import { useProjectV4SdkData } from "@/src/features/v4-migration/hooks/useV4MigrationData";import { api } from "@/src/utils/api";@@ -57,7 +57,7 @@ export function useEvalUpgradeAssistantPlan(params: {projectId: string | undefined;enabled: boolean;}) {- const isInAppAgentLauncherVisible = useIsInAppAgentLauncherVisible();+ const canUseAssistant = useCanUseInAppAgent();const sdk = useProjectV4SdkData(params);const evalQuery = api.v4Transition.traceLevelEvalSummary.useQuery({ projectId: params.projectId ?? "" },@@ -77,10 +77,10 @@ export function useEvalUpgradeAssistantPlan(params: {: "outside";return {- canUseAssistant: isInAppAgentLauncherVisible,+ canUseAssistant,mode,/** Whether the migration panel may show the Assistant CTA. */- showAssistantButton: isInAppAgentLauncherVisible && mode !== "outside",+ showAssistantButton: canUseAssistant && mode !== "outside",assistantPrompt:mode === "evals-ready"? EVAL_UPGRADE_ASSISTANT_PROMPTdiff --git a/web/src/server/auth.ts b/web/src/server/auth.tsindex 0188cff64c..281633bd5e 100644--- a/web/src/server/auth.ts+++ b/web/src/server/auth.ts@@ -6,7 +6,6 @@ import {} from "next-auth";import { PrismaAdapter } from "@next-auth/prisma-adapter";import { prisma } from "@langfuse/shared/src/db";-import { isInAppAgentInstanceEnabled } from "@langfuse/shared/in-app-agent/server/modelProvider";import {hashPassword,verifyPassword,@@ -880,7 +879,6 @@ export async function getAuthOptions(signupAttribution?: {environment: {enableExperimentalFeatures:env.LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES === "true",- inAppAgentEnabled: isInAppAgentInstanceEnabled(),// Enables features that are only available under an enterprise license when self-hosting Langfuse// If you edit this line, you risk executing code that is not MIT licensed (self-contained in /ee folders otherwise)selfHostedInstancePlan: getSelfHostedInstancePlanServerSide(),diff --git a/web/types/next-auth.d.ts b/web/types/next-auth.d.tsindex 5b3ccd2f57..24bb2b71ea 100644--- a/web/types/next-auth.d.ts+++ b/web/types/next-auth.d.ts@@ -57,9 +57,6 @@ declare module "next-auth" {environment: {// Run-time environment variables that need to be available client-sideenableExperimentalFeatures: boolean;- // Instance-wide in-app agent switch. Populated by the session callback.- // Optional so existing session mocks need not set it.- inAppAgentEnabled?: boolean;// Enables features that are only available under an enterprise/commercial license when self-hosting LangfuseselfHostedInstancePlan: Plan | null;// V4 migration write mode. Mirrors LANGFUSE_MIGRATION_V4_WRITE_MODE so thediff --git a/worker/package.json b/worker/package.jsonindex 87456b4ca2..b13fa6b79f 100644--- a/worker/package.json+++ b/worker/package.json@@ -37,6 +37,7 @@"@appsignal/opentelemetry-instrumentation-bullmq": "^0.8.0","@langfuse/shared": "workspace:*","@aws-sdk/client-lambda-microvms": "catalog:",+ "@aws-sdk/credential-providers": "catalog:","@mastra/core": "1.46.0","@mastra/mcp": "1.8.1","@opentelemetry/api": "^1.9.1",diff --git a/worker/src/features/in-app-agent/executeInAppAgentRun.test.ts b/worker/src/features/in-app-agent/executeInAppAgentRun.test.tsindex 2de17464b3..8dd39e241f 100644--- a/worker/src/features/in-app-agent/executeInAppAgentRun.test.ts+++ b/worker/src/features/in-app-agent/executeInAppAgentRun.test.ts@@ -35,13 +35,9 @@ type AgentScenario = (ctx: {};signal: AbortSignal;options: {- model: {- provider: "bedrock";- modelId: string;+ awsBedrock: {+ profile?: string;};- awsProfile?: string;- langfuseClient?: unknown;- useLocalPrompt: boolean;langfuseMcp: {toolPolicy: {available: ReadonlySet<string>;@@ -63,7 +59,6 @@ const scenarioRef = vi.hoisted(() => ({failApiKeyDelete: false,apiKeyDeleteCalls: 0,titleInferenceCalls: 0,- instanceEnabled: true,}));vi.mock("./runtime/agent", async (importOriginal) => {@@ -108,21 +103,6 @@ vi.mock(}),);-vi.mock(- "@langfuse/shared/in-app-agent/server/modelProvider",- async (importOriginal) => {- const actual =- await importOriginal<- typeof import("@langfuse/shared/in-app-agent/server/modelProvider")- >();-- return {- ...actual,- isInAppAgentInstanceEnabled: () => scenarioRef.instanceEnabled,- };- },-);-vi.mock("@langfuse/shared/src/server/auth/apiKeys", async (importOriginal) => {const actual =await importOriginal<@@ -291,7 +271,6 @@ async function seedApprovedContinuation(opts?: {describe("executeInAppAgentRun", () => {beforeEach(() => {scenarioRef.titleInferenceCalls = 0;- scenarioRef.instanceEnabled = true;});it("does not regenerate the conversation title after executing a user-message run", async () => {@@ -317,7 +296,7 @@ describe("executeInAppAgentRun", () => {const { projectId, run } = await seedBackgroundRun();scenarioRef.current = async ({ options }) => {- expect(options.awsProfile).toBe("developer-profile");+ expect(options.awsBedrock.profile).toBe("developer-profile");await options.onComplete();await options.onFinish();};@@ -330,25 +309,6 @@ describe("executeInAppAgentRun", () => {}});- it("uses the bundled prompt in self-hosted production", async () => {- const originalCloudRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;- env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;-- const { projectId, run } = await seedBackgroundRun();- scenarioRef.current = async ({ options }) => {- expect(options.useLocalPrompt).toBe(true);- expect(options.langfuseClient).toBeUndefined();- await options.onComplete();- await options.onFinish();- };-- try {- await executeInAppAgentRun({ projectId, runId: run.id });- } finally {- env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = originalCloudRegion;- }- });-it("passes persisted continuation context to the agent input", async () => {const rootRunId = "root-run-1";const traceStartedAt = "2026-08-14T10:00:00.000Z";@@ -754,21 +714,6 @@ describe("executeInAppAgentRun", () => {expect(await getInAppAgentApiKeys(projectId)).toHaveLength(0);});- it("fails revalidation at claim as FAILED (init_failed) when in-app agent is instance-disabled", async () => {- scenarioRef.instanceEnabled = false;- const { projectId, run } = await seedBackgroundRun();- scenarioRef.current = async () => {- throw new Error("agent loop must not start when the instance is off");- };-- await executeInAppAgentRun({ projectId, runId: run.id });-- const failed = await getRun(projectId, run.id);- expect(failed.status).toBe("FAILED");- expect(failed.errorCode).toBe("init_failed");- expect(await getInAppAgentApiKeys(projectId)).toHaveLength(0);- });-it("keeps the MCP-key pointer when the delete fails, for reconciliation to retry", async () => {const { projectId, run } = await seedBackgroundRun();diff --git a/worker/src/features/in-app-agent/executeInAppAgentRun.ts b/worker/src/features/in-app-agent/executeInAppAgentRun.tsindex 05dd1d3349..a712285b11 100644--- a/worker/src/features/in-app-agent/executeInAppAgentRun.ts+++ b/worker/src/features/in-app-agent/executeInAppAgentRun.ts@@ -1,5 +1,6 @@import { Role } from "@langfuse/shared";import { prisma } from "@langfuse/shared/src/db";+import { env as sharedEnv } from "@langfuse/shared/src/env";import {getLangfuseAITraceSinkParams,logger,@@ -28,10 +29,6 @@ import {toPersistableAgentEvent,type PersistedConversationEvent,} from "@langfuse/shared/in-app-agent/server/persistence";-import {- getInAppAgentModelConfig,- isInAppAgentInstanceEnabled,-} from "@langfuse/shared/in-app-agent/server/modelProvider";import {claimQueuedRun,clearRunMcpApiKeyPointer,@@ -156,23 +153,20 @@ export async function executeInAppAgentRun(params: {try {// ---- Revalidate at claim; nothing from enqueue time is trusted. ----- if (!isInAppAgentInstanceEnabled()) {+ if (!env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION) {throw new InAppAgentRunInitError(- "In-app agent is not enabled on this instance",+ "In-app agent is only available on Langfuse Cloud",);}- const modelConfig = getInAppAgentModelConfig({ modelId: run.model });+ const bedrockModelId = run.model ?? sharedEnv.LANGFUSE_AWS_BEDROCK_MODEL;- if (!modelConfig) {+ if (!bedrockModelId || !sharedEnv.LANGFUSE_AWS_BEDROCK_REGION) {throw new InAppAgentRunInitError(- "In-app agent Bedrock model is not configured",+ "Assistant Bedrock model is not configured",);}- const useBundledPrompt =- env.NODE_ENV === "development" || !env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;-const conversation = await prisma.inAppAgentConversation.findFirst({where: { id: run.conversationId, projectId, deletedAt: null },});@@ -506,8 +500,11 @@ export async function executeInAppAgentRun(params: {await cleanupMcpApiKeyLogged();await sandboxState?.onTurnEnded();},- model: modelConfig,- ...(awsProfile ? { awsProfile } : {}),+ awsBedrock: {+ region: sharedEnv.LANGFUSE_AWS_BEDROCK_REGION,+ modelId: bedrockModelId,+ ...(awsProfile ? { profile: awsProfile } : {}),+ },langfuseMcp: {url: getLangfuseMcpUrl(),publicKey: mcpApiKey.publicKey,@@ -519,10 +516,8 @@ export async function executeInAppAgentRun(params: {projectId,isV4Enabled: access.v4BetaEnabled,},- useLocalPrompt: useBundledPrompt,- ...(useBundledPrompt- ? {}- : { langfuseClient: getInAppAgentPromptClient() }),+ langfuseClient: getInAppAgentPromptClient(),+ useLocalPrompt: env.NODE_ENV === "development",langfuseTracing: buildTracingConfig({aiTelemetryEnabled: project.organization.aiTelemetryEnabled,projectId,diff --git a/worker/src/features/in-app-agent/runtime/agent.test.ts b/worker/src/features/in-app-agent/runtime/agent.test.tsindex 9328390ab2..3207df5ee8 100644--- a/worker/src/features/in-app-agent/runtime/agent.test.ts+++ b/worker/src/features/in-app-agent/runtime/agent.test.ts@@ -25,13 +25,6 @@ import type { InAppAgentTracingConfig } from "./instrumentation";const EXPECTED_MCP_USER_AGENT = "langfuse-in-app-agent";-const testBedrockModel = (modelId: string) => ({- provider: "bedrock" as const,- modelId,- titleModelId: modelId,- region: "eu-central-1",-});-// Shape of the tool entries the mocked MCP client feeds into the Agent// constructor. `Agent`'s own `tools` type is a `DynamicArgument` union that// does not allow property access, so tests read it through this view.@@ -479,10 +472,7 @@ describe("createAgUiStream", () => {});});- const initializeBasicTracedAgent = async (- runId: string,- model = testBedrockModel("test-model"),- ) => {+ const initializeBasicTracedAgent = async (runId: string) => {const { createAgUiStream } = await import("./agent");const input = {threadId: "conversation-1",@@ -516,7 +506,7 @@ describe("createAgUiStream", () => {input,signal: new AbortController().signal,options: {- model,+ awsBedrock: { modelId: "test-model" },langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -534,18 +524,6 @@ describe("createAgUiStream", () => {await readStream(stream);};- it("uses the shared Bedrock default-credential auth", async () => {- const { createAmazonBedrock } = await import("ai-sdk-amazon-bedrock-v4");-- await initializeBasicTracedAgent("run-default-bedrock-auth");-- expect(createAmazonBedrock).toHaveBeenCalledWith({- region: "eu-central-1",- apiKey: "",- credentialProvider: expect.any(Function),- });- });-it("forwards model stream parts when finish tracing throws", async () => {instrumentationMocks.instrumentation.recordModelStreamPart.mockImplementationOnce(() => undefined)@@ -707,7 +685,9 @@ describe("createAgUiStream", () => {eventOrder.push(`persist:${event.type}`);await Promise.resolve();},- model: testBedrockModel("eu.anthropic.claude-opus-4-8"),+ awsBedrock: {+ modelId: "eu.anthropic.claude-opus-4-8",+ },langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -993,7 +973,9 @@ describe("createAgUiStream", () => {input,signal: new AbortController().signal,options: {- model: testBedrockModel("meta.llama3-70b-instruct-v1:0"),+ awsBedrock: {+ modelId: "meta.llama3-70b-instruct-v1:0",+ },langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -1064,7 +1046,7 @@ describe("createAgUiStream", () => {input,signal: new AbortController().signal,options: {- model: testBedrockModel("eu.anthropic.claude-opus-4-8"),+ awsBedrock: { modelId: "eu.anthropic.claude-opus-4-8" },langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -1161,7 +1143,7 @@ describe("createAgUiStream", () => {onEvent: (event) => {persistedEvents.push(event);},- model: testBedrockModel("test-model"),+ awsBedrock: { modelId: "test-model" },langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -1233,7 +1215,7 @@ describe("createAgUiStream", () => {input,signal: new AbortController().signal,options: {- model: testBedrockModel("eu.anthropic.claude-opus-4-8"),+ awsBedrock: { modelId: "eu.anthropic.claude-opus-4-8" },langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -1281,7 +1263,7 @@ describe("createAgUiStream", () => {onEvent: (event) => {persistedEvents.push(event);},- model: testBedrockModel("test-model"),+ awsBedrock: { modelId: "test-model" },langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -1568,7 +1550,7 @@ describe("createAgUiStream", () => {onEvent: (event) => {persistedEvents.push(event);},- model: testBedrockModel("test-model"),+ awsBedrock: { modelId: "test-model" },langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -1645,7 +1627,7 @@ describe("createAgUiStream", () => {persistedEvents.push(event);},onError,- model: testBedrockModel("test-model"),+ awsBedrock: { modelId: "test-model" },langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -1809,7 +1791,7 @@ describe("createAgUiStream", () => {input,signal: new AbortController().signal,options: {- model: testBedrockModel("test-model"),+ awsBedrock: { modelId: "test-model" },langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -1890,7 +1872,7 @@ describe("createAgUiStream", () => {persistedEvents.push(event);},onComplete,- model: testBedrockModel("test-model"),+ awsBedrock: { modelId: "test-model" },langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -2039,7 +2021,7 @@ describe("createAgUiStream", () => {input,signal: new AbortController().signal,options: {- model: testBedrockModel("test-model"),+ awsBedrock: { modelId: "test-model" },langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -2127,7 +2109,7 @@ describe("createAgUiStream", () => {input,signal: new AbortController().signal,options: {- model: testBedrockModel("test-model"),+ awsBedrock: { modelId: "test-model" },langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",diff --git a/worker/src/features/in-app-agent/runtime/agent.ts b/worker/src/features/in-app-agent/runtime/agent.tsindex 2291dd1527..deb8cd5c80 100644--- a/worker/src/features/in-app-agent/runtime/agent.ts+++ b/worker/src/features/in-app-agent/runtime/agent.ts@@ -2,6 +2,7 @@ import { EventType } from "@ag-ui/core";import { MastraAgent } from "@ag-ui/mastra";import { IN_APP_AGENT_SYSTEM_PROMPT_TEMPLATE } from "@langfuse/shared/in-app-agent/server/systemPrompt";import { createAmazonBedrock } from "ai-sdk-amazon-bedrock-v4";+import { fromNodeProviderChain } from "@aws-sdk/credential-providers";import { Agent } from "@mastra/core/agent";import { MCPClient } from "@mastra/mcp";import type { Langfuse } from "langfuse";@@ -44,15 +45,11 @@ import {import { LANGFUSE_IN_APP_AGENT_SKILLS } from "./skills";import type { InAppAgentSandbox } from "./sandbox";import { DEFAULT_SIDEBAR_HIDDEN_ENVIRONMENTS } from "@langfuse/shared";-import {- createDefaultBedrockProviderAuth,- logger,-} from "@langfuse/shared/src/server";+import { logger } from "@langfuse/shared/src/server";import {IN_APP_AGENT_MCP_TOOL_OVERRIDE_HEADER,IN_APP_AGENT_REDIRECT_TOOL_NAME,} from "@langfuse/shared/in-app-agent";-import type { InAppAgentModelConfig } from "@langfuse/shared/in-app-agent/server/modelProvider";const ASSISTANT_TITLE = "Langfuse Assistant";const IN_APP_AGENT_SYSTEM_PROMPT_NAME = "in-app-agent-system-prompt";@@ -185,8 +182,11 @@ type CreateAgUiStreamOptions = {onAbort?: () => void | Promise<void>;onError?: (error: unknown) => void | Promise<void>;onFinish?: () => void | Promise<void>;- model: InAppAgentModelConfig;- awsProfile?: string;+ awsBedrock: {+ region?: string;+ profile?: string;+ modelId: string;+ };langfuseMcp: {url: string;publicKey: string;@@ -198,7 +198,7 @@ type CreateAgUiStreamOptions = {projectId: string;isV4Enabled: boolean;};- langfuseClient?: Langfuse;+ langfuseClient: Langfuse;useLocalPrompt: boolean;langfuseTracing?: InAppAgentTracingConfig;sandbox?: InAppAgentSandbox;@@ -212,7 +212,7 @@ export async function createAgUiStream(params: {options: CreateAgUiStreamOptions;}) {const encoder = new TextEncoder();- const awsProfile = params.options.awsProfile;+ const awsProfile = params.options.awsBedrock.profile;const langfuseMcpAuthHeader = `Basic ${Buffer.from(`${params.options.langfuseMcp.publicKey}:${params.options.langfuseMcp.secretKey}`,@@ -236,7 +236,7 @@ export async function createAgUiStream(params: {tracing: params.options.langfuseTracing? { ...params.options.langfuseTracing, prompt }: undefined,- model: params.options.model.modelId,+ model: params.options.awsBedrock.modelId,});const recordInstrumentation = (operation: string,@@ -846,17 +846,15 @@ type ExecutableInAppAgentTool = {toModelOutput?: (output: unknown) => unknown | PromiseLike<unknown>;};-type InAppAgentLanguageModel = ReturnType<- ReturnType<typeof createAmazonBedrock>->;+type BedrockLanguageModel = ReturnType<ReturnType<typeof createAmazonBedrock>>;function withModelTracing(- model: InAppAgentLanguageModel,+ model: BedrockLanguageModel,callbacks: {onStart?: (options: unknown) => void;onStreamPart?: (part: unknown) => void;},-): InAppAgentLanguageModel {+): BedrockLanguageModel {if (!callbacks.onStart && !callbacks.onStreamPart) {return model;}@@ -943,9 +941,11 @@ async function createMastraAdapter(params: {onToolExecutionEnd?: (toolCallId: string) => void;}) {const bedrock = createAmazonBedrock({- region: params.options.model.region,- ...createDefaultBedrockProviderAuth(- params.awsProfile ? { profile: params.awsProfile } : undefined,+ ...(params.options.awsBedrock.region+ ? { region: params.options.awsBedrock.region }+ : {}),+ credentialProvider: fromNodeProviderChain(+ params.awsProfile ? { profile: params.awsProfile } : {},),});@@ -1061,7 +1061,7 @@ async function createMastraAdapter(params: {params.onToolsAvailable?.(tools);const reasoningProviderOptions = getBedrockReasoningProviderOptions(- params.options.model.modelId,+ params.options.awsBedrock.modelId,);// @ag-ui/mastra currently forwards only assistant, user, and tool@@ -1071,7 +1071,9 @@ async function createMastraAdapter(params: {// guidance on resumed runs.let developerGuidance: string | undefined;const model = withModelTracing(- bedrock(params.options.model.modelId as Parameters<typeof bedrock>[0]),+ bedrock(+ params.options.awsBedrock.modelId as Parameters<typeof bedrock>[0],+ ),{onStart: params.onModelCallStart,onStreamPart: params.onModelStreamPart,@@ -1371,7 +1373,7 @@ function getToolErrorMessage(chunk: MastraApprovalStreamChunk): string {}async function getSystemPromptInstructions(params: {- langfuseClient?: Langfuse;+ langfuseClient: Langfuse;useLocalPrompt: boolean;variables: {currentDate: string;@@ -1395,10 +1397,6 @@ async function getSystemPromptInstructions(params: {};}- if (!params.langfuseClient) {- throw new Error("Managed in-app agent prompt client is not configured");- }-const prompt = await params.langfuseClient.getPrompt(IN_APP_AGENT_SYSTEM_PROMPT_NAME,undefined,@@ -1460,7 +1458,7 @@ function createRunErrorEvent(error: unknown,): AgUiEvent {const message =- error instanceof Error ? error.message : "Unknown in-app agent error";+ error instanceof Error ? error.message : "Unknown assistant error";return {type: EventType.RUN_ERROR,@@ -1473,5 +1471,5 @@ function createRunErrorEvent(function getRunErrorMessage(event: AgUiEvent) {return typeof event.message === "string" && event.message.trim()? event.message- : "Unknown in-app agent error";+ : "Unknown assistant error";}diff --git a/worker/src/features/in-app-agent/runtime/instrumentation.ts b/worker/src/features/in-app-agent/runtime/instrumentation.tsindex 0cfecf2e53..114373d8e0 100644--- a/worker/src/features/in-app-agent/runtime/instrumentation.ts+++ b/worker/src/features/in-app-agent/runtime/instrumentation.ts@@ -536,7 +536,7 @@ export class InAppAgentInstrumentation {this.endWithError(typeof event.message === "string"? event.message- : "Unknown in-app agent error",+ : "Unknown assistant error",);return;}