Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(agent): Update system prompt to exclude `langfuse-*` envs (#14366)

Ben Bachem6257c8db286f
diff --git a/web/src/__tests__/server/in-app-agent-stream.servertest.ts b/web/src/__tests__/server/in-app-agent-stream.servertest.ts
index 25ec25477e..b4234e6118 100644
--- a/web/src/__tests__/server/in-app-agent-stream.servertest.ts
+++ b/web/src/__tests__/server/in-app-agent-stream.servertest.ts
@@ -4,9 +4,10 @@ import { Agent } from "@mastra/core/agent";
import { describe, expect, it, vi } from "vitest";
import type { AgUiEvent } from "@/src/ee/features/in-app-agent/schema";
-import { decodeFiltersGeneric } from "@/src/features/filters/lib/filter-query-encoding";
import { IN_APP_AGENT_REDIRECT_TOOL_NAME } from "@/src/ee/features/in-app-agent/constants";
import { patchMastraToolCallInputStreaming } from "@/src/ee/features/in-app-agent/server/agent";
+import { DEFAULT_SIDEBAR_HIDDEN_ENVIRONMENTS } from "@/src/features/filters/constants/internal-environments";
+import { decodeFiltersGeneric } from "@/src/features/filters/lib/filter-query-encoding";
import type { MastraAgent } from "@ag-ui/mastra";
const adapterEvents = vi.hoisted(() => ({
@@ -495,6 +496,9 @@ describe("createAgUiStream", () => {
currentDate: expect.any(String),
redirectToolName: IN_APP_AGENT_REDIRECT_TOOL_NAME,
screenContext: "",
+ sidebarHiddenEnvironments: DEFAULT_SIDEBAR_HIDDEN_ENVIRONMENTS.map(
+ (environment) => `"${environment}"`,
+ ).join(", "),
}),
);
expect(Agent).toHaveBeenCalledWith(
diff --git a/web/src/ee/features/in-app-agent/server/agent.ts b/web/src/ee/features/in-app-agent/server/agent.ts
index f917180ca2..5fd1a4b64d 100644
--- a/web/src/ee/features/in-app-agent/server/agent.ts
+++ b/web/src/ee/features/in-app-agent/server/agent.ts
@@ -19,6 +19,7 @@ import type {
} from "@/src/ee/features/in-app-agent/server/instrumentation";
import { createInAppAgentInstrumentation } from "@/src/ee/features/in-app-agent/server/instrumentation";
import { createRedirectActionTool } from "@/src/ee/features/in-app-agent/server/tools";
+import { DEFAULT_SIDEBAR_HIDDEN_ENVIRONMENTS } from "@/src/features/filters/constants/internal-environments";
import { logger } from "@langfuse/shared/src/server";
import { IN_APP_AGENT_REDIRECT_TOOL_NAME } from "@/src/ee/features/in-app-agent/constants";
@@ -93,6 +94,9 @@ export async function createAgUiStream(params: {
currentDate: new Date().toISOString(),
redirectToolName: IN_APP_AGENT_REDIRECT_TOOL_NAME,
screenContext: formatScreenContext(params.input.context),
+ sidebarHiddenEnvironments: DEFAULT_SIDEBAR_HIDDEN_ENVIRONMENTS.map(
+ (environment) => `"${environment}"`,
+ ).join(", "),
},
});
const instrumentation = createInAppAgentInstrumentation({
@@ -754,6 +758,7 @@ async function getSystemPromptInstructions(params: {
currentDate: string;
redirectToolName: string;
screenContext: string;
+ sidebarHiddenEnvironments: string;
};
}): Promise<{ instructions: string; prompt: InAppAgentPromptMetadata }> {
if (params.useLocalPrompt) {
diff --git a/web/src/features/in-app-agent/prompts/in-app-agent-system-prompt.txt b/web/src/features/in-app-agent/prompts/in-app-agent-system-prompt.txt
index 44cf9fe3b7..8fa7db2133 100644
--- a/web/src/features/in-app-agent/prompts/in-app-agent-system-prompt.txt
+++ b/web/src/features/in-app-agent/prompts/in-app-agent-system-prompt.txt
@@ -27,6 +27,14 @@ IMPORTANT: You should NOT answer with unnecessary preamble or postamble (such as
Use the docs tools to find relevant general information about Langfuse or best practices.
</tools>
+<data_scope>
+Langfuse uses internal environments for Langfuse-managed product workflows, such as evaluations, prompt experiments or code evals. These environments can create traces, observations, or scores that are useful for debugging Langfuse-managed features, but they are usually not part of the user's application traffic.
+
+When answering questions about project data, exclude these environments by default: {{sidebarHiddenEnvironments}}.
+Tell the user about these environments and their purpose when relevant, and give them the option to include them in your answers when appropriate.
+Only include them if the user explicitly asks for internal or Langfuse-managed environments, or asks for all environments.
+</data_scope>
+
<permissions>
Currently, you only have read access to user's project. All your tools enforce this restriction so no need to worry about it.
If the user asks you to perform an action, you have two options: