Repository navigation
refactor(py/anthropic)!: flat AnthropicConfig with exported Literals - #6700
Conversation
There was a problem hiding this comment.
Code Review
This pull request flattens the AnthropicConfig structure in the genkit-anthropic package, replacing previously nested configuration models (such as ThinkingConfig, OutputConfig, and RequestMetadata) with flat, top-level fields including thinking_budget, thinking_display, effort, task_budget, and user_id. The plugin now internally constructs the nested request objects for the Anthropic API from these flat fields. Additionally, migration validators have been introduced to provide clear error messages for deprecated nested keys, and all tests, samples, and documentation have been updated accordingly. I have no feedback to provide as there are no review comments.
|
Does "thinking" need to be exposed? Can it be inferred from the presence of |
AnthropicConfig no longer nests Anthropic's request objects. The plugin
builds them from flat fields:
- thinking (ThinkingMode: 'enabled' | 'adaptive' | 'disabled'),
thinking_budget and thinking_display (ThinkingDisplay) -> thinking
- effort (Effort: 'low' ... 'max') and task_budget -> output_config,
sent as {'effort': ..., 'task_budget': {'type': 'tokens', 'total': N}}
and merged with the structured-output format
- user_id -> metadata.user_id
Remove ThinkingConfig, OutputConfig, TaskBudget and RequestMetadata, and
the legacy enabled/adaptive bools. Export Effort, ThinkingMode and
ThinkingDisplay.
Rules: a thinking_budget alone means enabled; 'enabled' requires one;
'disabled' now rejects one (it was silently dropped); 'adaptive' accepts
and ignores it, as before. thinking_display with no mode now raises (it
was silently dropped).
The old nested keys (thinking={...}, output_config, metadata) raise
INVALID_ARGUMENT naming the flat replacement. extra={'thinking': ...}
and extra={'metadata': ...} still replace the built object;
output_config stays managed because it carries the structured-output
format.
Request bodies and anthropic-beta headers are byte-identical to main for
equivalent configs. task_budget still selects the beta API.
65ddad6 to
3dca646
Compare
Stack: 4/4 · previous #6699
AnthropicConfigis flat. Choices are exported Literals, and the plugin builds Anthropic's nestedthinking,output_configandmetadataobjects. For equivalent configs, request bodies andanthropic-betaheaders are byte-identical to main.Previously,
AnthropicConfignested four SDK-shaped classes,ThinkingConfig,OutputConfig,TaskBudgetandRequestMetadata, with three spellings of the thinking mode (enabled,adaptive,type). Some combinations were silently dropped: a budget with thinking disabled, or a display with no mode.Decisions
thinking(ThinkingMode),thinking_budget,thinking_display(ThinkingDisplay),effort(Effort),task_budgetanduser_id. They map tothinking,output_config(merged with the structured-output format) andmetadata.user_id.thinking=is the one spelling of the mode.'enabled'requires one.'adaptive'accepts and ignores a budget, as before.'disabled'with a budget, andthinking_displaywith no mode, now raise; main silently dropped both.extrastill replaces a built object, exceptoutput_config:extra={'thinking': {...}}orextra={'metadata': {...}}goes out whole.output_configstays a managed field, because replacing it would drop the structured-output format Genkit merges in.Breaking changes
ThinkingConfig,OutputConfig,TaskBudgetandRequestMetadata.thinking={...},output_config=andmetadata=raiseINVALID_ARGUMENTnaming the flat field. Theenabled/adaptivebools are gone.thinking='disabled'with a budget, andthinking_displaywith no mode, now raise.thinking_budgetmust be an integer;'adaptive'used to accept a fractional budget.thinking,output_configandmetadataobjects are replaced bythinking(enum),thinkingBudget,thinkingDisplay,effort,taskBudgetanduserId.Verification
packages/*/src, ty,generate_schema_typing --ci,uv lock --check: all clean. pyright, pyrefly and ty onpackages/*/tests/config_typing_test.py: 0 errors.anthropic-betaheaders and bodies are byte-identical;task_budgetstill selects the beta API with the default betas.AnthropicConfig, so it gets the same surface; its tests pass.