Deliver tool-tied `'asap'` enqueue content into the same `ModelRequest` as the tool's `ToolReturnPart'
Fixes #7014
ctx.enqueue(.....) called during a tool's execution currently delivers the enqueued
content as its own trailing ModelRequest, appended after the request carrying the
tool's ToolReturnPart. The wire-level _clean_message_history merge already hides
this (adjacent requests with no assistant turn between them get combined before
sending to the model), but all_messages() keeps them separate, so the causal tie
between a tool call and its enqueued side effect isn't visible in history.
When enqueue is called during a tool call (the tool body itself, or a capability
hook wrapping that call) with the default priority='asap', and the enqueued
content is a single request's worth of parts (not a passthrough ModelRequest/
ModelResponse), it's now spliced into the same ModelRequest as that tool call's
ToolReturnPart, immediately after it. Everything else when_idle, enqueues
outside a tool call (hooks between steps, AgentRun.enqueue), and passthrough
messages is delivered exactly as before.
Multiple enqueue() calls from the same tool call stay in their own call order
when spliced. Parallel tool calls each splice into their own return, never a
sibling's.
EnqueuedMessagesEvent gains a parts field alongside messages: a spliced
delivery has no standalone message object to report, so the event carries the
inserted parts themselves instead still "the same objects held in the run's
message history, exactly as they landed there," just at the parts level.
Test plan
- Existing enqueue-during-tool tests updated for the new merged shape
- Added a test verifying parallel tool calls each land next to their own return
- Added a test pinning that wire output is byte-identical to the old
separate-request-plus-merge shape -
ruff format --check,ruff check,pyrightall pass -
pytest tests/test_capabilities.py: 871 passed