Skip to content

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

fix(agent): Various Improvements (#14179)

Ben Bachemeff2306c8116
diff --git a/web/.storybook/preview.ts b/web/.storybook/preview.ts
index b679f735f3..fc79f9a7e2 100644
--- a/web/.storybook/preview.ts
+++ b/web/.storybook/preview.ts
@@ -1,6 +1,7 @@
import { definePreview } from "@storybook/nextjs-vite";
import addonA11y from "@storybook/addon-a11y";
import { createElement } from "react";
+import { TooltipProvider } from "../src/components/ui/tooltip";
import { ThemeProvider } from "../src/features/theming/ThemeProvider";
import "../src/styles/globals.css";
@@ -36,9 +37,13 @@ export default definePreview({
forcedTheme: theme,
},
createElement(
- "div",
- { className: "min-h-screen bg-background text-foreground" },
- createElement(Story),
+ TooltipProvider,
+ null,
+ createElement(
+ "div",
+ { className: "min-h-screen bg-background text-foreground" },
+ createElement(Story),
+ ),
),
);
},
diff --git a/web/src/components/layouts/routes.tsx b/web/src/components/layouts/routes.tsx
index db7963133d..2c5f344fc2 100644
--- a/web/src/components/layouts/routes.tsx
+++ b/web/src/components/layouts/routes.tsx
@@ -245,7 +245,7 @@ export const ROUTES: Route[] = [
menuNode: <BookACallButton />,
},
{
- title: "AI Assistant",
+ title: "Assistant",
section: RouteSection.Secondary,
pathname: "",
featureFlag: "inAppAgent",
diff --git a/web/src/components/nav/in-app-ai-agent-button.tsx b/web/src/components/nav/in-app-ai-agent-button.tsx
index 65b2a6f0d8..572f4c1790 100644
--- a/web/src/components/nav/in-app-ai-agent-button.tsx
+++ b/web/src/components/nav/in-app-ai-agent-button.tsx
@@ -6,7 +6,7 @@ import {
type CSSProperties,
} from "react";
import { createPortal } from "react-dom";
-import { Bot } from "lucide-react";
+import { BotMessageSquare } from "lucide-react";
import { Button } from "@/src/components/ui/button";
import {
@@ -122,8 +122,8 @@ export const InAppAiAgentButton = () => {
return (
<>
<SidebarMenuButton ref={buttonRef} isActive={open} onClick={handleClick}>
- <Bot className="h-4 w-4" />
- AI Assistant
+ <BotMessageSquare className="h-4 w-4" />
+ Assistant
</SidebarMenuButton>
{open && portalContainer
? createPortal(
@@ -163,7 +163,7 @@ export const InAppAiAgentButton = () => {
</DialogHeader>
<DialogBody>
<AIFeaturesDisabledNotice organizationId={organization?.id}>
- The AI assistant requires AI features to be enabled for this
+ The assistant requires AI features to be enabled for this
organization.
</AIFeaturesDisabledNotice>
</DialogBody>
diff --git a/web/src/components/nav/nav-user.tsx b/web/src/components/nav/nav-user.tsx
index 7f265ed592..d732df2917 100644
--- a/web/src/components/nav/nav-user.tsx
+++ b/web/src/components/nav/nav-user.tsx
@@ -108,7 +108,8 @@ export function NavUser({ user, items }: UserNavigationProps) {
</SidebarMenuButton>
</DropdownMenuTrigger>
<DropdownMenuContent
- className="w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg"
+ // Ensure the zIndex here is higher than that of the in-app agent window (see: web/src/ee/features/in-app-agent/components/InAppAgentWindow.tsx)
+ className="z-60 w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg"
side={isMobile ? "bottom" : "right"}
align="end"
sideOffset={4}
diff --git a/web/src/ee/features/in-app-agent/components/InAppAgentMessage.tsx b/web/src/ee/features/in-app-agent/components/InAppAgentMessage.tsx
index 9a9b049ef2..153a3f7f6c 100644
--- a/web/src/ee/features/in-app-agent/components/InAppAgentMessage.tsx
+++ b/web/src/ee/features/in-app-agent/components/InAppAgentMessage.tsx
@@ -67,7 +67,7 @@ export function InAppAgentMessage({
return (
<div
className={cn(
- "bg-card dark:bg-header text-card-foreground border-border rounded-2xl border py-2 shadow-xs",
+ "bg-card dark:bg-header text-foreground border-border rounded-2xl border py-2 shadow-xs",
isCompact
? "rounded-xl py-1 text-[0.775rem]"
: "rounded-2xl py-1.5 text-sm",
@@ -111,13 +111,13 @@ const MessageCard = forwardRef<
<div
ref={ref}
className={cn(
- "shadow-xs",
+ "max-w-full overflow-hidden wrap-break-word shadow-xs",
isCompact
? "rounded-xl px-2.5 py-1 text-[0.775rem]"
: "rounded-2xl px-3 py-1.5 text-sm",
isUser
? "bg-primary text-primary-foreground"
- : "bg-card dark:bg-header text-card-foreground border-border border",
+ : "bg-card dark:bg-header text-foreground border-border border",
)}
>
{content.type === "loading" ? (
@@ -545,7 +545,7 @@ function MessageText({
return (
<div
className={cn(
- "prose prose-sm text-foreground prose-strong:text-inherit prose-pre:bg-muted prose-pre:text-foreground prose-code:text-foreground prose-table:m-0! prose-headings:text-inherit dark:prose-pre:bg-card prose-pre:leading-tight prose-table:border prose-td:p-2 prose-th:p-2 prose-table:bg-muted dark:prose-table:bg-card prose-table:overflow-hidden prose-table:rounded prose-tr:border-b prose-tr:border-border dark:prose-tr:border-border prose-headings:text-sm prose-hr:border-border max-w-none",
+ "prose prose-sm text-foreground prose-strong:text-inherit prose-pre:bg-muted prose-pre:text-foreground prose-code:text-foreground prose-table:m-0! prose-headings:text-inherit dark:prose-pre:bg-card prose-pre:leading-tight prose-table:border prose-td:p-2 prose-th:p-2 prose-table:bg-muted dark:prose-table:bg-card prose-table:overflow-hidden prose-table:rounded prose-tr:border-b prose-tr:border-border dark:prose-tr:border-border prose-headings:text-sm prose-hr:border-border prose-code:before:content-[''] prose-code:after:content-[''] prose-code:bg-muted prose-code:rounded prose-code:px-1.5 prose-code:py-1 dark:prose-code:bg-card prose-code:font-normal max-w-none [&_pre>code]:p-0",
isCompact
? "prose-headings:my-2 prose-p:my-1 prose-ul:my-1 prose-li:my-0.5 prose-ol:my-1 prose-blockquote:my-2 prose-pre:my-2 prose-table:my-2 prose-th:text-xs prose-hr:my-3 text-[0.775rem] leading-4"
: "prose-headings:my-2.5 prose-p:my-1.5 prose-ul:my-1.5 prose-li:my-1 prose-ol:my-1.5 prose-blockquote:my-2.5 prose-pre:my-2.5 prose-table:my-2.5 prose-th:text-sm prose-hr:my-5 leading-4.5",
@@ -594,7 +594,11 @@ function MessageText({
tr: ({ children }) => <tr>{children}</tr>,
th: ({ children }) => <th>{children}</th>,
td: ({ children }) => <td>{children}</td>,
- table: ({ children }) => <table>{children}</table>,
+ table: ({ children }) => (
+ <div className="overflow-x-auto rounded">
+ <table>{children}</table>
+ </div>
+ ),
}}
>
{text}
diff --git a/web/src/ee/features/in-app-agent/components/InAppAgentWindow.stories.tsx b/web/src/ee/features/in-app-agent/components/InAppAgentWindow.stories.tsx
index 4b85366f55..8f02489fbc 100644
--- a/web/src/ee/features/in-app-agent/components/InAppAgentWindow.stories.tsx
+++ b/web/src/ee/features/in-app-agent/components/InAppAgentWindow.stories.tsx
@@ -1,25 +1,351 @@
import preview from "../../../../../.storybook/preview";
-import { useArgs } from "storybook/preview-api";
+import { useEffect, useRef, useState } from "react";
import { fn } from "storybook/test";
import {
InAppAgentWindow,
+ type InAppAgentWindowMessage,
type InAppAgentWindowProps,
} from "./InAppAgentWindow";
function StatefulInAppAgentWindow(args: InAppAgentWindowProps) {
- const [, updateArgs] = useArgs<InAppAgentWindowProps>();
+ const [isExpanded, setIsExpanded] = useState(args.isExpanded);
return (
<InAppAgentWindow
{...args}
+ isExpanded={isExpanded}
onExpandedChange={(isExpanded) => {
- updateArgs({ isExpanded });
+ setIsExpanded(isExpanded);
args.onExpandedChange(isExpanded);
}}
/>
);
}
+const streamingSeedMessages: InAppAgentWindowMessage[] = [
+ {
+ id: "seed-user-1",
+ role: "user",
+ content: {
+ type: "text",
+ text: "Find the cause of latency spikes in production traces.",
+ },
+ },
+ {
+ id: "seed-assistant-1",
+ role: "assistant",
+ content: {
+ type: "text",
+ text: "I will inspect recent traces, query latency metrics, and compare the slowest observations against scores and model usage.",
+ },
+ },
+ {
+ id: "seed-tool-1",
+ role: "assistant",
+ content: {
+ type: "toolGroup",
+ tools: [
+ {
+ type: "tool",
+ name: "langfuse_queryMetrics",
+ args: JSON.stringify({
+ view: "observations",
+ metrics: [{ measure: "latency", aggregation: "p95" }],
+ fromTimestamp: "2026-06-10T08:00:00Z",
+ toTimestamp: "2026-06-10T09:00:00Z",
+ }),
+ result: JSON.stringify({ data: [{ p95_latency: 4.82 }] }),
+ },
+ ],
+ },
+ },
+ ...(Array.from({ length: 8 }, (_, index) => ({
+ id: `seed-follow-up-${index}`,
+ role: index % 3 === 0 ? "user" : "assistant",
+ content: {
+ type: "text",
+ text:
+ index % 3 === 0
+ ? `Can you narrow this down for service group ${index + 1}?`
+ : [
+ `Service group ${index + 1} has enough previous context to make this story scrollable before live streaming starts.`,
+ "Scroll up while the assistant response streams to verify auto-follow detaches.",
+ "Scroll back near the bottom to attach again.",
+ ].join("\n"),
+ },
+ })) satisfies InAppAgentWindowMessage[]),
+];
+
+const streamingInvestigations = [
+ {
+ prompt: "Check whether the spike is isolated to retrieval.",
+ intro:
+ "I am checking retrieval-heavy traces first because their p95 latency moved before generation latency changed.",
+ toolName: "langfuse_getTraces",
+ toolArgs: {
+ limit: 5,
+ orderBy: "latency.desc",
+ filter: "name contains retrieval",
+ },
+ toolResult: {
+ data: [
+ { traceId: "trace-ret-104", latencyMs: 5820 },
+ { traceId: "trace-ret-219", latencyMs: 5410 },
+ ],
+ },
+ conclusion:
+ "The slowest traces are retrieval-heavy. The expensive step is document reranking, not the initial vector search.",
+ },
+ {
+ prompt: "Compare the same window against quality scores.",
+ intro:
+ "Next I am joining the slow traces with score distributions so we can see whether the latency spike also changed output quality.",
+ toolName: "langfuse_queryMetrics",
+ toolArgs: {
+ view: "scores",
+ dimensions: ["scoreName"],
+ metrics: [{ measure: "value", aggregation: "avg" }],
+ },
+ toolResult: {
+ data: [
+ { scoreName: "helpfulness", avg_value: 0.72 },
+ { scoreName: "groundedness", avg_value: 0.68 },
+ ],
+ },
+ conclusion:
+ "Quality moved down in the same segment. The groundedness score dropped most, which fits a retrieval or reranking regression.",
+ },
+ {
+ prompt: "Inspect model usage for the outlier traces.",
+ intro:
+ "I am checking model and token usage because a fallback model or larger context window can make otherwise healthy traces slow.",
+ toolName: "langfuse_getObservations",
+ toolArgs: {
+ traceIds: ["trace-ret-104", "trace-ret-219"],
+ columns: ["providedModelName", "totalTokens", "latency"],
+ },
+ toolResult: {
+ data: [
+ { providedModelName: "gpt-4.1", totalTokens: 18420, latencyMs: 3820 },
+ { providedModelName: "gpt-4.1", totalTokens: 17610, latencyMs: 3610 },
+ ],
+ },
+ conclusion:
+ "Model choice is stable, but token counts are much higher than the baseline. The reranker is likely passing too many documents forward.",
+ },
+];
+
+function appendToken(currentText: string, nextText: string) {
+ if (currentText.length >= nextText.length) {
+ return currentText;
+ }
+
+ const nextSpaceIndex = nextText.indexOf(" ", currentText.length + 1);
+
+ return nextText.slice(
+ 0,
+ nextSpaceIndex === -1 ? nextText.length : nextSpaceIndex,
+ );
+}
+
+function StreamingInAppAgentWindow(args: InAppAgentWindowProps) {
+ const [isExpanded, setIsExpanded] = useState(args.isExpanded);
+ const [messages, setMessages] = useState<InAppAgentWindowMessage[]>(
+ streamingSeedMessages,
+ );
+ const streamRef = useRef({
+ cycle: 0,
+ phase: "start" as
+ | "start"
+ | "intro"
+ | "tool-loading"
+ | "tool-done"
+ | "conclusion",
+ phaseTicks: 0,
+ introMessageId: "",
+ toolMessageId: "",
+ conclusionMessageId: "",
+ });
+
+ useEffect(() => {
+ const intervalId = window.setInterval(() => {
+ const stream = streamRef.current;
+ const investigation =
+ streamingInvestigations[stream.cycle % streamingInvestigations.length];
+
+ if (stream.phase === "start") {
+ const cycleId = `stream-${stream.cycle}`;
+ stream.introMessageId = `${cycleId}-intro`;
+ stream.toolMessageId = `${cycleId}-tool`;
+ stream.conclusionMessageId = `${cycleId}-conclusion`;
+ stream.phase = "intro";
+ stream.phaseTicks = 0;
+
+ setMessages((currentMessages) => [
+ ...currentMessages,
+ {
+ id: `${cycleId}-user`,
+ role: "user",
+ content: { type: "text", text: investigation.prompt },
+ },
+ {
+ id: stream.introMessageId,
+ role: "assistant",
+ content: { type: "text", text: "" },
+ },
+ ]);
+
+ return;
+ }
+
+ if (stream.phase === "intro") {
+ setMessages((currentMessages) =>
+ currentMessages.map((message) => {
+ if (
+ message.id !== stream.introMessageId ||
+ message.content.type !== "text"
+ ) {
+ return message;
+ }
+
+ const text = appendToken(message.content.text, investigation.intro);
+
+ if (text === investigation.intro) {
+ stream.phase = "tool-loading";
+ stream.phaseTicks = 0;
+ }
+
+ return { ...message, content: { type: "text", text } };
+ }),
+ );
+
+ return;
+ }
+
+ if (stream.phase === "tool-loading") {
+ stream.phase = "tool-done";
+ stream.phaseTicks = 0;
+
+ setMessages((currentMessages) => [
+ ...currentMessages,
+ {
+ id: stream.toolMessageId,
+ role: "assistant",
+ content: {
+ type: "toolGroup",
+ isLoading: true,
+ tools: [
+ {
+ type: "tool",
+ name: investigation.toolName,
+ args: JSON.stringify(investigation.toolArgs, null, 2),
+ },
+ ],
+ },
+ },
+ ]);
+
+ return;
+ }
+
+ if (stream.phase === "tool-done") {
+ stream.phaseTicks += 1;
+
+ if (stream.phaseTicks < 5) {
+ return;
+ }
+
+ stream.phase = "conclusion";
+ stream.phaseTicks = 0;
+
+ setMessages((currentMessages) => [
+ ...currentMessages.map((message) => {
+ if (
+ message.id !== stream.toolMessageId ||
+ message.content.type !== "toolGroup"
+ ) {
+ return message;
+ }
+
+ return {
+ ...message,
+ content: {
+ type: "toolGroup" as const,
+ tools: [
+ {
+ type: "tool" as const,
+ name: investigation.toolName,
+ args: JSON.stringify(investigation.toolArgs, null, 2),
+ result: JSON.stringify(investigation.toolResult, null, 2),
+ },
+ ],
+ },
+ };
+ }),
+ {
+ id: stream.conclusionMessageId,
+ role: "assistant",
+ content: { type: "text", text: "" },
+ },
+ ]);
+
+ return;
+ }
+
+ setMessages((currentMessages) =>
+ currentMessages.map((message) => {
+ if (
+ message.id !== stream.conclusionMessageId ||
+ message.content.type !== "text"
+ ) {
+ return message;
+ }
+
+ const text = appendToken(
+ message.content.text,
+ investigation.conclusion,
+ );
+
+ if (text === investigation.conclusion) {
+ stream.cycle += 1;
+ stream.phase = "start";
+ stream.phaseTicks = 0;
+ }
+
+ return { ...message, content: { type: "text", text } };
+ }),
+ );
+ }, 140);
+
+ return () => window.clearInterval(intervalId);
+ }, []);
+
+ return (
+ <InAppAgentWindow
+ {...args}
+ isExpanded={isExpanded}
+ messages={messages}
+ onExpandedChange={(isExpanded) => {
+ setIsExpanded(isExpanded);
+ args.onExpandedChange(isExpanded);
+ }}
+ onSubmit={(input) => {
+ setMessages((currentMessages) => [
+ ...currentMessages,
+ {
+ id: `manual-${currentMessages.length}`,
+ role: "user",
+ content: { type: "text", text: input },
+ },
+ ]);
+
+ args.onSubmit(input);
+ return true;
+ }}
+ />
+ );
+}
+
const conversations = [
{
id: "conversation-1",
@@ -33,6 +359,9 @@ const conversations = [
},
];
+const longUnbrokenWord = `trace-${"0123456789abcdef".repeat(18)}`;
+const longUnbrokenTableValue = `observation-${"abcdefghijklmnopqrstuvwxyz".repeat(10)}`;
+
const meta = preview.meta({
component: InAppAgentWindow,
parameters: {
@@ -186,10 +515,50 @@ export const Conversation = meta.story({
].join("\n"),
},
},
+ {
+ id: "user-long-word",
+ role: "user",
+ content: {
+ type: "text",
+ text: `This normal message includes a very long unbroken word to check wrapping: ${longUnbrokenWord}`,
+ },
+ },
+ {
+ id: "assistant-long-word",
+ role: "assistant",
+ content: {
+ type: "text",
+ text: `This normal message includes a very long unbroken word to check wrapping: ${longUnbrokenWord}`,
+ },
+ },
+ {
+ id: "assistant-long-table",
+ role: "assistant",
+ content: {
+ type: "text",
+ text: [
+ "Some trace attributes can contain very long values without spaces:",
+ "",
+ "| Field | Value | Notes |",
+ "| --- | --- | --- |",
+ `| Trace ID | ${longUnbrokenWord} | Generated by a customer system without delimiters |`,
+ `| Observation ID | ${longUnbrokenTableValue} | Long table cell value without spaces |`,
+ `| Metadata key | custom-${longUnbrokenTableValue} | Another long unbroken token in a different column |`,
+ ].join("\n"),
+ },
+ },
],
},
});
+export const Streaming = meta.story({
+ args: {
+ selectedConversationId: "conversation-1",
+ messages: streamingSeedMessages,
+ },
+ render: StreamingInAppAgentWindow,
+});
+
export const LoadingResponse = meta.story({
args: {
messages: [
diff --git a/web/src/ee/features/in-app-agent/components/InAppAgentWindow.tsx b/web/src/ee/features/in-app-agent/components/InAppAgentWindow.tsx
index 9b6324abef..8224170fef 100644
--- a/web/src/ee/features/in-app-agent/components/InAppAgentWindow.tsx
+++ b/web/src/ee/features/in-app-agent/components/InAppAgentWindow.tsx
@@ -6,9 +6,9 @@ import {
History,
Maximize2,
Minimize2,
+ Minus,
Plus,
SendHorizontal,
- X,
} from "lucide-react";
import { Button } from "@/src/components/ui/button";
import {
@@ -19,6 +19,11 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/src/components/ui/dropdown-menu";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from "@/src/components/ui/tooltip";
import { cn } from "@/src/utils/tailwind";
import {
InAppAgentMessage,
@@ -27,7 +32,19 @@ import {
} from "./InAppAgentMessage";
import type { InAppAgentMessageFeedbackValue } from "@/src/ee/features/in-app-agent/schema";
-const AUTO_SCROLL_THRESHOLD_PX = 200;
+const AUTO_SCROLL_THRESHOLD_PX = 50;
+const SCROLL_DIRECTION_TOLERANCE_PX = 1;
+
+function scrollViewportToBottom(viewport: HTMLDivElement | null) {
+ if (!viewport) {
+ return;
+ }
+
+ viewport.scrollTo({
+ top: viewport.scrollHeight,
+ behavior: "auto",
+ });
+}
export type InAppAgentWindowMessage = {
id: string;
@@ -94,38 +111,25 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {
zIndex,
} = props;
const viewportRef = useRef<HTMLDivElement>(null);
- const scrollPositionRef = useRef<{
- scrollHeight: number;
- scrollTop: number;
- clientHeight: number;
- } | null>(null);
+ const isAutoScrollAttachedRef = useRef(true);
+ const previousScrollTopRef = useRef(0);
const inputRef = useRef<HTMLTextAreaElement>(null);
const [input, setInput] = useState("");
useEffect(() => {
- const viewport = viewportRef.current;
-
- if (!viewport) {
+ if (!isAutoScrollAttachedRef.current) {
return;
}
- const scrollPosition = scrollPositionRef.current;
- const isNearBottom =
- !scrollPosition ||
- scrollPosition.scrollHeight -
- scrollPosition.scrollTop -
- scrollPosition.clientHeight <=
- AUTO_SCROLL_THRESHOLD_PX;
+ scrollViewportToBottom(viewportRef.current);
+ }, [messages]);
- if (!isNearBottom) {
- return;
- }
+ useEffect(() => {
+ isAutoScrollAttachedRef.current = true;
+ previousScrollTopRef.current = 0;
- viewport.scrollTo({
- top: viewport.scrollHeight,
- behavior: "smooth",
- });
- }, [messages]);
+ scrollViewportToBottom(viewportRef.current);
+ }, [selectedConversationId]);
useEffect(() => {
const input = inputRef.current;
@@ -140,6 +144,7 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {
return (
<section
+ aria-label="Assistant"
className={cn(
"bg-background flex min-w-0 flex-col overflow-hidden rounded-xl border shadow/5",
isExpanded
@@ -149,38 +154,46 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {
>
<header className="bg-header flex min-h-11.25 shrink-0 items-center justify-between gap-2 border-b px-3 py-1">
<div className="flex min-w-0 flex-1 items-center gap-2">
- <p className="shrink-0 truncate text-sm font-semibold">
- AI Assistant
- </p>
+ <p className="shrink-0 truncate text-sm font-semibold">Assistant</p>
<span className="text-muted-foreground rounded border px-1.5 py-1 text-xs leading-none font-medium">
Beta
</span>
</div>
<div className="flex shrink-0 items-center gap-0.5">
- <Button
- type="button"
- variant="ghost"
- size="icon"
- className="size-6 shrink-0"
- onClick={onNewConversation}
- disabled={isInputDisabled}
- aria-label="Start new AI agent conversation"
- >
- <Plus className="size-3" />
- </Button>
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
+ <Tooltip delayDuration={100} disableHoverableContent>
+ <TooltipTrigger asChild>
<Button
type="button"
variant="ghost"
size="icon"
className="size-6 shrink-0"
+ onClick={onNewConversation}
disabled={isInputDisabled}
- aria-label="Conversation history"
+ aria-label="Start new conversation"
>
- <History className="size-3" />
+ <Plus className="size-3" />
</Button>
- </DropdownMenuTrigger>
+ </TooltipTrigger>
+ <TooltipContent>Start new conversation</TooltipContent>
+ </Tooltip>
+ <DropdownMenu>
+ <Tooltip delayDuration={100} disableHoverableContent>
+ <TooltipTrigger asChild>
+ <DropdownMenuTrigger asChild>
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon"
+ className="size-6 shrink-0"
+ disabled={isInputDisabled}
+ aria-label="Conversation history"
+ >
+ <History className="size-3" />
+ </Button>
+ </DropdownMenuTrigger>
+ </TooltipTrigger>
+ <TooltipContent>Conversation history</TooltipContent>
+ </Tooltip>
<DropdownMenuContent
align="end"
className="max-h-80 w-64 overflow-y-auto"
@@ -222,31 +235,43 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {
) : null}
</DropdownMenuContent>
</DropdownMenu>
- <Button
- type="button"
- variant="ghost"
- size="icon"
- className="size-6"
- aria-label={isExpanded ? "Collapse window" : "Expand window"}
- onClick={() => onExpandedChange(!isExpanded)}
- >
- {isExpanded ? (
- <Minimize2 className="size-3" />
- ) : (
- <Maximize2 className="size-3" />
- )}
- </Button>
+ <Tooltip delayDuration={100} disableHoverableContent>
+ <TooltipTrigger asChild>
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon"
+ className="size-6"
+ aria-label={isExpanded ? "Collapse window" : "Expand window"}
+ onClick={() => onExpandedChange(!isExpanded)}
+ >
+ {isExpanded ? (
+ <Minimize2 className="size-3" />
+ ) : (
+ <Maximize2 className="size-3" />
+ )}
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>
+ {isExpanded ? "Collapse window" : "Expand window"}
+ </TooltipContent>
+ </Tooltip>
{props.showCloseButton !== false ? (
- <Button
- type="button"
- variant="ghost"
- size="icon"
- className="size-6"
- aria-label="Close assistant"
- onClick={props.onClose}
- >
- <X className="size-3" />
- </Button>
+ <Tooltip delayDuration={100} disableHoverableContent>
+ <TooltipTrigger asChild>
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon"
+ className="size-6"
+ aria-label="Minimize assistant"
+ onClick={props.onClose}
+ >
+ <Minus className="size-3" />
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>Minimize assistant</TooltipContent>
+ </Tooltip>
) : null}
</div>
</header>
@@ -256,11 +281,22 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {
className="min-h-0 flex-1 overflow-y-auto"
onScroll={(event) => {
const viewport = event.currentTarget;
- scrollPositionRef.current = {
- scrollHeight: viewport.scrollHeight,
- scrollTop: viewport.scrollTop,
- clientHeight: viewport.clientHeight,
- };
+ const distanceFromBottom =
+ viewport.scrollHeight -
+ viewport.scrollTop -
+ viewport.clientHeight;
+ const isNearBottom = distanceFromBottom <= AUTO_SCROLL_THRESHOLD_PX;
+ const scrolledUp =
+ viewport.scrollTop <
+ previousScrollTopRef.current - SCROLL_DIRECTION_TOLERANCE_PX;
+
+ if (scrolledUp && !isNearBottom) {
+ isAutoScrollAttachedRef.current = false;
+ } else if (isNearBottom) {
+ isAutoScrollAttachedRef.current = true;
+ }
+
+ previousScrollTopRef.current = viewport.scrollTop;
}}
>
<div
@@ -366,15 +402,22 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {
Promise.resolve(onSubmit(content))
.then((submitted) => {
if (submitted) {
+ isAutoScrollAttachedRef.current = true;
+
setInput((currentInput) =>
currentInput.trim() === content ? "" : currentInput,
);
+
+ window.requestAnimationFrame(() =>
+ scrollViewportToBottom(viewportRef.current),
+ );
}
})
.catch(() => undefined);
}}
>
<textarea
+ autoFocus={!isExpanded}
ref={inputRef}
value={input}
onChange={(event) => setInput(event.target.value)}
@@ -389,8 +432,8 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {
}
}}
disabled={isInputDisabled}
- aria-label="Ask about Langfuse"
- placeholder="Ask about Langfuse..."
+ aria-label="Ask the assistant a question"
+ placeholder="Ask the assistant a question..."
rows={1}
className={cn(
"bg-background placeholder:text-muted-foreground w-full flex-1 resize-none overflow-y-auto rounded-md text-sm leading-5 disabled:cursor-not-allowed disabled:opacity-60",
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 f5be8eea06..925de20ae3 100644
--- a/web/src/ee/features/in-app-agent/server/agent.ts
+++ b/web/src/ee/features/in-app-agent/server/agent.ts
@@ -18,8 +18,8 @@ const getAssistantSystemPrompt = (
context: AgUiRunAgentInput["context"] = [],
) => `
<identity>
- You are an assistant called Langfuse Assistant.
- Your role is to assist users with tasks in the Langfuse Cloud product.
+You are an assistant called Langfuse Assistant.
+Your role is to assist users with tasks in the Langfuse Cloud product.
</identity>
<behavioral_rules>
@@ -30,10 +30,18 @@ Focus on answering the user's questions. Do not comment on your own behavior:
Always provide a complete answer to the user's question in your response, do not rely on users seeing tool input or output.
If a tool call fails but you intend on re-trying it, do not mention the failure and just retry the tool call.
If you cannot provide an answer to the user, spare the user the details of failed tool calls and instead summarize the issue.
+If you think it would be helpful, ask the user for clarification or follow up questions to guide them.
</behavioral_rules>
+<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:
+- Explain to the user how they can perform the action themselves in the UI (use the docs for this if needed).
+- If the action is available via the CLI, suggest that the user can ask their own agent (Claude, Codex or similar) to perform the action for them using the CLI, for that they should use the Langfuse skill: https://github.com/langfuse/skills. When suggesting this, provide a prompt the user can use as a code block.
+</permissions>
+
<style_rules>
-Be concise, factual, and useful.
+Be concise, factual, and useful. Unless asked for a detailed explanation, keep your answers short and to the point.
Use markdown in your responses when appropriate, especially for tables and lists.
</style_rules>