AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
feat(agents): an agent's runs open in a side panel next to the chat, like the flow builder (#16034)
Hazem Adel06041de28e72
diff --git a/packages/web/public/locales/en/translation.json b/packages/web/public/locales/en/translation.jsonindex 6f799548b61..d2f2471fde5 100644--- a/packages/web/public/locales/en/translation.json+++ b/packages/web/public/locales/en/translation.json@@ -2375,6 +2375,8 @@"from failed step": "from failed step","Viewing retried runs": "Viewing retried runs","No flow runs found": "No flow runs found",+ "No flow has run this agent yet": "No flow has run this agent yet",+ "Add a Run Agent step to a flow and pick this agent. Every run it makes on its own shows up here.": "Add a Run Agent step to a flow and pick this agent. Every run it makes on its own shows up here.","Come back later when your automations start running": "Come back later when your automations start running","runsRetriedNote": "{runsCount, plural, =0 {0 runs retried} =1 {A run was retried} other {# runs were retried}}","Queue Status": "Queue Status",diff --git a/packages/web/src/app/routes/agents/id/index.tsx b/packages/web/src/app/routes/agents/id/index.tsxindex 5de6f05d5fe..fadf27231b1 100644--- a/packages/web/src/app/routes/agents/id/index.tsx+++ b/packages/web/src/app/routes/agents/id/index.tsx@@ -1,13 +1,7 @@import { isNil, unique } from '@activepieces/core-utils';import { Agent, AgentToolType } from '@activepieces/shared';import { t } from 'i18next';-import {- ChevronLeft,- History,- MessageSquare,- SearchX,- Settings2,-} from 'lucide-react';+import { ChevronLeft, History, SearchX, Settings2 } from 'lucide-react';import { useState } from 'react';import {useLocation,@@ -26,7 +20,6 @@ import {EmptyTitle,} from '@/components/ui/empty';import { Skeleton } from '@/components/ui/skeleton';-import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';import { useAgentsAvailable } from '@/features/agents';import { AgentMark } from '@/features/agents/agent-mark';import { agentsQueries } from '@/features/agents/hooks/agents-hooks';@@ -115,6 +108,7 @@ const AgentEditorContent = () => {writeConversationParam(nextConversationId);};const runsOpen = pathname.endsWith(`/${RUNS_TAB}`);+ const [runsWereOpen, setRunsWereOpen] = useState(runsOpen);const showTab = (nextTab: string) => {const suffix = nextTab === RUNS_TAB ? `/${RUNS_TAB}` : '';const carried = new URLSearchParams();@@ -128,6 +122,7 @@ const AgentEditorContent = () => {authenticationSession.appendProjectRoutePrefix(`/agents/${agentId}${suffix}${query.length > 0 ? `?${query}` : ''}`,),+ { replace: true },);};const startNewConversation = () => {@@ -146,9 +141,23 @@ const AgentEditorContent = () => {const needsModel = agent !== undefined && needsAModel(agent);const panel: OpenPanel =- openPanel ?? (needsModel ? 'configure' : 'conversations');+ openPanel ?? (needsModel && !runsOpen ? 'configure' : 'conversations');const configureOpen = panel === 'configure';const conversationsOpen = panel === 'conversations';+ const runsVisible = runsOpen && !configureOpen;+ const toggleRuns = () => showTab(runsVisible ? CHAT_TAB : RUNS_TAB);+ const openConfigure = () => {+ setOpenPanel('configure');+ if (runsOpen) {+ showTab(CHAT_TAB);+ }+ };+ if (runsOpen !== runsWereOpen) {+ setRunsWereOpen(runsOpen);+ if (runsOpen && configureOpen) {+ setOpenPanel('conversations');+ }+ }if (configureOpen && !configureMounted) {setConfigureMounted(true);}@@ -185,12 +194,7 @@ const AgentEditorContent = () => {return (<div className="flex h-full w-full"><div className="flex min-w-0 grow flex-col">- <div- className={cn(- 'flex h-[60px] shrink-0 items-center gap-3 px-5',- !runsOpen && 'border-b border-border',- )}- >+ <div className="flex h-[60px] shrink-0 items-center gap-3 border-b border-border px-5"><buttontype="button"aria-label={t('Back')}@@ -208,37 +212,23 @@ const AgentEditorContent = () => {{agent.description ?? t('No description yet')}</span></div>- <Tabs- value={runsOpen ? RUNS_TAB : CHAT_TAB}- onValueChange={showTab}- className="h-full self-stretch"+ <Button+ type="button"+ variant="outline"+ className="h-[34px] shrink-0 gap-2 rounded-lg px-[13px]"+ aria-pressed={runsVisible}+ onClick={toggleRuns}>- <TabsList variant="outline" className="h-full gap-1">- <TabsTrigger- value={CHAT_TAB}- variant="outline"- className="h-full rounded-none"- >- <MessageSquare className="mr-2 size-4" />- {t('Chat')}- </TabsTrigger>- <TabsTrigger- value={RUNS_TAB}- variant="outline"- className="h-full rounded-none"- >- <History className="mr-2 size-4" />- {t('Runs')}- </TabsTrigger>- </TabsList>- </Tabs>+ <History size={15} />+ {t('Runs')}+ </Button>{!configureOpen && (<div className="flex min-w-0 shrink items-center gap-2"><Buttontype="button"variant="outline"className="h-[34px] shrink-0 gap-2 rounded-lg px-[13px] animate-in fade-in duration-200"- onClick={() => setOpenPanel('configure')}+ onClick={openConfigure}><Settings2 size={15} />{t('Configure')}@@ -247,24 +237,33 @@ const AgentEditorContent = () => {)}</div><div className="flex min-h-0 grow">- {runsOpen ? (- <AgentRuns agentId={agent.id} />- ) : (- <AgentChatView- agent={agent}- conversationsOpen={conversationsOpen}- openedConversationId={openedConversationId ?? conversationId}- chatSessionKey={chatSessionKey}- footerNote={buildCapabilityNote(agent)}- onSelectConversation={openConversation}- onNewConversation={startNewConversation}- onCollapseConversations={() => setOpenPanel('none')}- onExpandConversations={() => setOpenPanel('conversations')}- onConversationCreated={writeConversationParam}- />- )}+ <AgentChatView+ agent={agent}+ conversationsOpen={conversationsOpen}+ openedConversationId={openedConversationId ?? conversationId}+ chatSessionKey={chatSessionKey}+ footerNote={buildCapabilityNote(agent)}+ onSelectConversation={openConversation}+ onNewConversation={startNewConversation}+ onCollapseConversations={() => setOpenPanel('none')}+ onExpandConversations={() => setOpenPanel('conversations')}+ onConversationCreated={writeConversationParam}+ /></div></div>+ <aside+ className={cn(+ SLIDING_ASIDE,+ 'border-l',+ runsVisible ? 'w-[400px]' : 'w-0',+ )}+ >+ <div className="flex h-full w-[400px] flex-col">+ {runsVisible && (+ <AgentRuns agentId={agent.id} onClose={() => showTab(CHAT_TAB)} />+ )}+ </div>+ </aside><asideonTransitionEnd={(event) => {if (event.propertyName === 'width' && !configureOpen) {diff --git a/packages/web/src/app/routes/agents/id/runs/index.tsx b/packages/web/src/app/routes/agents/id/runs/index.tsxindex ed7eb7dee5b..8b1e1845992 100644--- a/packages/web/src/app/routes/agents/id/runs/index.tsx+++ b/packages/web/src/app/routes/agents/id/runs/index.tsx@@ -1,35 +1,31 @@import { isNil } from '@activepieces/core-utils';-import { AgentRunListItem } from '@activepieces/shared';-import { ColumnDef } from '@tanstack/react-table';import { t } from 'i18next';-import {- Activity,- Bot,- Clock,- History,- Coins,- Hourglass,- Workflow,-} from 'lucide-react';-import { useMemo, useState } from 'react';+import { History } from 'lucide-react';+import { useState } from 'react';-import { DataTable, RowDataWithActions } from '@/components/custom/data-table';-import { DataTableColumnHeader } from '@/components/custom/data-table/data-table-column-header';-import { TruncatedColumnTextValue } from '@/components/custom/data-table/truncated-column-text-value';+import { SidebarHeader } from '@/app/builder/sidebar-header';+import {+ CardListItem,+ CardListItemSkeleton,+} from '@/components/custom/card-list';+import { DataFetchErrorState } from '@/components/custom/data-fetch-error-state';import { FormattedDate } from '@/components/custom/formatted-date';-import { StatusIconWithText } from '@/components/custom/status-icon-with-text';+import { Button } from '@/components/ui/button';+import {+ Empty,+ EmptyDescription,+ EmptyHeader,+ EmptyMedia,+ EmptyTitle,+} from '@/components/ui/empty';import { agentsQueries } from '@/features/agents/hooks/agents-hooks';import { agentRunUtils } from '@/features/agents/lib/agent-run-utils';import { projectCollectionUtils } from '@/features/projects';-import { formatUtils } from '@/lib/format-utils';+import { cn } from '@/lib/utils';import { RunDetailPanel } from './run-detail-panel';-type AgentRunsProps = {- agentId: string;-};--export const AgentRuns = ({ agentId }: AgentRunsProps) => {+export const AgentRuns = ({ agentId, onClose }: AgentRunsProps) => {const { project } = projectCollectionUtils.useCurrentProject();const [openRunId, setOpenRunId] = useState<string | null>(null);const {@@ -37,153 +33,98 @@ export const AgentRuns = ({ agentId }: AgentRunsProps) => {isLoading,isError,refetch,+ hasNextPage,+ fetchNextPage,+ isFetchingNextPage,} = agentsQueries.useAgentRuns({ agentId, projectId: project.id });-- const columns: ColumnDef<RowDataWithActions<AgentRunListItem>>[] = useMemo(- () => [- {- accessorKey: 'title',- size: 380,- header: ({ column }) => (- <DataTableColumnHeader column={column} title={t('Run')} icon={Bot} />- ),- cell: ({ row }) => (- <button- type="button"- className="flex items-center gap-2 text-left hover:underline"- onClick={(e) => {- e.stopPropagation();- setOpenRunId(row.original.id);- }}- >- <TruncatedColumnTextValue- value={row.original.title ?? t('Untitled run')}- className="max-w-[260px] 2xl:max-w-[420px]"- />- </button>- ),- },- {- accessorKey: 'flow',- size: 220,- header: ({ column }) => (- <DataTableColumnHeader- column={column}- title={t('Flow')}- icon={Workflow}- />- ),- cell: ({ row }) => {- const flow = row.original.flow;- if (isNil(flow)) {- return <span className="text-muted-foreground">{'\u2014'}</span>;- }- return (- <div className="flex items-center gap-2 text-left">- <TruncatedColumnTextValue value={flow.displayName} />- </div>- );- },- },- {- accessorKey: 'status',- size: 140,- header: ({ column }) => (- <DataTableColumnHeader- column={column}- title={t('Status')}- icon={Activity}- />- ),- cell: ({ row }) => {- const { Icon, variant } = agentRunUtils.getStatusIcon(- row.original.status,- );- return (- <div className="text-left">- <StatusIconWithText- icon={Icon}- text={agentRunUtils.getStatusLabel(row.original.status)}- variant={variant}- />- </div>- );- },- },- {- accessorKey: 'updated',- size: 140,- header: ({ column }) => (- <DataTableColumnHeader- column={column}- title={t('Duration')}- icon={Hourglass}- />- ),- cell: ({ row }) => {- const durationMs = agentRunUtils.getDurationMs(row.original);- return (- <span className="text-left text-muted-foreground">- {isNil(durationMs)- ? '\u2014'- : formatUtils.formatDuration(durationMs, true)}- </span>- );- },- },- {- accessorKey: 'aiCredits',- size: 130,- header: ({ column }) => (- <DataTableColumnHeader- column={column}- title={t('Credits')}- icon={Coins}- />- ),- cell: ({ row }) => (- <span className="text-left text-muted-foreground">- {isNil(row.original.aiCredits) ? '\u2014' : row.original.aiCredits}- </span>- ),- },- {- accessorKey: 'created',- header: ({ column }) => (- <DataTableColumnHeader- column={column}- title={t('Started At')}- icon={Clock}- />- ),- cell: ({ row }) => (- <FormattedDate- date={new Date(row.original.created)}- className="text-left"- />- ),- },- ],- [],- );+ const items = runs?.pages.flatMap((page) => page.data) ?? [];+ const showList = !isLoading && !isError && items.length > 0;return (<div className="flex h-full w-full min-w-0 flex-col">- <DataTable- columns={columns}- page={runs}- isLoading={isLoading}- isError={isError}- errorStateEntity={t('runs')}- onRetry={refetch}- onRowClick={(row) => setOpenRunId(row.id)}- emptyStateIcon={<History className="size-14" />}- emptyStateTextTitle={t('No flow has run this agent yet')}- emptyStateTextDescription={t(- 'Add a Run Agent step to a flow and pick this agent. Every run it makes on its own shows up here.',- )}- />+ <div className="flex h-[60px] shrink-0 items-center border-b border-border px-2">+ <SidebarHeader onClose={onClose}>{t('Recent Runs')}</SidebarHeader>+ </div>+ {isLoading && <CardListItemSkeleton numberOfCards={6} />}+ {isError && <DataFetchErrorState entity={t('runs')} onRetry={refetch} />}+ {!isLoading && !isError && items.length === 0 && (+ <Empty className="h-full">+ <EmptyHeader>+ <EmptyMedia variant="icon">+ <History />+ </EmptyMedia>+ <EmptyTitle>{t('No flow has run this agent yet')}</EmptyTitle>+ <EmptyDescription>+ {t(+ 'Add a Run Agent step to a flow and pick this agent. Every run it makes on its own shows up here.',+ )}+ </EmptyDescription>+ </EmptyHeader>+ </Empty>+ )}+ {showList && (+ <div className="min-h-0 grow overflow-y-auto">+ {items.map((run) => {+ const { Icon, variant } = agentRunUtils.getStatusIcon(run.status);+ return (+ <CardListItem+ key={run.id}+ className="p-0"+ selected={run.id === openRunId}+ >+ <button+ type="button"+ className="flex w-full min-w-0 items-center gap-3 px-3 py-3 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"+ onClick={() => setOpenRunId(run.id)}+ >+ <Icon+ aria-label={agentRunUtils.getStatusLabel(run.status)}+ className={cn('size-5 shrink-0', {+ 'text-success': variant === 'success',+ 'text-destructive': variant === 'error',+ })}+ />+ <div className="flex min-w-0 flex-col gap-1">+ <span className="truncate text-sm font-medium">+ {run.title ?? t('Untitled run')}+ </span>+ <span className="flex min-w-0 gap-1 text-xs text-muted-foreground">+ {!isNil(run.flow) && (+ <span className="truncate">+ {run.flow.displayName} ·+ </span>+ )}+ <FormattedDate+ date={new Date(run.created)}+ includeTime={true}+ className="shrink-0"+ />+ </span>+ </div>+ </button>+ </CardListItem>+ );+ })}+ {hasNextPage && (+ <div className="px-3 py-2">+ <Button+ className="w-full"+ variant="accent"+ onClick={() => fetchNextPage()}+ loading={isFetchingNextPage}+ >+ {t('More...')}+ </Button>+ </div>+ )}+ </div>+ )}<RunDetailPanel runId={openRunId} onClose={() => setOpenRunId(null)} /></div>);};++type AgentRunsProps = {+ agentId: string;+ onClose: () => void;+};diff --git a/packages/web/src/features/agents/hooks/agents-hooks.ts b/packages/web/src/features/agents/hooks/agents-hooks.tsindex b5616abe8d9..746e9b109fe 100644--- a/packages/web/src/features/agents/hooks/agents-hooks.ts+++ b/packages/web/src/features/agents/hooks/agents-hooks.ts@@ -2,24 +2,22 @@ import { isNil } from '@activepieces/core-utils';import {Agent,AgentConversationStatus,+ AgentRunListItem,AgentListSort,CreateAgentRequest,MoveAgentRequest,Permission,+ SeekPage,UpdateAgentRequest,} from '@activepieces/shared';import {+ InfiniteData,useInfiniteQuery,useMutation,useQuery,useQueryClient,} from '@tanstack/react-query';-import { useSearchParams } from 'react-router-dom';-import {- CURSOR_QUERY_PARAM,- LIMIT_QUERY_PARAM,-} from '@/components/custom/data-table';import { internalErrorToast } from '@/components/ui/sonner';import { useAuthorization } from '@/hooks/authorization-hooks';import { platformHooks } from '@/hooks/platform-hooks';@@ -40,6 +38,7 @@ export const useAgentsNavVisible = (): boolean => {};const AGENTS_PAGE_SIZE = 100;+const AGENT_RUNS_PAGE_SIZE = 20;const AGENT_RUNS_ACTIVE_POLL_MS = 5 * 1000;const AGENT_RUNS_IDLE_POLL_MS = 15 * 1000;@@ -121,18 +120,41 @@ export const agentsQueries = {agentId: string;projectId: string;}) => {- const [searchParams] = useSearchParams();- const cursor = searchParams.get(CURSOR_QUERY_PARAM);- const limit = searchParams.get(LIMIT_QUERY_PARAM);- return useQuery({- queryKey: [AGENTS_KEY, 'runs', agentId, cursor, limit],- queryFn: () =>+ const queryClient = useQueryClient();+ const listKey = [AGENTS_KEY, 'runs', agentId];+ const list = useInfiniteQuery({+ queryKey: listKey,+ queryFn: ({ pageParam }) =>agentsApi.listRuns({agentId,projectId,- cursor: cursor ?? undefined,- limit: limit === null ? undefined : parseInt(limit),+ cursor: pageParam,+ limit: AGENT_RUNS_PAGE_SIZE,}),+ initialPageParam: undefined as string | undefined,+ getNextPageParam: (lastPage) => lastPage.next ?? undefined,+ });+ const latest = useQuery({+ queryKey: [AGENTS_KEY, 'runs-latest', agentId],+ queryFn: async () => {+ const latest = await agentsApi.listRuns({+ agentId,+ projectId,+ limit: AGENT_RUNS_PAGE_SIZE,+ });+ const shown =+ queryClient.getQueryData<InfiniteData<SeekPage<AgentRunListItem>>>(+ listKey,+ )?.pages[0];+ if (!isNil(shown) && runsSignature(shown) !== runsSignature(latest)) {+ await queryClient.invalidateQueries({+ queryKey: listKey,+ exact: true,+ });+ }+ return latest;+ },+ enabled: list.isSuccess,refetchInterval: (query) => {const stillRunning = query.state.data?.data.some((run) => run.status === AgentConversationStatus.STREAMING,@@ -142,6 +164,12 @@ export const agentsQueries = {: AGENT_RUNS_IDLE_POLL_MS;},});+ return {+ ...list,+ isError: list.isError || latest.isError,+ refetch: () =>+ Promise.all([list.refetch(), latest.refetch()]).catch(() => undefined),+ };},};@@ -191,3 +219,9 @@ export const agentsMutations = {});},};++function runsSignature(page: SeekPage<AgentRunListItem>): string {+ return page.data+ .map((run) => `${run.id}:${run.status}:${run.title ?? ''}`)+ .join(',');+}