Skip to content

Commit ad42545

Browse files
author
Bohdan Danyliuk
committed
provide env var to enable tool error logging
1 parent 503a6ea commit ad42545

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/agents/_debug.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ def _load_dont_log_tool_data() -> bool:
1717
return _debug_flag_enabled("OPENAI_AGENTS_DONT_LOG_TOOL_DATA", default=True)
1818

1919

20+
def _load_log_tool_errors() -> bool:
21+
return _debug_flag_enabled("OPENAI_AGENTS_LOG_TOOL_ERRORS", default=False)
22+
23+
2024
DONT_LOG_MODEL_DATA = _load_dont_log_model_data()
2125
"""By default we don't log LLM inputs/outputs, to prevent exposing sensitive information. Set this
2226
flag to enable logging them.
@@ -26,3 +30,6 @@ def _load_dont_log_tool_data() -> bool:
2630
"""By default we don't log tool call inputs/outputs, to prevent exposing sensitive information. Set
2731
this flag to enable logging them.
2832
"""
33+
34+
LOG_TOOL_ERRORS = _load_log_tool_errors()
35+
"""By default we don't log tool errors. Set this flag to enable logging them."""

src/agents/tool.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,11 @@ async def _on_invoke_tool(ctx: ToolContext[Any], input: str) -> Any:
456456
},
457457
)
458458
)
459+
if _debug.LOG_TOOL_ERRORS:
460+
logger.exception(
461+
f"Tool error occurred: {e.__class__.__name__}",
462+
exc_info=e,
463+
)
459464
return result
460465

461466
return FunctionTool(

0 commit comments

Comments
 (0)