refactor(sdk): move SDKCaptureHook to agent/hook.py
Colocate the capture hook with the rest of the hook infrastructure instead of inlining it in the top-level facade module.
This commit is contained in:
@@ -102,3 +102,22 @@ class CompositeHook(AgentHook):
|
||||
for h in self._hooks:
|
||||
content = h.finalize_content(context, content)
|
||||
return content
|
||||
|
||||
|
||||
class SDKCaptureHook(AgentHook):
|
||||
"""Record tool names and the final message list for ``RunResult``.
|
||||
|
||||
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.
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.tools_used: list[str] = []
|
||||
self.messages: list[dict[str, Any]] = []
|
||||
|
||||
async def after_iteration(self, context: AgentHookContext) -> None:
|
||||
for call in context.tool_calls:
|
||||
self.tools_used.append(call.name)
|
||||
self.messages = list(context.messages)
|
||||
|
||||
Reference in New Issue
Block a user