Skip to content

Commit c144b53

Browse files
thiagosalvatorecopybara-github
authored andcommitted
fix: Add support for required params
Merge #2212 This PR closes issue #2202 ADK was not parsing the required attribute when using LiteLLM, letting the LLM decide what is required vs not, not respecting function definitions. ## Test Plan There's a fork of adk-python that is being running live for over 2 weeks in our production environment with millions of requests per day. Below you can find a screenshot of the unit tests passing. I've also added one change to the test cases to cover this scenario <img width="1904" height="483" alt="image" src="https://github.com/user-attachments/assets/5a6eb069-63ae-45a3-baca-6b01543f56fb" /> COPYBARA_INTEGRATE_REVIEW=#2212 from thiagosalvatore:main 7de4037 PiperOrigin-RevId: 797393698
1 parent 5b999ed commit c144b53

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/google/adk/models/lite_llm.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def _function_declaration_to_tool_param(
380380
for key, value in function_declaration.parameters.properties.items():
381381
properties[key] = _schema_to_dict(value)
382382

383-
return {
383+
tool_params = {
384384
"type": "function",
385385
"function": {
386386
"name": function_declaration.name,
@@ -392,6 +392,13 @@ def _function_declaration_to_tool_param(
392392
},
393393
}
394394

395+
if function_declaration.parameters.required:
396+
tool_params["function"]["parameters"][
397+
"required"
398+
] = function_declaration.parameters.required
399+
400+
return tool_params
401+
395402

396403
def _model_response_to_chunk(
397404
response: ModelResponse,

tests/unittests/models/test_litellm.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,10 @@ def test_maybe_append_user_content(
558558
"nested_key1": types.Schema(type=types.Type.STRING),
559559
"nested_key2": types.Schema(type=types.Type.STRING),
560560
},
561+
required=["nested_key1"],
561562
),
562563
},
564+
required=["nested_arg"],
563565
),
564566
),
565567
{
@@ -581,8 +583,10 @@ def test_maybe_append_user_content(
581583
"nested_key2": {"type": "string"},
582584
},
583585
"type": "object",
586+
"required": ["nested_key1"],
584587
},
585588
},
589+
"required": ["nested_arg"],
586590
},
587591
},
588592
},

0 commit comments

Comments
 (0)