Skip to content

Conversation

@fede-kamel
Copy link
Contributor

Problem

The test_tool_choice_none_after_tool_results test added in PR #50 fails with:

AttributeError: module 'oci.generative_ai_inference.models' has no attribute 'Tool'

This was reported by @paxiaatucsdedu in #50 (comment)

Root Cause

The test used non-existent OCI SDK classes and had several issues:

  1. Used models.Tool which doesn't exist in the OCI SDK
  2. Incorrect test expectations - Expected tool_choice=none after any ToolMessage, but the actual implementation only sets it when:
    • max_sequential_tool_calls limit is exceeded, OR
    • An infinite loop is detected
  3. Missing stop parameter in _prepare_request() call
  4. Missing kwargs - Didn't pass bound model kwargs containing tools

Solution

Fixed the test to:

  1. ✅ Use Python function instead of OCI SDK mock objects (following pattern from other tests)
  2. ✅ Create scenario with 3 sequential tool calls to exceed max_sequential_tool_calls=3 limit
  3. ✅ Add required stop parameter to _prepare_request() call
  4. ✅ Pass bound model kwargs to ensure tools are included in the request

Changes

  • libs/oci/tests/unit_tests/chat_models/test_oci_generative_ai.py
    • Replaced models.Tool with Python function get_weather(city: str)
    • Updated test to create 3 ToolMessages to trigger the limit
    • Fixed _prepare_request() call signature
    • Updated docstring to accurately describe the test

Test Results

Before: ❌ FAILED

AttributeError: module 'oci.generative_ai_inference.models' has no attribute 'Tool'

After: ✅ PASSED

tests/unit_tests/chat_models/test_oci_generative_ai.py::test_tool_choice_none_after_tool_results PASSED

All 6 tool-related unit tests now pass:

test_meta_tool_calling PASSED
test_cohere_tool_choice_validation PASSED
test_meta_tool_conversion PASSED
test_ai_message_tool_calls_direct_field PASSED
test_ai_message_tool_calls_additional_kwargs PASSED
test_tool_choice_none_after_tool_results PASSED ✅

Impact

  • ✅ Unblocks developers encountering this test failure
  • ✅ No changes to production code - test-only fix
  • ✅ Backward compatible
  • ✅ Ready to merge immediately

Related:

The test was failing after rebase because it used non-existent OCI SDK
classes (models.Tool) and had incorrect expectations about when tool_choice
is set to 'none'.

Changes:
1. Replace OCI SDK mock objects with Python function (following pattern
   from other tests in the file)
2. Update test to trigger actual tool_choice=none behavior by exceeding
   max_sequential_tool_calls limit (3 tool calls)
3. Fix _prepare_request call signature (add stop parameter)
4. Pass bound model kwargs to _prepare_request (required for tools)
5. Update docstring to accurately describe what's being tested

The test now correctly validates that tool_choice is set to ToolChoiceNone
when the max_sequential_tool_calls limit is reached, preventing infinite
tool calling loops.

Related to PR oracle#50 (infinite loop fix) and PR oracle#53 (tool call optimization).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Oct 30, 2025
@fede-kamel
Copy link
Contributor Author

✅ All Unit Tests Verified

Ran all unit tests for ChatOCIGenAI to verify the fix:

cd ~/Projects/langchain-oracle/libs/oci
.venv/bin/python -m pytest tests/unit_tests/chat_models/test_oci_generative_ai.py -v

Test Results: 12/12 PASSED

tests/unit_tests/chat_models/test_oci_generative_ai.py::test_llm_chat[cohere.command-r-16k] PASSED
tests/unit_tests/chat_models/test_oci_generative_ai.py::test_llm_chat[meta.llama-3.3-70b-instruct] PASSED
tests/unit_tests/chat_models/test_oci_generative_ai.py::test_meta_tool_calling PASSED
tests/unit_tests/chat_models/test_oci_generative_ai.py::test_cohere_tool_choice_validation PASSED
tests/unit_tests/chat_models/test_oci_generative_ai.py::test_meta_tool_conversion PASSED
tests/unit_tests/chat_models/test_oci_generative_ai.py::test_json_mode_output PASSED
tests/unit_tests/chat_models/test_oci_generative_ai.py::test_json_schema_output PASSED
tests/unit_tests/chat_models/test_oci_generative_ai.py::test_auth_file_location PASSED
tests/unit_tests/chat_models/test_oci_generative_ai.py::test_include_raw_output PASSED
tests/unit_tests/chat_models/test_oci_generative_ai.py::test_ai_message_tool_calls_direct_field PASSED
tests/unit_tests/chat_models/test_oci_generative_ai.py::test_ai_message_tool_calls_additional_kwargs PASSED
tests/unit_tests/chat_models/test_oci_generative_ai.py::test_tool_choice_none_after_tool_results PASSED ✅

All tool-related tests pass, including the previously failing test_tool_choice_none_after_tool_results!

This fix is ready to merge and will unblock developers encountering the test failure.

@YouNeedCryDear YouNeedCryDear self-assigned this Oct 31, 2025
@YouNeedCryDear YouNeedCryDear merged commit a317f22 into oracle:main Oct 31, 2025
1 check passed
@fede-kamel fede-kamel deleted the fix/test-tool-choice-none branch October 31, 2025 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants