In _run_agent(), the pending message handler references 'event' which is not defined in that scope — it only exists in the caller. This causes a NameError when sending the first response before processing a queued follow-up message. Replace getattr(event, 'metadata', None) with the established pattern using source.thread_id, consistent with lines 2625, 2810, 3678, 4410, 4566 in the same file.