Conversation
Log each PydanticAI tool invocation via Python logging to stderr and print a dim Rich indicator (⚙ tool_name) in the REPL. A new -v/--verbose flag includes tool arguments in debug-level output. Logging setup is idempotent and isolated in patchwork/logging_config.py.
|
Two issues stood out in this patch:
I'd also add one regression test for each behavior:
If the always-on tool indicator is intentional, I think that should be called out explicitly in the PR description because it's a UX change, not just logging infrastructure. |
- Move console.print of ⚙ tool_name inside the verbose branch so default mode only logs to stderr without changing REPL output - Update setup_logging to always apply the handler level on subsequent calls instead of returning early, so verbose=True is honored even if the logger was previously initialized with verbose=False - Add regression tests for both behaviors
What
Adds structured logging for every PydanticAI tool invocation, giving operators
visibility into which tools the agent calls during a conversation. A new
-v/--verboseCLI flag enables debug-level output that includes tool arguments.How
patchwork/logging_config.py— New module withsetup_logging(verbose)thatconfigures a
patchworklogger writing to stderr. Idempotent (safe to callmultiple times without adding duplicate handlers).
patchwork/cli.py—_make_event_handler()returns an async callback matchingPydanticAI's
EventStreamHandlersignature. It filters forFunctionToolCallEvent,logs the tool name at INFO, optionally logs args at DEBUG in verbose mode, and prints
a dim Rich indicator (
⚙ tool_name) to the console. The handler is wired intoagent.run_stream()via theevent_stream_handlerparameter. Anargparseparseradds
-v/--verbose, and errors now go throughlogger.exception().Tests —
test_logging_config.py(6 tests) covers logger creation, handlerlevels, and idempotency.
test_tool_logging.py(4 tests) covers tool name logging,verbose args, non-tool event filtering, and multiple events.
Recommended Review Order
patchwork/logging_config.py— small standalone modulepatchwork/cli.py— event handler + CLI wiringtests/test_logging_config.pytests/test_tool_logging.py