[Concept,03/29] u_boot_pylib: Add a way to inspect agent output
Commit Message
From: Simon Glass <sjg@chromium.org>
When the Claude Agent SDK interrupts mid-run (e.g. due to a blocked tool
or an internal limit), only the text blocks are printed and any
surrounding message metadata is lost. This makes it hard to see why the
interruption happened.
Add an env-var hook: setting PATMAN_DEBUG_AGENT=1 dumps every message
and block received from the SDK to stderr. This is verbose so it is off
by default, but invaluable when diagnosing a stuck apply or review run.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
tools/u_boot_pylib/claude.py | 8 ++++++++
1 file changed, 8 insertions(+)
@@ -50,11 +50,19 @@ async def run_agent_collect(prompt, options):
tuple: (success, conversation_log) where success is bool and
conversation_log is the agent's output text
"""
+ import os
+ debug = os.environ.get('PATMAN_DEBUG_AGENT')
conversation_log = []
try:
async for message in query(prompt=prompt, options=options):
+ if debug:
+ tout.error(f'AGENT MSG: {type(message).__name__}: '
+ f'{message!r}')
if hasattr(message, 'content'):
for block in message.content:
+ if debug:
+ tout.error(f' BLOCK: {type(block).__name__}: '
+ f'{block!r}')
if hasattr(block, 'text'):
print(block.text)
conversation_log.append(block.text)