🪢 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): Foundation to make in-app agent available in OSS (self-hosted setups) (#16284)
Lysander Kiesele0c78264afa8
diff --git a/.env.dev.example b/.env.dev.exampleindex 7a377d2916..0381ecf79c 100644--- a/.env.dev.example+++ b/.env.dev.example@@ -201,6 +201,9 @@ 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 9f6439f9d1..822f82b65f 100644--- a/docker-compose.build.yml+++ b/docker-compose.build.yml@@ -54,6 +54,19 @@ 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"]@@ -76,6 +89,17 @@ 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 028eddf772..8657364684 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -73,6 +73,27 @@ 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@@ -93,6 +114,9 @@ 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 0f7b5ca3a8..7791acd883 100644--- a/packages/shared/AGENTS.md+++ b/packages/shared/AGENTS.md@@ -45,7 +45,8 @@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`), and server test utilities.+ `streamLLMText`), Bedrock default-credential provider auth+ (`createDefaultBedrockProviderAuth`), 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.@@ -60,12 +61,13 @@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`, and `systemPrompt`. These are storage/lifecycle or durable- cross-process policy contracts; the Mastra runtime and sandbox belong to the- worker.+ `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.- Narrower exported subpaths also exist for targeted imports:`@langfuse/shared/src/server/auth/apiKeys`,- `@langfuse/shared/src/server/ee/ingestionMasking`, and+ `@langfuse/shared/src/server/ee/ingestionMasking`,+ `@langfuse/shared/src/server/llm/llmText`, 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 91538fab2e..7d0fd39cce 100644--- a/packages/shared/package.json+++ b/packages/shared/package.json@@ -31,6 +31,10 @@"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"@@ -98,6 +102,10 @@"./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 8fd573c109..53ec693f3d 100644--- a/packages/shared/src/env.ts+++ b/packages/shared/src/env.ts@@ -522,6 +522,7 @@ 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.tsnew file mode 100644index 0000000000..557a12f0ec--- /dev/null+++ b/packages/shared/src/in-app-agent/server/modelProvider.ts@@ -0,0 +1,54 @@+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 b6ee67cf6a..a2b9646e87 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,10 +431,9 @@ export async function maybeInferAndPersistConversationTitle(params: {userId: string;aiTelemetryEnabled: boolean;}) {- const model =- env.LANGFUSE_AWS_BEDROCK_SMALL_MODEL ?? env.LANGFUSE_AWS_BEDROCK_MODEL;+ const modelConfig = getInAppAgentModelConfig();- if (!model) {+ if (!modelConfig) {return;}@@ -523,7 +522,7 @@ ${JSON.stringify(transcript, null, 2)}`.trim(),},],- model,+ model: modelConfig.titleModelId,maxTokens: 1000,traceSinkParams: params.aiTelemetryEnabled? getLangfuseAITraceSinkParams({diff --git a/packages/shared/src/server/index.ts b/packages/shared/src/server/index.tsindex b3308bb988..7ec6aacff3 100644--- a/packages/shared/src/server/index.ts+++ b/packages/shared/src/server/index.ts@@ -57,6 +57,7 @@ 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 84f234b669..5940830a56 100644--- a/packages/shared/src/server/llm/ai-sdk/providers/bedrock.ts+++ b/packages/shared/src/server/llm/ai-sdk/providers/bedrock.ts@@ -80,6 +80,28 @@ 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@@ -101,10 +123,7 @@ 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 {- credentialProvider: fromNodeProviderChain(),- ...SUPPRESS_BEARER_TOKEN_ENV_FALLBACK,- };+ return createDefaultBedrockProviderAuth();}try {diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 257829c883..b2e2fb3f12 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -1021,9 +1021,6 @@ 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 de4afebda5..25fbf4973e 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",+ "src/features/in-app-agent/components/InAppAiAgentProvider.tsx: extra exports: useInAppAiAgent, useCanUseInAppAgent, useIsInAppAgentLauncherVisible","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 d7cc088b89..dcecd86182 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,6 +12,7 @@ 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,@@ -96,6 +97,11 @@ 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 =@@ -104,6 +110,10 @@ 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();@@ -117,6 +127,13 @@ 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 =@@ -194,6 +211,103 @@ 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 c74171bac6..a2345f9693 100644--- a/web/src/__tests__/server/in-app-agent-persistence.servertest.ts+++ b/web/src/__tests__/server/in-app-agent-persistence.servertest.ts@@ -1,5 +1,7 @@-vi.mock("@langfuse/shared/src/server", async () => {- const actual = await vi.importActual("@langfuse/shared/src/server");+vi.mock("@langfuse/shared/src/server/llm/llmText", async () => {+ const actual = await vi.importActual(+ "@langfuse/shared/src/server/llm/llmText",+ );return {...actual,generateLLMText: vi.fn(),@@ -17,9 +19,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,@@ -244,18 +246,16 @@ describe("in-app agent persistence", () => {});});- it("rejects users without the in-app agent entitlement", async () => {+ it("allows oss-plan users to list conversations", async () => {const { caller, projectId } = await createCaller(`user-${randomUUID()}`,"oss",);- await expect(caller.listConversations({ projectId })).rejects.toMatchObject(- {- code: "FORBIDDEN",- message: expect.stringContaining("in-app-agent"),- },- );+ await expect(caller.listConversations({ projectId })).resolves.toEqual({+ conversations: [],+ nextCursor: undefined,+ });});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.tsnew file mode 100644index 0000000000..1f24c25c50--- /dev/null+++ b/web/src/__tests__/server/organization-ai-features.servertest.ts@@ -0,0 +1,154 @@+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 10c23105e1..2c75d6b7da 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", () => ({- useCanUseInAppAgent: () => true,+ useIsInAppAgentLauncherVisible: () => 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 bdf7ca677a..6ac1e2d737 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 {- useCanUseInAppAgent,+ useIsInAppAgentLauncherVisible,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 canUseAssistant = useCanUseInAppAgent();+ const isInAppAgentLauncherVisible = useIsInAppAgentLauncherVisible();const toggleAssistant = useCallback((source: InAppAgentEntryPoint) => {@@ -39,7 +39,7 @@ export const InAppAiAgentButton = ({);useEffect(() => {- if (!canUseAssistant) {+ if (!isInAppAgentLauncherVisible) {return;}@@ -60,9 +60,9 @@ export const InAppAiAgentButton = ({document.addEventListener("keydown", handleKeyDown);return () => document.removeEventListener("keydown", handleKeyDown);- }, [canUseAssistant, toggleAssistant]);+ }, [isInAppAgentLauncherVisible, toggleAssistant]);- if (!canUseAssistant) {+ if (!isInAppAgentLauncherVisible) {return null;}diff --git a/web/src/env.mjs b/web/src/env.mjsindex 05d95b2243..0d907139bf 100644--- a/web/src/env.mjs+++ b/web/src/env.mjs@@ -452,6 +452,7 @@ 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(),@@ -977,6 +978,7 @@ 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 1bac2d9c86..39e880d326 100644--- a/web/src/features/entitlements/constants/entitlements.ts+++ b/web/src/features/entitlements/constants/entitlements.ts@@ -30,6 +30,7 @@ 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 2fa3f844a2..629494a47a 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 {- useCanUseInAppAgent,+ useIsInAppAgentLauncherVisible,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 canUseAssistant = useCanUseInAppAgent();+ const isInAppAgentLauncherVisible = useIsInAppAgentLauncherVisible();const { openAssistant, submit } = useInAppAiAgent();const sdk = useProjectV4SdkData({projectId,@@ -231,7 +231,7 @@ export default function RemapEvaluatorPage() {align="top"actions={() => (<>- {canUseAssistant ? (+ {isInAppAgentLauncherVisible ? (<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 42d3f37f6a..6e55f721a1 100644--- a/web/src/features/in-app-agent/components/InAppAgentExecution.clienttest.tsx+++ b/web/src/features/in-app-agent/components/InAppAgentExecution.clienttest.tsx@@ -112,6 +112,7 @@ vi.mock("next/router", () => ({const sessionMocks = vi.hoisted(() => ({userId: "user-1" as string | undefined,aiFeaturesEnabled: true,+ inAppAgentEnabled: true,isLangfuseCloud: true,}));@@ -119,6 +120,7 @@ vi.mock("next-auth/react", () => ({useSession: () => ({data: {user: { id: sessionMocks.userId, name: "Test User" },+ environment: { inAppAgentEnabled: sessionMocks.inAppAgentEnabled },},}),}));@@ -279,6 +281,7 @@ describe("in-app agent execution", () => {beforeEach(() => {sessionMocks.userId = "user-1";sessionMocks.aiFeaturesEnabled = true;+ sessionMocks.inAppAgentEnabled = true;sessionMocks.isLangfuseCloud = true;providerMocks.activityUseQuery.mockImplementation(() => providerMocks.activityQuery,@@ -301,9 +304,10 @@ describe("in-app agent execution", () => {window.sessionStorage.clear();});- // 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.+ // 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.it("polls for activity only once AI features are on", () => {sessionMocks.aiFeaturesEnabled = false;@@ -330,6 +334,20 @@ 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 18055ef292..de813dc264 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", () => ({- useCanUseInAppAgent: () => true,+ useIsInAppAgentLauncherVisible: () => 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 f4c626aa8c..0ea0783a02 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 {- useCanUseInAppAgent,+ useIsInAppAgentLauncherVisible,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 canUseAgent = useCanUseInAppAgent();+ const isInAppAgentLauncherVisible = useIsInAppAgentLauncherVisible();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 `canUseAgent` gates the tree: the shell owns the `open` guard so the- // handheld drawer stays mounted and can animate itself closed.- if (!canUseAgent) {+ // Only `isInAppAgentLauncherVisible` gates the tree: the shell owns the `open` guard+ // so the handheld drawer stays mounted and can animate itself closed.+ if (!isInAppAgentLauncherVisible) {return null;}diff --git a/web/src/features/in-app-agent/components/InAppAiAgentProvider.tsx b/web/src/features/in-app-agent/components/InAppAiAgentProvider.tsxindex 9b5d96a962..c31ca99378 100644--- a/web/src/features/in-app-agent/components/InAppAiAgentProvider.tsx+++ b/web/src/features/in-app-agent/components/InAppAiAgentProvider.tsx@@ -54,7 +54,6 @@ 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 {@@ -293,7 +292,7 @@ function InAppAiAgentProviderInner({const utils = api.useUtils();const capture = usePostHogClientCapture();const session = useSession();- const isInAppAgentEnabled = useIsInAppAgentEnabled();+ const canUseAssistant = useCanUseInAppAgent();const { organization } = useQueryProjectOrOrganization();const [enableDialogOpen, setEnableDialogOpen] = useState(false);const [_selectedConversationId, setSelectedConversationId] =@@ -435,7 +434,7 @@ function InAppAiAgentProviderInner({userId,// Polling a project the server will reject turns every page load and// window focus into a Forbidden toast.- enabled: isInAppAgentEnabled,+ enabled: canUseAssistant,// 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,@@ -1591,34 +1590,39 @@ export function useInAppAiAgent() {return ctx;}-/** 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() {+/** 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() {const hasInAppAgentEntitlement = useHasEntitlement("in-app-agent");- const { isLangfuseCloud } = useLangfuseCloudRegion();const { organization } = useQueryProjectOrOrganization();+ const session = useSession();+ const instanceEnabled = session.data?.environment.inAppAgentEnabled ?? false;return (- isLangfuseCloud &&+ instanceEnabled &&hasInAppAgentEntitlement &&Boolean(organization?.aiFeaturesEnabled));}-/** 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() {+/** 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() {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 9544b74949..0daa31993e 100644--- a/web/src/features/in-app-agent/server/availability.ts+++ b/web/src/features/in-app-agent/server/availability.ts@@ -2,8 +2,11 @@ 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({@@ -15,12 +18,11 @@ export async function assertInAppAgentAvailable({projectId: string;user: NonNullable<Session["user"]>;}) {- // TODO(LFE-14555): Remove this guard once the OSS release strategy is ready.- if (!env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION) {+ if (!isInAppAgentInstanceEnabled()) {throw new BaseError("PreconditionFailedError",412,- "In-app agent is not available in this environment yet.",+ "In-app agent is not enabled on this instance.",true,);}@@ -52,8 +54,22 @@ export async function assertInAppAgentAvailable({});if (!project?.organization.aiFeaturesEnabled) {- throw new ForbiddenError("Assistant is not enabled for this organization");+ throw new ForbiddenError(+ "In-app agent 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 da0a695968..92a2a40e05 100644--- a/web/src/features/in-app-agent/server/router.ts+++ b/web/src/features/in-app-agent/server/router.ts@@ -18,7 +18,10 @@ import {getInAppAgentInstrumentationTraceId,} from "@langfuse/shared/in-app-agent";import { InAppAgentMessageFeedbackValueSchema } from "../schema";-import { assertInAppAgentAvailable } from "@/src/features/in-app-agent/server/availability";+import {+ assertInAppAgentAvailable,+ assertInAppAgentModelConfigured,+} from "@/src/features/in-app-agent/server/availability";import {createTRPCRouter,protectedProjectProcedure,@@ -209,6 +212,7 @@ export const inAppAgentRouter = createTRPCRouter({projectId: input.projectId,user: ctx.session.user,});+ assertInAppAgentModelConfigured();const rateLimitScope = getInAppAgentApiAccessScope(ctx.session.user,@@ -268,6 +272,7 @@ 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 ebd76261cc..72d1efd02d 100644--- a/web/src/features/organizations/components/AIFeatureSwitch.tsx+++ b/web/src/features/organizations/components/AIFeatureSwitch.tsx@@ -114,8 +114,6 @@ export default function AIFeatureSwitch() {});}- if (!isLangfuseCloud) return null;-return (<div><Header title="AI Features" />@@ -125,22 +123,30 @@ export default function AIFeatureSwitch() {<h4 className="font-bold">Enable AI powered features for your organization</h4>- <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>+ {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>+ )}</div><div className="relative"><Switch@@ -155,7 +161,7 @@ export default function AIFeatureSwitch() {)}</div></div>- {isAIFeatureSwitchEnabled && (+ {isLangfuseCloud && 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">@@ -200,20 +206,27 @@ export default function AIFeatureSwitch() {<strong>{isAIFeatureSwitchEnabled ? "enable " : "disable"}</strong>{" "}- 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>+ 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>+ </>+ )}</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 fc77a204e6..9c457f296c 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.aiFeaturesEnabled !== undefined ||- input.aiTelemetryEnabled !== undefined) &&+ input.aiTelemetryEnabled !== undefined &&!env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION) {throw new TRPCError({code: "PRECONDITION_FAILED",- message: "AI features are not available in self-hosted deployments.",+ message:+ "AI telemetry controls are only available on Langfuse Cloud.",});}diff --git a/web/src/features/v4-migration/EvaluatorMigrationDialog.tsx b/web/src/features/v4-migration/EvaluatorMigrationDialog.tsxindex c26d682266..511e5279b0 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 {- useCanUseInAppAgent,+ useIsInAppAgentLauncherVisible,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 canUseAssistant = useCanUseInAppAgent();+ const isInAppAgentLauncherVisible = useIsInAppAgentLauncherVisible();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 = canUseAssistant;+ const showAssistantOption = isInAppAgentLauncherVisible;// 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 a1ed32e399..0e95dddaea 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", () => ({- useCanUseInAppAgent: () => true,+ useIsInAppAgentLauncherVisible: () => 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 c9381e62f5..572967d785 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 { useCanUseInAppAgent } from "@/src/features/in-app-agent/components/InAppAiAgentProvider";+import { useIsInAppAgentLauncherVisible } 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 canUseAssistant = useCanUseInAppAgent();+ const isInAppAgentLauncherVisible = useIsInAppAgentLauncherVisible();// 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={- canUseAssistant+ isInAppAgentLauncherVisible? {onMigrate: handleMigrateEvalsWithAgent,aiFeaturesEnabled,diff --git a/web/src/features/v4-migration/V4MigrationDelayBadge.clienttest.tsx b/web/src/features/v4-migration/V4MigrationDelayBadge.clienttest.tsxindex a1b42a26fc..06ae234eea 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", () => ({- useCanUseInAppAgent: () => false,+ useIsInAppAgentLauncherVisible: () => 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 6436f6efa1..cbd794e037 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", () => ({- useCanUseInAppAgent: () => true,+ useIsInAppAgentLauncherVisible: () => true,}));describe("V4_CODING_AGENT_PROMPT", () => {diff --git a/web/src/features/v4-migration/useV4UpgradeAssistantSupport.ts b/web/src/features/v4-migration/useV4UpgradeAssistantSupport.tsindex 79afb8ef60..4bcb953318 100644--- a/web/src/features/v4-migration/useV4UpgradeAssistantSupport.ts+++ b/web/src/features/v4-migration/useV4UpgradeAssistantSupport.ts@@ -1,4 +1,4 @@-import { useCanUseInAppAgent } from "@/src/features/in-app-agent/components/InAppAiAgentProvider";+import { useIsInAppAgentLauncherVisible } 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 canUseAssistant = useCanUseInAppAgent();+ const isInAppAgentLauncherVisible = useIsInAppAgentLauncherVisible();const sdk = useProjectV4SdkData(params);const evalQuery = api.v4Transition.traceLevelEvalSummary.useQuery({ projectId: params.projectId ?? "" },@@ -77,10 +77,10 @@ export function useEvalUpgradeAssistantPlan(params: {: "outside";return {- canUseAssistant,+ canUseAssistant: isInAppAgentLauncherVisible,mode,/** Whether the migration panel may show the Assistant CTA. */- showAssistantButton: canUseAssistant && mode !== "outside",+ showAssistantButton: isInAppAgentLauncherVisible && mode !== "outside",assistantPrompt:mode === "evals-ready"? EVAL_UPGRADE_ASSISTANT_PROMPTdiff --git a/web/src/server/auth.ts b/web/src/server/auth.tsindex 281633bd5e..0188cff64c 100644--- a/web/src/server/auth.ts+++ b/web/src/server/auth.ts@@ -6,6 +6,7 @@ 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,@@ -879,6 +880,7 @@ 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 24bb2b71ea..5b3ccd2f57 100644--- a/web/types/next-auth.d.ts+++ b/web/types/next-auth.d.ts@@ -57,6 +57,9 @@ 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 b13fa6b79f..87456b4ca2 100644--- a/worker/package.json+++ b/worker/package.json@@ -37,7 +37,6 @@"@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 8dd39e241f..2de17464b3 100644--- a/worker/src/features/in-app-agent/executeInAppAgentRun.test.ts+++ b/worker/src/features/in-app-agent/executeInAppAgentRun.test.ts@@ -35,9 +35,13 @@ type AgentScenario = (ctx: {};signal: AbortSignal;options: {- awsBedrock: {- profile?: string;+ model: {+ provider: "bedrock";+ modelId: string;};+ awsProfile?: string;+ langfuseClient?: unknown;+ useLocalPrompt: boolean;langfuseMcp: {toolPolicy: {available: ReadonlySet<string>;@@ -59,6 +63,7 @@ const scenarioRef = vi.hoisted(() => ({failApiKeyDelete: false,apiKeyDeleteCalls: 0,titleInferenceCalls: 0,+ instanceEnabled: true,}));vi.mock("./runtime/agent", async (importOriginal) => {@@ -103,6 +108,21 @@ 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<@@ -271,6 +291,7 @@ 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 () => {@@ -296,7 +317,7 @@ describe("executeInAppAgentRun", () => {const { projectId, run } = await seedBackgroundRun();scenarioRef.current = async ({ options }) => {- expect(options.awsBedrock.profile).toBe("developer-profile");+ expect(options.awsProfile).toBe("developer-profile");await options.onComplete();await options.onFinish();};@@ -309,6 +330,25 @@ 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";@@ -714,6 +754,21 @@ 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 a712285b11..05dd1d3349 100644--- a/worker/src/features/in-app-agent/executeInAppAgentRun.ts+++ b/worker/src/features/in-app-agent/executeInAppAgentRun.ts@@ -1,6 +1,5 @@import { Role } from "@langfuse/shared";import { prisma } from "@langfuse/shared/src/db";-import { env as sharedEnv } from "@langfuse/shared/src/env";import {getLangfuseAITraceSinkParams,logger,@@ -29,6 +28,10 @@ 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,@@ -153,20 +156,23 @@ export async function executeInAppAgentRun(params: {try {// ---- Revalidate at claim; nothing from enqueue time is trusted. ----- if (!env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION) {+ if (!isInAppAgentInstanceEnabled()) {throw new InAppAgentRunInitError(- "In-app agent is only available on Langfuse Cloud",+ "In-app agent is not enabled on this instance",);}- const bedrockModelId = run.model ?? sharedEnv.LANGFUSE_AWS_BEDROCK_MODEL;+ const modelConfig = getInAppAgentModelConfig({ modelId: run.model });- if (!bedrockModelId || !sharedEnv.LANGFUSE_AWS_BEDROCK_REGION) {+ if (!modelConfig) {throw new InAppAgentRunInitError(- "Assistant Bedrock model is not configured",+ "In-app agent 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 },});@@ -500,11 +506,8 @@ export async function executeInAppAgentRun(params: {await cleanupMcpApiKeyLogged();await sandboxState?.onTurnEnded();},- awsBedrock: {- region: sharedEnv.LANGFUSE_AWS_BEDROCK_REGION,- modelId: bedrockModelId,- ...(awsProfile ? { profile: awsProfile } : {}),- },+ model: modelConfig,+ ...(awsProfile ? { awsProfile } : {}),langfuseMcp: {url: getLangfuseMcpUrl(),publicKey: mcpApiKey.publicKey,@@ -516,8 +519,10 @@ export async function executeInAppAgentRun(params: {projectId,isV4Enabled: access.v4BetaEnabled,},- langfuseClient: getInAppAgentPromptClient(),- useLocalPrompt: env.NODE_ENV === "development",+ useLocalPrompt: useBundledPrompt,+ ...(useBundledPrompt+ ? {}+ : { langfuseClient: getInAppAgentPromptClient() }),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 3207df5ee8..9328390ab2 100644--- a/worker/src/features/in-app-agent/runtime/agent.test.ts+++ b/worker/src/features/in-app-agent/runtime/agent.test.ts@@ -25,6 +25,13 @@ 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.@@ -472,7 +479,10 @@ describe("createAgUiStream", () => {});});- const initializeBasicTracedAgent = async (runId: string) => {+ const initializeBasicTracedAgent = async (+ runId: string,+ model = testBedrockModel("test-model"),+ ) => {const { createAgUiStream } = await import("./agent");const input = {threadId: "conversation-1",@@ -506,7 +516,7 @@ describe("createAgUiStream", () => {input,signal: new AbortController().signal,options: {- awsBedrock: { modelId: "test-model" },+ model,langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -524,6 +534,18 @@ 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)@@ -685,9 +707,7 @@ describe("createAgUiStream", () => {eventOrder.push(`persist:${event.type}`);await Promise.resolve();},- awsBedrock: {- modelId: "eu.anthropic.claude-opus-4-8",- },+ model: testBedrockModel("eu.anthropic.claude-opus-4-8"),langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -973,9 +993,7 @@ describe("createAgUiStream", () => {input,signal: new AbortController().signal,options: {- awsBedrock: {- modelId: "meta.llama3-70b-instruct-v1:0",- },+ model: testBedrockModel("meta.llama3-70b-instruct-v1:0"),langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -1046,7 +1064,7 @@ describe("createAgUiStream", () => {input,signal: new AbortController().signal,options: {- awsBedrock: { modelId: "eu.anthropic.claude-opus-4-8" },+ model: testBedrockModel("eu.anthropic.claude-opus-4-8"),langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -1143,7 +1161,7 @@ describe("createAgUiStream", () => {onEvent: (event) => {persistedEvents.push(event);},- awsBedrock: { modelId: "test-model" },+ model: testBedrockModel("test-model"),langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -1215,7 +1233,7 @@ describe("createAgUiStream", () => {input,signal: new AbortController().signal,options: {- awsBedrock: { modelId: "eu.anthropic.claude-opus-4-8" },+ model: testBedrockModel("eu.anthropic.claude-opus-4-8"),langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -1263,7 +1281,7 @@ describe("createAgUiStream", () => {onEvent: (event) => {persistedEvents.push(event);},- awsBedrock: { modelId: "test-model" },+ model: testBedrockModel("test-model"),langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -1550,7 +1568,7 @@ describe("createAgUiStream", () => {onEvent: (event) => {persistedEvents.push(event);},- awsBedrock: { modelId: "test-model" },+ model: testBedrockModel("test-model"),langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -1627,7 +1645,7 @@ describe("createAgUiStream", () => {persistedEvents.push(event);},onError,- awsBedrock: { modelId: "test-model" },+ model: testBedrockModel("test-model"),langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -1791,7 +1809,7 @@ describe("createAgUiStream", () => {input,signal: new AbortController().signal,options: {- awsBedrock: { modelId: "test-model" },+ model: testBedrockModel("test-model"),langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -1872,7 +1890,7 @@ describe("createAgUiStream", () => {persistedEvents.push(event);},onComplete,- awsBedrock: { modelId: "test-model" },+ model: testBedrockModel("test-model"),langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -2021,7 +2039,7 @@ describe("createAgUiStream", () => {input,signal: new AbortController().signal,options: {- awsBedrock: { modelId: "test-model" },+ model: testBedrockModel("test-model"),langfuseMcp: {url: "https://example.com/api/public/mcp",publicKey: "pk",@@ -2109,7 +2127,7 @@ describe("createAgUiStream", () => {input,signal: new AbortController().signal,options: {- awsBedrock: { modelId: "test-model" },+ model: testBedrockModel("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 deb8cd5c80..2291dd1527 100644--- a/worker/src/features/in-app-agent/runtime/agent.ts+++ b/worker/src/features/in-app-agent/runtime/agent.ts@@ -2,7 +2,6 @@ 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";@@ -45,11 +44,15 @@ import {import { LANGFUSE_IN_APP_AGENT_SKILLS } from "./skills";import type { InAppAgentSandbox } from "./sandbox";import { DEFAULT_SIDEBAR_HIDDEN_ENVIRONMENTS } from "@langfuse/shared";-import { logger } from "@langfuse/shared/src/server";+import {+ createDefaultBedrockProviderAuth,+ 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";@@ -182,11 +185,8 @@ type CreateAgUiStreamOptions = {onAbort?: () => void | Promise<void>;onError?: (error: unknown) => void | Promise<void>;onFinish?: () => void | Promise<void>;- awsBedrock: {- region?: string;- profile?: string;- modelId: string;- };+ model: InAppAgentModelConfig;+ awsProfile?: 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.awsBedrock.profile;+ const awsProfile = params.options.awsProfile;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.awsBedrock.modelId,+ model: params.options.model.modelId,});const recordInstrumentation = (operation: string,@@ -846,15 +846,17 @@ type ExecutableInAppAgentTool = {toModelOutput?: (output: unknown) => unknown | PromiseLike<unknown>;};-type BedrockLanguageModel = ReturnType<ReturnType<typeof createAmazonBedrock>>;+type InAppAgentLanguageModel = ReturnType<+ ReturnType<typeof createAmazonBedrock>+>;function withModelTracing(- model: BedrockLanguageModel,+ model: InAppAgentLanguageModel,callbacks: {onStart?: (options: unknown) => void;onStreamPart?: (part: unknown) => void;},-): BedrockLanguageModel {+): InAppAgentLanguageModel {if (!callbacks.onStart && !callbacks.onStreamPart) {return model;}@@ -941,11 +943,9 @@ async function createMastraAdapter(params: {onToolExecutionEnd?: (toolCallId: string) => void;}) {const bedrock = createAmazonBedrock({- ...(params.options.awsBedrock.region- ? { region: params.options.awsBedrock.region }- : {}),- credentialProvider: fromNodeProviderChain(- params.awsProfile ? { profile: params.awsProfile } : {},+ region: params.options.model.region,+ ...createDefaultBedrockProviderAuth(+ params.awsProfile ? { profile: params.awsProfile } : undefined,),});@@ -1061,7 +1061,7 @@ async function createMastraAdapter(params: {params.onToolsAvailable?.(tools);const reasoningProviderOptions = getBedrockReasoningProviderOptions(- params.options.awsBedrock.modelId,+ params.options.model.modelId,);// @ag-ui/mastra currently forwards only assistant, user, and tool@@ -1071,9 +1071,7 @@ async function createMastraAdapter(params: {// guidance on resumed runs.let developerGuidance: string | undefined;const model = withModelTracing(- bedrock(- params.options.awsBedrock.modelId as Parameters<typeof bedrock>[0],- ),+ bedrock(params.options.model.modelId as Parameters<typeof bedrock>[0]),{onStart: params.onModelCallStart,onStreamPart: params.onModelStreamPart,@@ -1373,7 +1371,7 @@ function getToolErrorMessage(chunk: MastraApprovalStreamChunk): string {}async function getSystemPromptInstructions(params: {- langfuseClient: Langfuse;+ langfuseClient?: Langfuse;useLocalPrompt: boolean;variables: {currentDate: string;@@ -1397,6 +1395,10 @@ 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,@@ -1458,7 +1460,7 @@ function createRunErrorEvent(error: unknown,): AgUiEvent {const message =- error instanceof Error ? error.message : "Unknown assistant error";+ error instanceof Error ? error.message : "Unknown in-app agent error";return {type: EventType.RUN_ERROR,@@ -1471,5 +1473,5 @@ function createRunErrorEvent(function getRunErrorMessage(event: AgUiEvent) {return typeof event.message === "string" && event.message.trim()? event.message- : "Unknown assistant error";+ : "Unknown in-app agent error";}diff --git a/worker/src/features/in-app-agent/runtime/instrumentation.ts b/worker/src/features/in-app-agent/runtime/instrumentation.tsindex 114373d8e0..0cfecf2e53 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 assistant error",+ : "Unknown in-app agent error",);return;}