Skip to content

feat: implement OpenAICompatibleModel with native list tool return - #116

Merged
Million-mo merged 2 commits into
wolf1069b:feat/openai-compatible-native-tool-returnfrom
Million-mo:feat/openai-compatible-native-tool-return
Jul 6, 2026
Merged

feat: implement OpenAICompatibleModel with native list tool return#116
Million-mo merged 2 commits into
wolf1069b:feat/openai-compatible-native-tool-returnfrom
Million-mo:feat/openai-compatible-native-tool-return

Conversation

@Million-mo

Copy link
Copy Markdown
Collaborator

Summary

Implements the code for the OpenAI-Compatible Native Tool Return spec defined in PR #115.

Changes

  • src/agentpool/models/openai_compatible.pyOpenAICompatibleModel(OpenAIChatModel) subclass:

    • Overrides _map_user_message() to emit list[ChatCompletionContentPartTextParam] for tool returns with list content (when flag enabled)
    • openai_chat_tool_return_as_list profile flag (default False for backward compat)
    • openai_* kwarg passthrough with string→bool coercion for known boolean keys
    • ImportModelConfig support with base_url, api_key, tool_return_as_list constructor params
    • _coerce_profile_value() helper and _OPENAI_BOOL_PROFILE_KEYS / _OPENAI_PROFILE_FIELDS constants
  • src/agentpool/models/__init__.py — Export OpenAICompatibleModel and OpenAICompatibleModelProfile

  • tests/models/test_openai_compatible.py — 25 tests covering all spec scenarios:

    • Subclass relationship
    • Constructor params (string/bool coercion, defaults, profile overrides, TypeError)
    • _coerce_profile_value helper
    • _map_user_message full coverage (flag disabled delegation, list string/non-string items, string content, empty list, SystemPromptPart, RetryPromptPart, mixed messages)
    • ImportModelConfig integration (YAML resolution, profile overrides, TypeError)

Verification

  • ruff check: All checks passed ✓
  • ruff format --check: Formatted correctly ✓
  • mypy: Success, no issues found ✓
  • pytest: 25 passed, 0 failed ✓

Spec Reference

Implements: openspec/changes/openai-compatible-native-tool-return/tasks.md

Closes #112

Subclass OpenAIChatModel to emit native list tool return content
instead of JSON strings for OpenAI-compatible models (GLM-5, vLLM).

- OpenAICompatibleModel(OpenAIChatModel) with _map_user_message override
- Profile flag openai_chat_tool_return_as_list (default False)
- openai_* kwarg passthrough with string→bool coercion
- ImportModelConfig support with base_url, api_key, tool_return_as_list
- 25 tests covering all spec scenarios

Implements: openspec/changes/openai-compatible-native-tool-return/
@gemini-code-assist

Copy link
Copy Markdown

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@Million-mo
Million-mo requested a review from Leoyzen July 6, 2026 08:21
Move profile override validation before OpenAIProvider init so invalid
kwargs raise TypeError without requiring OPENAI_API_KEY credentials.

Fixes CI failure in test_import_model_config_non_openai_kwarg_raises.
@Million-mo
Million-mo merged commit 6be1507 into wolf1069b:feat/openai-compatible-native-tool-return Jul 6, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant