From 8a5ea5725311e2bf37c37599ab8ff5fd8cf54a13 Mon Sep 17 00:00:00 2001 From: Ben Browning Date: Thu, 12 Jun 2025 07:05:58 -0400 Subject: [PATCH] Responses file_search wire up additional params This adds passing of max_num_results from the file_search tool call into the knowledge_search tool, as well as logs warnings if the filters or ranking_options params are used since those are not wired up yet. And, it adds the API surface for filters and ranking options so we don't have to generate clients again as we add that. Signed-off-by: Ben Browning --- docs/_static/llama-stack-spec.html | 29 +++++++++++++++++++ docs/_static/llama-stack-spec.yaml | 13 +++++++++ llama_stack/apis/agents/openai_responses.py | 3 +- .../agents/meta_reference/openai_responses.py | 10 ++++++- 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/docs/_static/llama-stack-spec.html b/docs/_static/llama-stack-spec.html index 98e959780..ce47f8ebb 100644 --- a/docs/_static/llama-stack-spec.html +++ b/docs/_static/llama-stack-spec.html @@ -7255,6 +7255,35 @@ "type": "string" } }, + "filters": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "type": "null" + }, + { + "type": "boolean" + }, + { + "type": "number" + }, + { + "type": "string" + }, + { + "type": "array" + }, + { + "type": "object" + } + ] + } + }, + "max_num_results": { + "type": "integer", + "default": 10 + }, "ranking_options": { "type": "object", "properties": { diff --git a/docs/_static/llama-stack-spec.yaml b/docs/_static/llama-stack-spec.yaml index b31f6bbb0..07a176b32 100644 --- a/docs/_static/llama-stack-spec.yaml +++ b/docs/_static/llama-stack-spec.yaml @@ -5157,6 +5157,19 @@ components: type: array items: type: string + filters: + type: object + additionalProperties: + oneOf: + - type: 'null' + - type: boolean + - type: number + - type: string + - type: array + - type: object + max_num_results: + type: integer + default: 10 ranking_options: type: object properties: diff --git a/llama_stack/apis/agents/openai_responses.py b/llama_stack/apis/agents/openai_responses.py index bdd9c3e26..2e1cb257a 100644 --- a/llama_stack/apis/agents/openai_responses.py +++ b/llama_stack/apis/agents/openai_responses.py @@ -409,8 +409,9 @@ class FileSearchRankingOptions(BaseModel): class OpenAIResponseInputToolFileSearch(BaseModel): type: Literal["file_search"] = "file_search" vector_store_ids: list[str] + filters: dict[str, Any] | None = None + max_num_results: int | None = Field(default=10, ge=1, le=50) ranking_options: FileSearchRankingOptions | None = None - # TODO: add filters, max_num_results class ApprovalFilter(BaseModel): diff --git a/llama_stack/providers/inline/agents/meta_reference/openai_responses.py b/llama_stack/providers/inline/agents/meta_reference/openai_responses.py index 963dd1ddd..33fcbfa5d 100644 --- a/llama_stack/providers/inline/agents/meta_reference/openai_responses.py +++ b/llama_stack/providers/inline/agents/meta_reference/openai_responses.py @@ -64,7 +64,7 @@ from llama_stack.apis.inference.inference import ( OpenAIToolMessageParam, OpenAIUserMessageParam, ) -from llama_stack.apis.tools.tools import ToolGroups, ToolRuntime +from llama_stack.apis.tools import RAGQueryConfig, ToolGroups, ToolRuntime from llama_stack.log import get_logger from llama_stack.models.llama.datatypes import ToolDefinition, ToolParamDefinition from llama_stack.providers.utils.inference.openai_compat import convert_tooldef_to_openai_tool @@ -699,7 +699,15 @@ class OpenAIResponsesImpl: t for t in ctx.response_tools if isinstance(t, OpenAIResponseInputToolFileSearch) ) if response_file_search_tool: + if response_file_search_tool.filters: + logger.warning("Filters are not yet supported for file_search tool") + if response_file_search_tool.ranking_options: + logger.warning("Ranking options are not yet supported for file_search tool") tool_kwargs["vector_db_ids"] = response_file_search_tool.vector_store_ids + tool_kwargs["query_config"] = RAGQueryConfig( + mode="vector", + max_chunks=response_file_search_tool.max_num_results, + ) result = await self.tool_runtime_api.invoke_tool( tool_name=function.name, kwargs=tool_kwargs,