Skip to content

Commit 6942561

Browse files
Include total_blocks in content_block:end events
Orchestrator now includes total_blocks count in content_block:end event data, allowing hooks to determine which block is the last in the response. This enables hooks to display token usage after the last content block from each LLM response, rather than after every block or only at the end. Changes: - Added total_blocks to CONTENT_BLOCK_START event data - Added total_blocks to CONTENT_BLOCK_END event data - Hooks can now check: is_last = block_index == total_blocks - 1 🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
1 parent cb3fe47 commit 6942561

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

amplifier_module_loop_basic/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ async def execute(
174174
f"Response has content_blocks: {content_blocks is not None} - count: {len(content_blocks) if content_blocks else 0}"
175175
)
176176
if content_blocks:
177-
logger.info(f"Emitting events for {len(content_blocks)} content blocks")
177+
total_blocks = len(content_blocks)
178+
logger.info(f"Emitting events for {total_blocks} content blocks")
178179
for idx, block in enumerate(content_blocks):
179180
logger.info(f"Emitting CONTENT_BLOCK_START for block {idx}, type: {block.type.value}")
180181
# Emit block start (without non-serializable raw object)
@@ -183,11 +184,16 @@ async def execute(
183184
{
184185
"block_type": block.type.value,
185186
"block_index": idx,
187+
"total_blocks": total_blocks,
186188
},
187189
)
188190

189-
# Emit block end with complete block and usage
190-
event_data = {"block_index": idx, "block": block.to_dict()}
191+
# Emit block end with complete block, usage, and total count
192+
event_data = {
193+
"block_index": idx,
194+
"total_blocks": total_blocks,
195+
"block": block.to_dict(),
196+
}
191197
if usage:
192198
event_data["usage"] = usage.model_dump() if hasattr(usage, "model_dump") else usage
193199
await hooks.emit(CONTENT_BLOCK_END, event_data)

0 commit comments

Comments
 (0)