Validate a Streamed Sequence of Parallel Tool Call Events

Last updated: November 29, 2026

Quick Overview

A model streams tool calls as start, delta (argument text) and end events, possibly interleaving several calls, followed by a finish event. Validate the sequence: ids are unique, deltas and ends target open calls, each call's concatenated arguments are valid JSON, and finish comes last with no calls open.

OpenAI
Coding & Algorithms
Software Engineer
OpenAI
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


A model streams tool calls as start, delta (argument text) and end events, possibly interleaving several calls, followed by a finish event. Validate the sequence: ids are unique, deltas and ends target open calls, each call's concatenated arguments are valid JSON, and finish comes last with no calls open.

Function calling in the OpenAI API can stream several tool calls in parallel, and client libraries must reassemble and validate them before executing anything. The interviewer is checking that you model this as a state machine with per-call state, give precise error messages, and treat the end of the stream as its own check.

What the Interviewer Expects
  • Track per-call state in a map from id to buffered fragments
  • Reject events for unknown or already closed calls
  • Validate JSON only once a call ends, not per fragment
  • Reject events after finish and a missing finish
  • Return a specific reason for the first violation
Key Topics to Cover
state machines
stream validation
hash maps
function calling
JSON
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Return the parsed tool calls in the order they started.
  • Make the validator incremental so it can run as events arrive and reject early.
  • Arguments must also match a JSON schema per tool name: where does that check go?
  • How would you recover gracefully from one malformed call without discarding the others?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Events: ("start", id, name), ("delta", id, text), ("end", id), ("finish",).
  • Ids are unique for the whole stream; calls may interleave.
  • On end, the joined deltas must parse as JSON.
  • `...
High-Level Design

Each call moves through states: not seen, open, closed. Keep open_calls (id to fragment list) and closed (ids already ended), plus a finished flag for the stream. Each event is a transition that...


Submit Your Answer
Markdown supported