Workspace/Coding labs
Loading progress

Assemble interleaved message events

Intermediate65 min

Reduce only AG-UI TEXT_MESSAGE_START, TEXT_MESSAGE_CONTENT, and TEXT_MESSAGE_END events. A start requires a new nonempty message ID and role assistant. Content requires an open message and a nonempty string delta. End closes an open message. Return {messageId: {text, open}}, preserving incomplete messages. Reject invalid ordering and unsupported types with ValueError. This is a strict subset for teaching, not a full AG-UI client, transport, replay protocol, or renderer.

Your task

  1. Complete the starter function using the contract above.
  2. Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
  3. Run tests to record your result, then compare with the explained reference solution.

Examples

EXAMPLE 1

Inputstart a, content a=Hi, start b, content b=Wait, end a

Outputa contains Hi and is closed; b contains Wait and is open

Interleaving must not combine unrelated buffers.
EXAMPLE 2

Inputcontent for an unknown message

OutputValueError

Lifecycle identity is required before a delta.
solution.pyPython 3.12