🪢 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): default Assistant worker surfaces to LANGFUSE_IN_APP_AGENT_ENABLED (#16646)
Lysander Kiesel0f062bec1802
diff --git a/.env.dev.example b/.env.dev.exampleindex fef4309b4e..66d7ffca59 100644--- a/.env.dev.example+++ b/.env.dev.example@@ -231,12 +231,12 @@ LANGFUSE_IN_APP_AGENT_AWS_PROFILE="playground"# Optional: overrides Lambda's default INTERNET_EGRESS connector.# LANGFUSE_IN_APP_AGENT_SANDBOX_AWS_LAMBDA_MICROVM_EGRESS_NETWORK_CONNECTOR_ARN="arn:aws:lambda:us-east-1:123456789012:network-connector:langfuse-in-app-agent-sandbox-egress"-# Turns run in background by default; without the consumer they die at queue_timeout.-QUEUE_CONSUMER_IN_APP_AGENT_RUN_QUEUE_IS_ENABLED="true"+# Workers follow LANGFUSE_IN_APP_AGENT_ENABLED for the run queue and integrity+# runner. Without that flag, queued turns die at queue_timeout. Split-role+# workers can opt out without turning the instance off:+# QUEUE_CONSUMER_IN_APP_AGENT_RUN_QUEUE_IS_ENABLED=false+# LANGFUSE_IN_APP_AGENT_INTEGRITY_RUNNER_ENABLED=false# LANGFUSE_IN_APP_AGENT_RUN_QUEUE_PROCESSING_CONCURRENCY=5--# Reconciles stale runs that nobody reopened, then reports remainders.-# LANGFUSE_IN_APP_AGENT_INTEGRITY_RUNNER_ENABLED="false"# LANGFUSE_IN_APP_AGENT_INTEGRITY_RUNNER_INTERVAL_MS=900000# Web-only admission ceilings.diff --git a/.env.prod.example b/.env.prod.exampleindex 6d8fbc3bdf..16187443b8 100644--- a/.env.prod.example+++ b/.env.prod.example@@ -304,10 +304,11 @@ LANGFUSE_ENABLE_BLOB_STORAGE_FILE_LOG=true# Origin only, the app appends /v1# LANGFUSE_AI_BASE_URL=https://api.anthropic.com-# Worker that executes Assistant runs. Without the consumer, runs never start.-# The integrity runner reconciles runs abandoned by a crashed worker.-# QUEUE_CONSUMER_IN_APP_AGENT_RUN_QUEUE_IS_ENABLED=true-# LANGFUSE_IN_APP_AGENT_INTEGRITY_RUNNER_ENABLED=true+# Workers follow LANGFUSE_IN_APP_AGENT_ENABLED for the run queue and integrity+# runner. Split-role workers (ingestion-only) can opt out without turning the+# instance off:+# QUEUE_CONSUMER_IN_APP_AGENT_RUN_QUEUE_IS_ENABLED=false+# LANGFUSE_IN_APP_AGENT_INTEGRITY_RUNNER_ENABLED=false# LANGFUSE_IN_APP_AGENT_RUN_QUEUE_PROCESSING_CONCURRENCY=5# Admission ceilings for concurrent Assistant runs, web onlydiff --git a/docker-compose.build.yml b/docker-compose.build.ymlindex 1b4297c73b..4365d68222 100644--- a/docker-compose.build.yml+++ b/docker-compose.build.yml@@ -95,9 +95,6 @@ services: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:-}diff --git a/docker-compose.yml b/docker-compose.ymlindex b3e2d117dd..b7f5f80b60 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -88,9 +88,6 @@ services: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:-}diff --git a/packages/shared/src/in-app-agent/server/modelProvider.test.ts b/packages/shared/src/in-app-agent/server/modelProvider.test.tsindex b89dff7128..481b6c19b9 100644--- a/packages/shared/src/in-app-agent/server/modelProvider.test.ts+++ b/packages/shared/src/in-app-agent/server/modelProvider.test.ts@@ -2,7 +2,10 @@ import { afterEach, describe, expect, it, vi } from "vitest";import { env } from "../../env";import { logger } from "../../server/logger";-import { getInAppAgentModelConfig } from "./modelProvider";+import {+ getInAppAgentModelConfig,+ isInAppAgentInstanceEnabled,+} from "./modelProvider";const original = {LANGFUSE_AI_PROVIDER: env.LANGFUSE_AI_PROVIDER,@@ -11,6 +14,7 @@ const original = {LANGFUSE_AI_API_KEY: env.LANGFUSE_AI_API_KEY,LANGFUSE_AI_BASE_URL: env.LANGFUSE_AI_BASE_URL,LANGFUSE_AI_AWS_BEDROCK_REGION: env.LANGFUSE_AI_AWS_BEDROCK_REGION,+ LANGFUSE_IN_APP_AGENT_ENABLED: env.LANGFUSE_IN_APP_AGENT_ENABLED,NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION,};@@ -147,3 +151,23 @@ describe("getInAppAgentModelConfig", () => {});});});++describe("isInAppAgentInstanceEnabled", () => {+ it("enables the self-hosted worker when LANGFUSE_IN_APP_AGENT_ENABLED is true", () => {+ Object.assign(env, {+ NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: undefined,+ LANGFUSE_IN_APP_AGENT_ENABLED: "true",+ });++ expect(isInAppAgentInstanceEnabled()).toBe(true);+ });++ it("disables the self-hosted worker when LANGFUSE_IN_APP_AGENT_ENABLED is unset", () => {+ Object.assign(env, {+ NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: undefined,+ LANGFUSE_IN_APP_AGENT_ENABLED: undefined,+ });++ expect(isInAppAgentInstanceEnabled()).toBe(false);+ });+});diff --git a/web/src/features/in-app-agent/README.md b/web/src/features/in-app-agent/README.mdindex 1793875715..77ca0f5c58 100644--- a/web/src/features/in-app-agent/README.md+++ b/web/src/features/in-app-agent/README.md@@ -154,9 +154,13 @@ separate click event would answer.Rollback is a code revert; background execution does not require a schemarollback.-`QUEUE_CONSUMER_IN_APP_AGENT_RUN_QUEUE_IS_ENABLED` must be on wherever turns run-in background, otherwise runs commit as `QUEUED` and die at `queue_timeout`. It-is already enabled in every Langfuse Cloud region. Check+Workers with `LANGFUSE_IN_APP_AGENT_ENABLED` set consume the run queue and+reconcile stale runs; without it, runs commit as `QUEUED` and die at+`queue_timeout`. Cloud is on unless the flag is `"false"`. Split-role workers+can keep the instance on and set+`QUEUE_CONSUMER_IN_APP_AGENT_RUN_QUEUE_IS_ENABLED=false` (and+`LANGFUSE_IN_APP_AGENT_INTEGRITY_RUNNER_ENABLED=false`) to skip those+surfaces. Check`LANGFUSE_IN_APP_AGENT_MAX_ACTIVE_RUNS_PER_ORG` against execution capacity too:its default of 20 equals full US capacity and exceeds JP and staging.@@ -165,8 +169,10 @@ statuses remain separate project concerns.Environment ownership:-- Worker: queue enable/concurrency, sandbox provider and Lambda MicroVM values,- and development-only `LANGFUSE_IN_APP_AGENT_AWS_PROFILE`.+- Worker: queue concurrency, sandbox provider and Lambda MicroVM values,+ and development-only `LANGFUSE_IN_APP_AGENT_AWS_PROFILE`. Enablement is+ `LANGFUSE_IN_APP_AGENT_ENABLED` (shared with web); optional `"false"`+ queue and integrity flags opt a split-role worker out.- Fixed lifecycle policy: queue timeout (300000 ms), maximum run duration(900000 ms), and approval TTL (86400000 ms). These are shared constants, soweb and worker cannot diverge.diff --git a/worker/AGENTS.md b/worker/AGENTS.mdindex 56eb428d94..f20e1e98e0 100644--- a/worker/AGENTS.md+++ b/worker/AGENTS.md@@ -68,9 +68,14 @@- `src/features/in-app-agent/runtime/` owns Mastra adaptation, agent execution,instrumentation, prompt loading, continuation handling, tools, skills, andsandbox providers.-- Worker env owns queue consumer/concurrency, sandbox configuration, and the- development-only in-app-agent AWS profile. Shared lifecycle policy values- are fixed constants, so web and worker cannot diverge.+- Worker env owns queue concurrency, sandbox configuration, and the+ development-only in-app-agent AWS profile. Enablement is+ `LANGFUSE_IN_APP_AGENT_ENABLED` via `isInAppAgentInstanceEnabled()`. Optional+ `QUEUE_CONSUMER_IN_APP_AGENT_RUN_QUEUE_IS_ENABLED=false` and+ `LANGFUSE_IN_APP_AGENT_INTEGRITY_RUNNER_ENABLED=false` opt a split-role+ worker out of the queue consumer (and nested DLQ retry) or integrity runner.+ Shared lifecycle policy values are fixed constants, so web and worker cannot+ diverge.- Persisted/queued contracts, lifecycle, storage, MCP policy, tool-resulthandling, and the seeded system prompt remain explicit shared subpaths.diff --git a/worker/src/app.ts b/worker/src/app.tsindex c7cc28b521..9103040570 100644--- a/worker/src/app.ts+++ b/worker/src/app.ts@@ -50,6 +50,7 @@ import {import { monitorProcessorTtl } from "@langfuse/shared/monitors/server";import { IN_APP_AGENT_RUN_MAX_DURATION_MS } from "@langfuse/shared/in-app-agent/server/tunables";import { env, v4WritesToEventsTable } from "./env";+import { isInAppAgentWorkerSurfaceEnabled } from "./features/in-app-agent/enablement";import { ingestionQueueProcessorBuilder } from "./queues/ingestionQueue";import { BackgroundMigrationManager } from "./backgroundMigrations/backgroundMigrationManager";import { prisma } from "@langfuse/shared/src/db";@@ -429,7 +430,11 @@ if (env.QUEUE_CONSUMER_MONITOR_QUEUE_IS_ENABLED === "true") {export let inAppAgentDlqRetryRunner: InAppAgentDlqRetryRunner | null = null;-if (env.QUEUE_CONSUMER_IN_APP_AGENT_RUN_QUEUE_IS_ENABLED === "true") {+if (+ isInAppAgentWorkerSurfaceEnabled(+ env.QUEUE_CONSUMER_IN_APP_AGENT_RUN_QUEUE_IS_ENABLED,+ )+) {WorkerManager.register(QueueName.InAppAgentRunQueue,inAppAgentRunQueueProcessor,@@ -777,7 +782,11 @@ if (env.LANGFUSE_TRACE_DELETE_BATCH_ACTION_RUNNER_ENABLED === "true") {// Reconciles stale in-app agent runs that nobody reopened, then reports remainders.export let inAppAgentIntegrityRunner: InAppAgentIntegrityRunner | null = null;-if (env.LANGFUSE_IN_APP_AGENT_INTEGRITY_RUNNER_ENABLED === "true") {+if (+ isInAppAgentWorkerSurfaceEnabled(+ env.LANGFUSE_IN_APP_AGENT_INTEGRITY_RUNNER_ENABLED,+ )+) {inAppAgentIntegrityRunner = new InAppAgentIntegrityRunner();inAppAgentIntegrityRunner.start();}diff --git a/worker/src/env.ts b/worker/src/env.tsindex 2e4921950f..c7d45822e3 100644--- a/worker/src/env.ts+++ b/worker/src/env.ts@@ -234,16 +234,14 @@ const EnvSchema = z.object({QUEUE_CONSUMER_MONITOR_QUEUE_IS_ENABLED: z.enum(["true", "false"]).default("true"),- // Opt-in because only workers provisioned for agent execution should consume- // durable runs; ingestion-only workers must leave this disabled.+ // Optional opt-outs for split-role workers. Unset follows+ // LANGFUSE_IN_APP_AGENT_ENABLED; "false" skips that surface.QUEUE_CONSUMER_IN_APP_AGENT_RUN_QUEUE_IS_ENABLED: z.enum(["true", "false"])- .default("false"),- // Reconciles stale runs that nobody reopened. Off by default: one elected- // worker per region is enough.+ .optional(),LANGFUSE_IN_APP_AGENT_INTEGRITY_RUNNER_ENABLED: z.enum(["true", "false"])- .default("false"),+ .optional(),// The ambient host profile takes precedence over the agent-specific default// so local developer credentials win when both are configured.AWS_PROFILE: z.string().optional(),diff --git a/worker/src/features/in-app-agent/enablement.test.ts b/worker/src/features/in-app-agent/enablement.test.tsnew file mode 100644index 0000000000..9242d25aef--- /dev/null+++ b/worker/src/features/in-app-agent/enablement.test.ts@@ -0,0 +1,31 @@+import { afterEach, describe, expect, it, vi } from "vitest";++import { isInAppAgentWorkerSurfaceEnabled } from "./enablement";++const mocks = vi.hoisted(() => ({+ instanceEnabled: true,+}));++vi.mock("@langfuse/shared/in-app-agent/server/modelProvider", () => ({+ isInAppAgentInstanceEnabled: () => mocks.instanceEnabled,+}));++afterEach(() => {+ mocks.instanceEnabled = true;+});++describe("isInAppAgentWorkerSurfaceEnabled", () => {+ it("follows the instance switch when the override is unset", () => {+ expect(isInAppAgentWorkerSurfaceEnabled(undefined)).toBe(true);+ });++ it("opts out when the override is false even if the instance is on", () => {+ expect(isInAppAgentWorkerSurfaceEnabled("false")).toBe(false);+ });++ it("stays off when the instance is off even if the override is true", () => {+ mocks.instanceEnabled = false;++ expect(isInAppAgentWorkerSurfaceEnabled("true")).toBe(false);+ });+});diff --git a/worker/src/features/in-app-agent/enablement.ts b/worker/src/features/in-app-agent/enablement.tsnew file mode 100644index 0000000000..cabd8b4c9b--- /dev/null+++ b/worker/src/features/in-app-agent/enablement.ts@@ -0,0 +1,11 @@+import { isInAppAgentInstanceEnabled } from "@langfuse/shared/in-app-agent/server/modelProvider";++/**+ * Instance switch is the default. Explicit `"false"` opts a split-role+ * worker out of this surface.+ */+export function isInAppAgentWorkerSurfaceEnabled(+ override?: "true" | "false",+): boolean {+ return isInAppAgentInstanceEnabled() && override !== "false";+}