dynamic_choices - #19
Conversation
- Remove dead `| JSONResponse` union from `get_dynamic_choices` return type (endpoint never returns JSONResponse, only raises HTTPException or returns dict) - Drop unused `mocker: Any` params from all five dynamic_choices route tests - Strengthen `test_dynamic_choices_endpoint_multiple_keys` to assert values, not just key presence - Rename two misleading test_agent.py tests: `non_choice_field` → `optional_choice_field`, `returns_empty` → `dispatches_by_method_name` Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Review Summary by QodoAdd dynamic choices support for AgentMethodField with runtime callback resolution
WalkthroughsDescription• Add dynamic_choices attribute to AgentMethodField for runtime-resolved choice options • Implement dynamic_choices_callback on Agent to provide choices via callback function • Create GET /start/dynamic_choices endpoint to fetch dynamic choices at runtime • Wire callback into example controller template with sample implementation • Add 18 comprehensive unit tests covering field validation, serialization, endpoint behavior, and edge cases • Refactor code: remove dead return-type union, drop unused params, strengthen assertions, rename misleading tests • Update changelog and documentation with dynamic choices feature and setup guide Diagramflowchart LR
A["AgentMethodField<br/>dynamic_choices: str"] -->|key name| B["Agent<br/>dynamic_choices_callback"]
B -->|invoked with method_name| C["Callback Function<br/>returns dict of choices"]
C -->|returns| D["GET /start/dynamic_choices<br/>endpoint"]
D -->|fetches at runtime| E["Supervaize Studio<br/>renders form with choices"]
File Changes1. src/supervaizer/agent.py
|
Code Review by Qodo
1.
|
What did
Added dynamic support for AgentMethodField and wired a get_dynamic_choices callback into Agent- Implemented a new //dynamic_choices HTTP endpoint and integrated it into the example controller template- Added comprehensive unit tests covering serialization, endpoint behavior, multiple-key assertions, and runtime behavior- Refactored agent.py and dynamic_choices routes/tests: removed dead return-type union, dropped unused params, strengthened assertions, and renamed tests- Updated changelog and docs with the dynamic choices feature and link
Why
To support runtime-populated choice fields for agent methods, enabling UI/components to fetch up-to-date options from the agent at start time.
How
tested- tests verifying:
-_choices field serialization in fieldsinitions - get_dynamic_choices endpoint behavior and returned values (including multi-key cases)