[4643] fix(sdk): Support tool_choice in prompt templates#4707
[4643] fix(sdk): Support tool_choice in prompt templates#4707fintech07 wants to merge 2 commits into
Conversation
|
@fintech07 is attempting to deploy a commit to the agenta projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughSummary by CodeRabbit
WalkthroughIntroduces structured Pydantic models ( ChangesStructured ToolChoice types and serialization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
✅ Thanks @fintech07! This PR now meets the contribution requirements and has been reopened. A maintainer will review it soon. |
Summary
Refs #4643.
This PR adds SDK support for OpenAI-compatible
tool_choicevalues in Agenta prompt templates. Prompt configs can now use"required", named function choices, and allowed-tools choices, and those structured values are serialized back to plain dictionaries before they are forwarded to LiteLLM/OpenAI.Before this change, the SDK accepted
"none","auto", or arbitrary dictionaries. That meant"required"was rejected even though it is part of OpenAI's Chat Completionstool_choiceschema.Changes
The SDK now accepts these
tool_choiceshapes in prompt template model configs:The existing behavior is preserved where
tool_choiceis only sent to the provider whentoolsare present.Provider behavior note: OpenAI-compatible providers may support different subsets of
tool_choice. This PR keeps the SDK schema aligned with OpenAI and leaves unsupported model/provider combinations to fail at the provider or LiteLLM layer instead of adding Agenta-specific provider validation.Demo
SDK-only terminal verification:
Testing
"required", named function choices, allowed-tools choices, omission withouttools, and invalid string values.pipx run uv run pytest oss/tests/pytest/unit/test_prompt_template_extensions.py -vpipx run uv run pytest oss/tests/pytest/unit/ -vpipx run uv run --with ruff ruff format agenta/sdk/utils/types.py oss/tests/pytest/unit/test_prompt_template_extensions.pypipx run uv run --with ruff ruff check --fix agenta/sdk/utils/types.py oss/tests/pytest/unit/test_prompt_template_extensions.pyQA
No manual UI QA needed. This is covered by SDK unit tests.