Open
Description
Confirm this is a feature request for the Node library and not the underlying OpenAI API.
- This is a feature request for the Node library
Describe the feature or improvement you're requesting
Current Behavior
When handling tool outputs using submitToolOutputsStream()
, we currently need to track the run_id
through the runStepCreated
event; it would be better if the run_id
is available in the toolCallDone
event's payload.
Current pattern:
const stream: AssistantStream = await openaiClient.beta.threads.runs.stream(
thread.id,
{
assistant_id: assistant.id,
}
);
let runId: string | undefined;
stream
.on("runStepCreated", (runStep) => {
runId = runStep.run_id;
})
.on("toolCallDone", async (toolCall) => {
console.log("toolCallDone", toolCall);
if (toolCall.type == "function") {
// call function...
if (runId) {
await openaiClient.beta.threads.runs.submitToolOutputsStream(
thread.id,
runId,
{
tool_outputs: [
...
],
}
);
}
}
})
Proposed Enhancement
The toolCallDone
event handler should receive the run_id
directly in its payload, eliminating the need for the separate runStepCreated
event handler. This would simplify the code and remove potential race conditions.
Suggested pattern:
outputStream
.on("toolCallDone", async (toolCall: ToolCall, runId: string) => {
// call function...
await openaiClient.beta.threads.runs.submitToolOutputsStream(
thread.id,
runId,
{
tool_outputs: [...],
}
);
}
Benefits
- Simpler, more straightforward code
- Eliminates potential race conditions between events
- Reduces unnecessary state management
- More intuitive API design
Additional Context
This enhancement would be particularly useful when chaining multiple tool calls, as it would remove the need to maintain run ID state between event handlers.
Environment
- OpenAI Node.js Library Version: [4.77.3]
Additional context
No response
Metadata
Assignees
Labels
No labels
Activity