fix: harden run-level hook lifecycle
maintainer edit: keep cancellation out of on_error so shutdown paths do not look like run failures, and let the SDK capture hook use the authoritative after_run snapshot.
This commit is contained in:
@@ -166,7 +166,9 @@ class SDKCaptureHook(AgentHook):
|
||||
|
||||
The runner mutates ``context.messages`` in place across iterations, so the
|
||||
snapshot is refreshed on every ``after_iteration`` call; the last call
|
||||
reflects the end-of-turn state the SDK caller cares about.
|
||||
reflects the end-of-turn state the SDK caller cares about. The run-level
|
||||
snapshot is authoritative when available and covers paths without a final
|
||||
per-iteration callback.
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
@@ -178,3 +180,7 @@ class SDKCaptureHook(AgentHook):
|
||||
for call in context.tool_calls:
|
||||
self.tools_used.append(call.name)
|
||||
self.messages = list(context.messages)
|
||||
|
||||
async def after_run(self, context: AgentRunHookContext) -> None:
|
||||
self.tools_used = list(context.tools_used)
|
||||
self.messages = list(context.messages)
|
||||
|
||||
Reference in New Issue
Block a user