Skip to content

Commit 82b66b1

Browse files
authored
feat(slack): stream an Agent's tool-call timeline without its text (#10370)
* feat(slack): stream an Agent's tool-call timeline without its text Slack triggers gain streamTimelineSources (Agent blocks, including child workflows) and streamToolLabels. A timeline source streams through the executor as usual, but only its tool steps and optional thinking reach Slack; its text is drained and never posted. The first message of an execution is shared by timeline steps and the first answer, and is owned and stopped by the controller. Deployed configs without the new fields read as empty, so no redeploy is needed. * fix(slack): keep per-invocation outcomes, offer structured Agents, unique task IDs - The shared message settles from the invocations that wrote to it, and each invocation succeeds only if the ones before it did, matching how replies settled before the shared message existed. - The progress picker offers every Agent, including one whose response format replaces its content output. - Task IDs include the execution order inside a child workflow instance, so two Agents there never update the same step. - Tool labels and display titles ignore inherited object properties. - Fix the CI audits (toRecordOrNull, unused export) and test types. * fix(slack): serialize appends to a message shared by several invocations * test(slack): drive the append-ordering test with microtasks, not timers
1 parent c53ae4b commit 82b66b1

15 files changed

Lines changed: 897 additions & 119 deletions

File tree

‎apps/docs/content/docs/integrations/slack.mdx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ Custom-bot Slack triggers can stream workflow outputs directly back into the con
3131
- Loop and parallel invocations each create their own Slack response.
3232
- The response status label defaults to `Running` and can be customized in the trigger's advanced settings.
3333
- Optional thinking and tool-call updates appear as Slack tasks in a timeline or plan.
34+
- **Show progress from** (`streamTimelineSources`) shows an Agent's tool steps, and its thinking when enabled, without posting its text. Use it when an Agent's output is reviewed or reformatted by a later block: the steps and the first streamed answer share one Slack reply. Agents in child workflows can be selected. A block cannot be both an output to stream and a progress source.
35+
- **Tool step labels** (`streamToolLabels`) renames tool steps by tool name, for example `lc_cur` → `Reading AWS cost data`. Unlisted tools use a generated name. Steps never show tool arguments.
36+
- With PII block-output redaction on, Agent output is not streamed live, so no progress steps appear; selected outputs are still sent when their block completes.
3437
- Slack Agent Sessions remain in processing state for the run, return to active when it finishes, and the native Slack stop button cancels active workflow executions.
3538

3639
Automatic trigger responses require a custom bot created by the Slack setup wizard. They are not available with the shared Sim Slack app. Where the deployment enables shared-app triggers, the Sim app can receive its subscribed event subset without automatic streaming.
@@ -3867,6 +3870,8 @@ Trigger from Slack events, interactions, and slash commands
38673870
| `threads` | string | No | Include thread replies, exclude them \(top-level only\), or fire only on thread replies. |
38683871
| `streamResponse` | boolean | No | Create a Slack agent session and stream selected workflow outputs into the conversation that started this run. Custom bots only. |
38693872
| `streamOutputs` | workflow-output-selector | No | Use `<blockName>.<outputPath>` for this workflow or `<childWorkflowId>.<blockName>.<outputPath>` for a child workflow. Selecting a child workflow applies to every invocation of it. Agent outputs stream live; other outputs are sent when the block completes. |
3873+
| `streamTimelineSources` | workflow-output-selector | No | Agent blocks, including ones in child workflows, whose tool steps appear in the reply while they run. Their text is never posted. No steps appear when PII block-output redaction is on. |
3874+
| `streamToolLabels` | table | No | Optional names for tool steps, keyed by tool name \(an MCP tool by its own name, like lc_cur\). Unlisted tools use a generated name. |
38703875
| `streamTaskTitle` | string | No | Optional status Slack shows while each selected response is being produced. Leave empty to use Running. |
38713876
| `streamTaskDisplayMode` | string | No | Choose how Slack displays thinking and tool progress. |
38723877
| `streamIncludeThinking` | boolean | No | Show agent thinking as Slack task updates while the response is generated. |

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/chat/components/output-select/output-select.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
buildWorkflowOutputMenu,
1616
buildWorkflowOutputOptions,
1717
collectReferencedWorkflowIds,
18+
selectBlockPathOptions,
1819
type WorkflowOutputMenuNode,
1920
type WorkflowOutputOption,
2021
} from '@/lib/workflows/streaming/nested-output-options'
@@ -42,6 +43,8 @@ interface OutputSelectProps {
4243
disabled?: boolean
4344
/** Placeholder text when no outputs are selected */
4445
placeholder?: string
46+
/** Offers one option per block of this type, selecting this output path */
47+
outputFilter?: { blockType: string; path: string }
4548
/** Whether to emit internal IDs, display labels, or public dot selectors */
4649
valueMode?: 'id' | 'label' | 'public'
4750
/** Alignment of the dropdown relative to the trigger */
@@ -127,6 +130,7 @@ function OutputSelectContent({
127130
onOutputSelect,
128131
disabled = false,
129132
placeholder = 'Select outputs',
133+
outputFilter,
130134
valueMode = 'id',
131135
align = 'start',
132136
maxHeight = 200,
@@ -206,14 +210,17 @@ function OutputSelectContent({
206210
const thirdLevelStates = useWorkflowStates(thirdLevelWorkflowIds)
207211

208212
const workflowStates = new Map([...firstLevelStates, ...secondLevelStates, ...thirdLevelStates])
209-
const workflowOutputs = workflowId
213+
const allWorkflowOutputs = workflowId
210214
? buildWorkflowOutputOptions({
211215
rootWorkflowId: workflowId,
212216
rootState,
213217
workflowStates,
214218
maxChildDepth: DEFAULTS.MAX_SSE_CHILD_DEPTH,
215219
})
216220
: []
221+
const workflowOutputs = outputFilter
222+
? selectBlockPathOptions(allWorkflowOutputs, outputFilter.blockType, outputFilter.path)
223+
: allWorkflowOutputs
217224
const outputMenu = buildWorkflowOutputMenu(workflowOutputs)
218225
const outputMenuRevision = JSON.stringify([
219226
workflowId,

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/workflow-output-selector/workflow-output-selector.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface WorkflowOutputSelectorProps {
1111
previewValue?: string[] | null
1212
disabled?: boolean
1313
placeholder?: string
14+
outputFilter?: { blockType: string; path: string }
1415
}
1516

1617
export function WorkflowOutputSelector({
@@ -20,6 +21,7 @@ export function WorkflowOutputSelector({
2021
previewValue,
2122
disabled = false,
2223
placeholder,
24+
outputFilter,
2325
}: WorkflowOutputSelectorProps) {
2426
const workflowId = useWorkflowRegistry((state) => state.activeWorkflowId)
2527
const [storedValue, setStoredValue] = useSubBlockValue<string[]>(blockId, subBlockId)
@@ -34,6 +36,7 @@ export function WorkflowOutputSelector({
3436
onOutputSelect={setStoredValue}
3537
disabled={disabled || isPreview}
3638
placeholder={placeholder}
39+
outputFilter={outputFilter}
3740
valueMode='public'
3841
size='md'
3942
className='w-full'

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/sub-block.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,7 @@ function SubBlockComponent({
11521152
previewValue={previewValue as string[] | null | undefined}
11531153
disabled={isDisabled}
11541154
placeholder={config.placeholder}
1155+
outputFilter={config.outputFilter}
11551156
/>
11561157
)
11571158

‎apps/sim/blocks/blocks/slack.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3551,6 +3551,7 @@ export const SlackV2Block: BlockConfig = {
35513551
'Build Slack workflows with messages, conversations, files, reactions, pins, bookmarks, user groups, profiles, Lists, canvases, and Agent Sessions. Operations that need additional app scopes use custom Slack bots. Lists require lists:read/lists:write and a paid Slack plan. Native Sim connections retain their existing permissions. Page through list outputs explicitly.',
35523552
bestPractices: `${SlackBlock.bestPractices}
35533553
Native agent-session streaming uses a custom Slack bot and a supported trigger event. Enable streamResponse and select the intended outputs in streamOutputs; Sim Chat (mothership) streams its content output. The trigger owns the streamed reply, so another send needs a separate purpose.
3554+
To show an Agent's tool steps without posting its text (for example an analyst whose output a later block reviews), list that Agent in streamTimelineSources while streamOutputs keeps the block that posts the answer (a block cannot be in both), and optionally name its tools in streamToolLabels.
35543555
The custom-bot manifest's baseline agent scopes are ${SLACK_AGENT_SCOPES.join(', ')}. Selected capabilities add their required scopes and event subscriptions. Verify the installed app's grants, resource access and event configuration; a saved credential or edited manifest alone does not prove access.
35553556
streamIncludeToolCalls displays tool activity; it does not authorize tool execution. Configure Sim Chat's selected operations and their credentials separately. Choose streamIncludeThinking deliberately for the destination audience.
35563557
Block Kit messages can contain buttons, selects and forms, but interactions require the app's interactivity request URL and the corresponding interaction trigger. Treat message events, button/select callbacks and modal submissions as separate paths. A control's action_id/value correlates work; runtime actor and state checks authorize it.`,

‎apps/sim/blocks/types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ export interface SubBlockConfig {
393393
min?: number
394394
max?: number
395395
columns?: string[]
396+
/** Limits a `workflow-output-selector` to blocks of one type, each selecting `path`. */
397+
outputFilter?: { blockType: string; path: string }
396398
placeholder?: string
397399
/**
398400
* Conceals the stored value in the editor until the field is focused.

‎apps/sim/lib/mothership/tools/display.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,9 @@ export function getToolDisplayTitle(name: string, args?: Record<string, unknown>
14971497
}
14981498
}
14991499

1500-
return TOOL_TITLES[name] ?? CLI_TOOL_TITLES[name] ?? humanizeToolName(name)
1500+
if (Object.hasOwn(TOOL_TITLES, name)) return TOOL_TITLES[name]
1501+
if (Object.hasOwn(CLI_TOOL_TITLES, name)) return CLI_TOOL_TITLES[name]
1502+
return humanizeToolName(name)
15011503
}
15021504

15031505
/** First positional after the synthetic CLI command path; shared by resource and operation labels. */

‎apps/sim/lib/webhooks/slack-execution-stream.test.ts‎

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ const BASE_CONFIG: SlackStreamResponseConfig = {
4949
includeToolCalls: true,
5050
taskTitle: 'Running',
5151
taskDisplayMode: 'plan',
52+
timelineSources: [],
53+
toolLabels: {},
5254
}
5355

5456
function createLoggingSession() {
@@ -729,6 +731,213 @@ describe('SlackExecutionStreamController', () => {
729731
controller.assertSucceeded()
730732
})
731733

734+
describe('timeline sources', () => {
735+
const TIMELINE_CONFIG: SlackStreamResponseConfig = {
736+
...BASE_CONFIG,
737+
outputConfigs: [{ blockId: 'reply', path: 'result' }],
738+
timelineSources: [{ workflowId: 'child-workflow', blockId: 'analyst' }],
739+
toolLabels: { lc_cur: 'Reading AWS cost data' },
740+
}
741+
const TIMELINE_EVENTS: AgentStreamEvent[] = [
742+
{ type: 'tool_call_start', id: 'tool-1', name: 'mcp-6da535c1-lc_cur' },
743+
{ type: 'tool_call_end', id: 'tool-1', name: 'mcp-6da535c1-lc_cur', status: 'success' },
744+
{ type: 'tool_call_start', id: 'tool-2', name: 'mcp-6da535c1-lc_other' },
745+
{ type: 'tool_call_end', id: 'tool-2', name: 'mcp-6da535c1-lc_other', status: 'success' },
746+
{ type: 'text_delta', text: '{"secret":"analyst json"}', turn: 'pending' },
747+
{ type: 'turn_end', turn: 'final' },
748+
]
749+
750+
async function streamTimeline(
751+
controller: SlackExecutionStreamController,
752+
events: AgentStreamEvent[] = TIMELINE_EVENTS
753+
) {
754+
await controller.callbacks.onStream?.({
755+
blockId: 'child-workflow.analyst',
756+
childWorkflowInstanceId: 'child-instance-1',
757+
executionOrder: 2,
758+
stream: createByteStream('{"secret":"analyst json"}'),
759+
execution: { success: true, output: {} },
760+
clientStreamTransformed: false,
761+
subscribe: ({ onEvent }) => {
762+
for (const event of events) void onEvent(event)
763+
return vi.fn()
764+
},
765+
})
766+
}
767+
768+
function allChunks(): SlackStreamChunk[] {
769+
return [
770+
...mockStartSlackAgentStream.mock.calls.flatMap((call) => call[2]),
771+
...mockAppendSlackAgentStream.mock.calls.flatMap((call) => call[3]),
772+
...mockStopSlackAgentStream.mock.calls.flatMap((call) => call[6] ?? []),
773+
]
774+
}
775+
776+
it('streams the source as a block selector so the executor streams it', async () => {
777+
const { controller } = await createController(TIMELINE_CONFIG)
778+
expect(controller.selectedOutputs).toEqual(['reply_result', 'child-workflow.analyst_content'])
779+
})
780+
781+
it('shows tool steps without the source text and posts the answer in the same message', async () => {
782+
const { controller } = await createController(TIMELINE_CONFIG)
783+
await streamTimeline(controller)
784+
await controller.callbacks.onBlockComplete?.('reply', 'Reply', 'function', {
785+
output: { result: 'Reviewed answer' },
786+
executionOrder: 3,
787+
executionTime: 1,
788+
startedAt: '2026-11-24T00:00:00Z',
789+
endedAt: '2026-11-24T00:00:01Z',
790+
})
791+
await controller.finalize({ success: true, status: 'completed', output: {} })
792+
793+
controller.assertSucceeded()
794+
expect(mockStartSlackAgentStream).toHaveBeenCalledTimes(1)
795+
expect(mockStopSlackAgentStream).toHaveBeenCalledTimes(1)
796+
const text = allChunks()
797+
.filter((chunk) => chunk.type === 'markdown_text')
798+
.map((chunk) => (chunk.type === 'markdown_text' ? chunk.text : ''))
799+
.join('')
800+
expect(text).toBe('Reviewed answer')
801+
const toolTitles = allChunks().flatMap((chunk) =>
802+
chunk.type === 'task_update' && chunk.id.includes('-tool-') ? [chunk.title] : []
803+
)
804+
expect(new Set(toolTitles)).toEqual(new Set(['Reading AWS cost data', 'Lc Other']))
805+
expect(mockStopSlackAgentStream.mock.calls[0][3]).toBe('processing')
806+
})
807+
808+
it('stops a timeline-only message once with an error status when the run fails', async () => {
809+
const { controller } = await createController(TIMELINE_CONFIG)
810+
await streamTimeline(controller, [
811+
{ type: 'tool_call_start', id: 'tool-1', name: 'mcp-6da535c1-lc_cur' },
812+
])
813+
await controller.finalize({ success: false, output: {} })
814+
815+
expect(mockStartSlackAgentStream).toHaveBeenCalledTimes(1)
816+
expect(mockStopSlackAgentStream).toHaveBeenCalledTimes(1)
817+
expect(mockStopSlackAgentStream.mock.calls[0][3]).toBe('suspended')
818+
expect(mockStopSlackAgentStream.mock.calls[0][6]).toEqual(
819+
expect.arrayContaining([
820+
expect.objectContaining({ type: 'task_update', title: 'Running', status: 'error' }),
821+
expect.objectContaining({
822+
type: 'task_update',
823+
id: expect.stringContaining('-tool-tool-1'),
824+
status: 'error',
825+
}),
826+
])
827+
)
828+
})
829+
830+
it('never overlaps appends from the timeline and the answer on the shared message', async () => {
831+
let inFlight = 0
832+
let maxInFlight = 0
833+
mockAppendSlackAgentStream.mockImplementation(async () => {
834+
inFlight++
835+
maxInFlight = Math.max(maxInFlight, inFlight)
836+
for (let tick = 0; tick < 20; tick++) await Promise.resolve()
837+
inFlight--
838+
})
839+
const { controller } = await createController({
840+
...TIMELINE_CONFIG,
841+
outputConfigs: [{ blockId: 'reply', path: 'content' }],
842+
})
843+
await Promise.all([
844+
streamTimeline(controller),
845+
controller.callbacks.onStream?.({
846+
blockId: 'reply',
847+
executionOrder: 3,
848+
stream: createByteStream(),
849+
execution: { success: true, output: {} },
850+
clientStreamTransformed: false,
851+
subscribe: ({ onEvent }) => {
852+
void onEvent({ type: 'text_delta', text: 'Reviewed answer. ', turn: 'pending' })
853+
void onEvent({ type: 'turn_end', turn: 'final' })
854+
return vi.fn()
855+
},
856+
}),
857+
])
858+
859+
expect(mockStartSlackAgentStream).toHaveBeenCalledTimes(1)
860+
expect(mockAppendSlackAgentStream.mock.calls.length).toBeGreaterThan(1)
861+
expect(maxInFlight).toBe(1)
862+
})
863+
864+
it('still rejects a stream from a block in neither list', async () => {
865+
const { controller } = await createController(TIMELINE_CONFIG)
866+
await expect(
867+
controller.callbacks.onStream?.({
868+
blockId: 'other',
869+
executionOrder: 1,
870+
stream: createByteStream(),
871+
execution: { success: true, output: {} },
872+
})
873+
).rejects.toThrow('unselected block')
874+
})
875+
})
876+
877+
describe('per-invocation outcomes', () => {
878+
const unfinishedTool: AgentStreamEvent[] = [
879+
{ type: 'tool_call_start', id: 'tool-1', name: 'read_file' },
880+
]
881+
882+
function streamEvents(
883+
controller: SlackExecutionStreamController,
884+
executionOrder: number,
885+
events: AgentStreamEvent[]
886+
) {
887+
return controller.callbacks.onStream?.({
888+
blockId: 'agent',
889+
executionOrder,
890+
stream: createByteStream(),
891+
execution: { success: true, output: {} },
892+
clientStreamTransformed: false,
893+
subscribe: ({ onEvent }) => {
894+
for (const event of events) void onEvent(event)
895+
return vi.fn()
896+
},
897+
})
898+
}
899+
900+
it('does not mark an earlier answer failed when a later one fails', async () => {
901+
mockStartSlackAgentStream
902+
.mockResolvedValueOnce({ channel: 'C123', ts: 'first' })
903+
.mockResolvedValueOnce({ channel: 'C123', ts: 'second' })
904+
const { controller } = await createController()
905+
await streamEvents(controller, 1, [
906+
{ type: 'text_delta', text: 'First answer', turn: 'pending' },
907+
{ type: 'turn_end', turn: 'final' },
908+
])
909+
await streamEvents(controller, 2, unfinishedTool)
910+
await controller.finalize({ success: true, status: 'completed', output: {} })
911+
912+
const statusByTs = Object.fromEntries(
913+
mockStopSlackAgentStream.mock.calls.map((call) => [call[2], call[3]])
914+
)
915+
expect(statusByTs).toEqual({ first: 'processing', second: 'suspended' })
916+
})
917+
918+
it('posts no empty reply for a later invocation after an earlier one failed', async () => {
919+
const { controller } = await createController()
920+
await streamEvents(controller, 1, unfinishedTool)
921+
await streamEvents(controller, 2, [])
922+
await controller.finalize({ success: true, status: 'completed', output: {} })
923+
924+
expect(mockStartSlackAgentStream).toHaveBeenCalledTimes(1)
925+
expect(mockStopSlackAgentStream).toHaveBeenCalledTimes(1)
926+
})
927+
928+
it('titles a tool whose name is an object property', async () => {
929+
const { controller } = await createController({ ...BASE_CONFIG, toolLabels: {} })
930+
await streamEvents(controller, 1, [
931+
{ type: 'tool_call_start', id: 'tool-1', name: 'toString' },
932+
{ type: 'tool_call_end', id: 'tool-1', name: 'toString', status: 'success' },
933+
])
934+
const toolChunk = mockAppendSlackAgentStream.mock.calls
935+
.flatMap((call) => call[3] as SlackStreamChunk[])
936+
.find((chunk) => chunk.type === 'task_update' && chunk.id.includes('-tool-'))
937+
expect(toolChunk).toMatchObject({ title: expect.any(String) })
938+
})
939+
})
940+
732941
it('rejects credentials that do not belong to the workflow workspace', async () => {
733942
mockGetSlackBotCredential.mockResolvedValue({
734943
botToken: 'xoxb-token',

0 commit comments

Comments
 (0)