feat: support all model providers in JSON agent configuration#2109
feat: support all model providers in JSON agent configuration#2109
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
Assessment: Comment Solid implementation that extends the experimental JSON agent configuration to support all 12 SDK model providers with backward compatibility. The main areas for improvement are reducing code duplication in the provider factory functions and replacing the fragile Review Categories
Good backward compatibility preservation, thorough test coverage, and clean lazy-import pattern across all providers. |
142bcb1 to
e3c44bf
Compare
- Fix **kwargs type annotation (dict[str, Any] -> Any) in config_to_agent - Add defensive copy in all from_dict methods to avoid mutating caller's dict - Raise ValueError on unsupported config keys in SageMaker from_dict - Improve _create_model_from_dict return type to Model - Document env var pattern full-string-only matching
|
Assessment: Comment The rework since the last review is excellent — all 6 prior issues have been addressed. Moving factory logic to Review Details
Clean architecture, solid backward compatibility, and thorough test coverage overall. |
|
/strands address the open comments |
- Remove env var resolution per maintainer request (Unshure) - Move from_dict tests to respective model test files per project test mirroring convention (test_bedrock, test_ollama, test_mistral, test_llamacpp, test_sagemaker, test_model) - Add missing test for SageMaker unexpected config keys rejection - Remove dead code (unused BedrockModel import/patch block) - Fix test mocking to avoid triggering lazy imports of optional deps - Fix mypy type annotation on _create_model_from_dict return type
| "openai_responses", | ||
| ] | ||
|
|
||
| def test_all_providers_registered(self): |
There was a problem hiding this comment.
Let's remove this test, it doesn't add much value
There was a problem hiding this comment.
Removed TestProviderMap entirely. The parametrized test_all_providers_dispatch already covers dispatch correctness for every provider.
| # Should not raise | ||
| config_to_agent(config) | ||
|
|
||
| def test_null_model_still_valid(self): |
There was a problem hiding this comment.
Is this already tested elsewhere? Can you also check and make sure there aren't duplicated tests?
There was a problem hiding this comment.
Checked — test_null_model_still_valid is unique (tests model: null specifically), while test_config_to_agent_ignores_none_values tests prompt: null, name: null with a valid string model. Kept it. Also removed two actual duplicates: test_string_model_backward_compat (same as test_string_model_valid) and test_unknown_provider_error_message (same as test_unknown_provider_raises).
|
/strands |
- Remove TestProviderMap class (test_all_providers_dispatch already covers all provider dispatch correctness) - Remove test_string_model_backward_compat (duplicate of test_string_model_valid) - Remove test_unknown_provider_error_message (duplicate of test_unknown_provider_raises)
Motivation
The experimental
agent_config.pyfeature currently only accepts a simple string for themodelfield, which is always interpreted as a Bedrockmodel_id. This limits JSON-based agent configuration to a single provider, preventing use cases like agent-builder tools and theuse_agenttool from working with any of the SDK's 12 model providers.Resolves #1064
Public API Changes
The
modelfield in agent JSON configuration now supports two formats:All 12 SDK providers are supported:
bedrock,anthropic,openai,gemini,ollama,litellm,mistral,llamaapi,llamacpp,sagemaker,writer,openai_responses. Each provider's constructor parameters are correctly routed — for example,boto_client_configdicts are converted toBotocoreConfigobjects for Bedrock/SageMaker, Ollama'sclient_argsmaps toollama_client_args, and Mistral'sapi_keyis extracted as a separate parameter.The factory logic is co-located with each provider via
from_dictclassmethods: the baseModel.from_dicthandles the commonclient_args+**model_configpattern (used by 7 providers), while Bedrock, Ollama, Mistral, LlamaCpp, and SageMaker override it for their non-standard constructors.agent_config.pyis a thin orchestration layer that validates the schema, resolves the provider class viastrands.modelslazy__getattr__, and delegates tofrom_dict.All provider imports are lazy to avoid requiring optional dependencies that aren't installed. Non-serializable parameters (
boto_session,client,gemini_tools) cannot be specified from JSON and are documented as such.Use Cases