@@ -6023,6 +6023,66 @@ def make_result() -> dict[str, str]:
60236023 ]
60246024 assert len(execution_warnings) == 1
60256025 assert (_PRIVATE_ERROR_DETAIL in execution_warnings[0]) is enable_sensitive_data
6026+ assert ("Set include_detailed_errors=True" in execution_warnings[0]) is not include_detailed_errors
6027+
6028+
6029+ @pytest.mark.parametrize(
6030+ ("enable_instrumentation", "enable_sensitive_data"),
6031+ [(False, False), (True, False), (True, True)],
6032+ indirect=True,
6033+ )
6034+ @pytest.mark.usefixtures("span_exporter")
6035+ @pytest.mark.parametrize("include_detailed_errors", [False, True])
6036+ async def test_function_execution_error_warning_recommends_detailed_errors_only_when_disabled(
6037+ chat_client_base: SupportsChatGetResponse,
6038+ monkeypatch: pytest.MonkeyPatch,
6039+ caplog: pytest.LogCaptureFixture,
6040+ include_detailed_errors: bool,
6041+ enable_sensitive_data: bool,
6042+ ) -> None:
6043+ @tool(name="error_function", approval_mode="never_require")
6044+ def error_func() -> str:
6045+ raise RuntimeError(f"Tool failure: {_PRIVATE_ERROR_DETAIL}")
6046+
6047+ monkeypatch.setattr(
6048+ chat_client_base,
6049+ "run_responses",
6050+ [
6051+ ChatResponse(
6052+ messages=Message(
6053+ role="assistant",
6054+ contents=[Content.from_function_call(call_id="1", name="error_function", arguments="{}")],
6055+ )
6056+ ),
6057+ ChatResponse(messages=Message(role="assistant", contents=["done"])),
6058+ ],
6059+ )
6060+ monkeypatch.setitem(
6061+ chat_client_base.function_invocation_configuration, # type: ignore[attr-defined] # ty: ignore[unresolved-attribute]
6062+ "include_detailed_errors",
6063+ include_detailed_errors,
6064+ )
6065+
6066+ with caplog.at_level(logging.WARNING, logger="agent_framework"):
6067+ response = await chat_client_base.get_response(
6068+ [Message(role="user", contents=["hello"])], options={"tools": [error_func]}
6069+ )
6070+
6071+ result = next(content for msg in response.messages for content in msg.contents if content.type == "function_result")
6072+ assert (_PRIVATE_ERROR_DETAIL in (result.result or "")) is include_detailed_errors
6073+ execution_warnings = [
6074+ record.getMessage()
6075+ for record in caplog.records
6076+ if record.name == "agent_framework"
6077+ and record.levelno == logging.WARNING
6078+ and "raised an exception; returning an error result" in record.getMessage()
6079+ ]
6080+ assert len(execution_warnings) == 1
6081+ assert execution_warnings[0].startswith(
6082+ "Function 'error_function' raised an exception; returning an error result to the model."
6083+ )
6084+ assert ("Set include_detailed_errors=True" in execution_warnings[0]) is not include_detailed_errors
6085+ assert (_PRIVATE_ERROR_DETAIL in execution_warnings[0]) is enable_sensitive_data
60266086
60276087
60286088async def test_function_invocation_config_include_detailed_errors_false(chat_client_base: SupportsChatGetResponse):
0 commit comments