Heuristic:AIPexStudio AIPex Tool Args Streaming
| Knowledge Sources | |
|---|---|
| Domains | Streaming, UX_Optimization |
| Last Updated | 2026-10-24 12:00 GMT |
Overview
Tool call argument streaming is a best-effort, provider-dependent feature that emits incremental `tool_call_args_streaming_start` events from raw model deltas before the runner's `tool_called` event fires.
Description
During agent execution, the AIPex core agent inspects raw model streaming events to detect tool call argument assembly in real-time. For providers that stream tool call arguments as deltas (e.g., OpenAI ChatCompletions with `delta.tool_calls[].function.{name,arguments}`), the agent emits a `tool_call_args_streaming_start` event as soon as the tool name is identifiable from the accumulating deltas. This gives UIs an early "parameters being assembled" indicator before the `@openai/agents` runner emits the final `tool_called` event with complete arguments. The feature is best-effort: if the provider does not stream tool call deltas, only the `tool_call_args_streaming_complete` event will fire (when the runner emits `tool_called`).
Usage
Use this heuristic when building UIs that show tool execution progress. Handle `tool_call_args_streaming_start` to show a "preparing..." state and `tool_call_args_streaming_complete` to transition to "parameters ready." Do not rely on streaming start events for providers that don't support delta streaming — your UI should gracefully handle the case where only the complete event fires.
The Insight (Rule of Thumb)
- Action: Listen for both `tool_call_args_streaming_start` and `tool_call_args_streaming_complete` events in the agent event stream.
- Value: The `start` event provides only `toolName` (no params). The `complete` event provides `toolName` + `params` (full arguments).
- Trade-off: The start event may never fire for providers that don't stream tool call deltas. UIs must handle this gracefully — do not block on the start event.
- Compatibility: Works with OpenAI ChatCompletions streaming. Other providers (Anthropic, Google) may or may not emit the raw delta structure needed.
Reasoning
When a model decides to call a tool, the tool name and arguments are often streamed incrementally across multiple response chunks. The `@openai/agents` runner assembles these chunks and only emits a `tool_called` event when the full arguments are available. This creates a latency gap between when the model starts producing tool call output and when the UI can show "tool X is being called." By inspecting the raw `model` events for `delta.tool_calls`, AIPex can emit an early start event, giving UIs a faster visual signal. The tracking is per-response (reset on `response_started`) and uses a `Map<index, state>` keyed by the tool call's delta index, since multiple tool calls can be streamed simultaneously in a single response.
Code Evidence
Per-response tool args tracking initialization from `packages/core/src/agent/aipex.ts:134-138`:
// Track tool-call argument streaming during a single model response.
// This is best-effort and provider-dependent (e.g. OpenAI ChatCompletions tool_calls deltas).
const toolArgsStreamByIndex = new Map<
number,
{ toolName: string; startEmitted: boolean }
>();
Raw delta inspection for streaming start from `packages/core/src/agent/aipex.ts:197-239`:
if ((streamEvent.data as unknown as { type?: string })?.type === "model") {
const raw = (streamEvent.data as unknown as { event?: unknown })?.event;
const choices = (raw as any)?.choices;
const delta = Array.isArray(choices) ? choices?.[0]?.delta : null;
const toolCalls = delta?.tool_calls;
if (Array.isArray(toolCalls)) {
for (const tcDelta of toolCalls) {
const nameDelta = tcDelta?.function?.name;
if (typeof nameDelta === "string" && nameDelta.length > 0) {
state.toolName += nameDelta;
}
if (!state.startEmitted && state.toolName.length > 0) {
state.startEmitted = true;
yield { type: "tool_call_args_streaming_start", toolName: state.toolName };
}
}
}
}
Complete event emission before tool execution from `packages/core/src/agent/aipex.ts:251-261`:
if (streamEvent.name === "tool_called") {
const toolName = this.extractToolName(streamEvent.item);
const params = this.extractToolArguments(streamEvent.item);
const argsCompleteEvent: AgentEvent = {
type: "tool_call_args_streaming_complete",
toolName,
params,
};
yield argsCompleteEvent;
}
Tracking reset on new response boundary from `packages/core/src/agent/aipex.ts:161-167`:
if ((streamEvent.data as unknown as { type?: string })?.type === "response_started") {
toolArgsStreamByIndex.clear();
continue;
}