Skip to main content

Collapsed Segment Types

In v2, three specialized segment types have been collapsed into ToolCallSegment. This simplifies the segment union while preserving all functionality: a renderer picks the card by the display kind the tool declares (segment.display?.kind).

What changed​

Old typeNew typeHow to identify
SpawnAgentSegmentToolCallSegmentsegment.display?.kind === 'subagent'
SequentialThinkingSegmentToolCallSegmentsegment.display?.kind === 'thinking'
DSLPipelineSegmentToolCallSegmentsegment.display?.kind === 'bal'

All three are now regular ToolCallSegment instances. display.kind, resolved from the tool's declared toolMetadata.display, tells you which kind of tool call it is; core's own reducers select these calls by kind, not by tool name, so a tool named spawn_agent without a kind is an ordinary call.

Migration: SpawnAgentSegment​

// Before
import type { SpawnAgentSegment } from '@baleybots/core';

function renderSegment(segment: StreamSegment) {
if (segment.type === 'spawn_agent') {
return <AgentCard agentName={segment.agentName} />;
}
}

// After
import type { ToolCallSegment } from '@baleybots/core';
import { getSpawnAgentData } from '@baleybots/core';

function renderSegment(segment: StreamSegment) {
if (segment.type === 'tool_call' && segment.display?.kind === 'subagent') {
const data = getSpawnAgentData(segment);
return <AgentCard goal={data.goal} />;
}
}

Migration: SequentialThinkingSegment​

// Before
if (segment.type === 'sequential_thinking') {
return <ThinkingCard thoughts={segment.thoughts} />;
}

// After
import { getSequentialThinkingData } from '@baleybots/core';

if (segment.type === 'tool_call' && segment.display?.kind === 'thinking') {
const data = getSequentialThinkingData(segment);
return <ThinkingCard thoughts={data.thoughts} />;
}

Migration: DSLPipelineSegment​

// Before
if (segment.type === 'dsl_pipeline') {
return <PipelineCard steps={segment.steps} />;
}

// After
import { getDSLPipelineData } from '@baleybots/core';

if (segment.type === 'tool_call' && segment.display?.kind === 'bal') {
const data = getDSLPipelineData(segment);
return <PipelineCard steps={data.steps} />;
}

Generic rendering​

If you don't need special rendering for these tool types, you can treat all tool calls uniformly:

function renderSegment(segment: StreamSegment) {
if (segment.type === 'tool_call') {
return (
<div>
<b>Tool: {segment.name}</b>
<pre>{JSON.stringify(segment.args, null, 2)}</pre>
{segment.result && <pre>{JSON.stringify(segment.result, null, 2)}</pre>}
</div>
);
}
}

Typed helper functions​

The @baleybots/core package provides typed helper functions for accessing tool-specific data:

  • getSpawnAgentData(segment) -- returns { goal, agentType, tools, childSegments, result, ... }
  • getSequentialThinkingData(segment) -- returns { thoughts, ... }
  • getDSLPipelineData(segment) -- returns { steps, ... }

These helpers parse the tool call arguments and results into typed objects, so you don't need to manually extract data from segment.args and segment.result.