44
55import json
66import logging
7- from typing import Annotated , Any , cast
7+ from typing import Annotated , Any , Optional , cast
88
99from fastapi import APIRouter , Depends , Request
1010from llama_stack .apis .agents .openai_responses import (
7474
7575def _build_tool_call_summary ( # pylint: disable=too-many-return-statements,too-many-branches
7676 output_item : Any ,
77- ) -> tuple [ToolCallSummary | None , ToolResultSummary | None ]:
77+ ) -> tuple [Optional [ ToolCallSummary ], Optional [ ToolResultSummary ] ]:
7878 """Translate applicable Responses API tool outputs into ``ToolCallSummary`` records.
7979
8080 The OpenAI ``response.output`` array may contain any ``OpenAIResponseOutput`` variant:
@@ -110,7 +110,7 @@ def _build_tool_call_summary( # pylint: disable=too-many-return-statements,too-
110110 "status" : getattr (output_item , "status" , None ),
111111 }
112112 results = getattr (output_item , "results" , None )
113- response_payload : Any | None = None
113+ response_payload : Optional [ Any ] = None
114114 if results is not None :
115115 # Store only the essential result metadata to avoid large payloads
116116 response_payload = {
@@ -294,7 +294,7 @@ async def retrieve_response( # pylint: disable=too-many-locals,too-many-branche
294294 model_id : str ,
295295 query_request : QueryRequest ,
296296 token : str ,
297- mcp_headers : dict [str , dict [str , str ]] | None = None ,
297+ mcp_headers : Optional [ dict [str , dict [str , str ]]] = None ,
298298 * ,
299299 provider_id : str = "" ,
300300) -> tuple [TurnSummary , str , list [ReferencedDocument ], TokenCounter ]:
@@ -505,7 +505,7 @@ def parse_referenced_documents_from_responses_api(
505505 """
506506 documents : list [ReferencedDocument ] = []
507507 # Use a set to track unique documents by (doc_url, doc_title) tuple
508- seen_docs : set [tuple [str | None , str | None ]] = set ()
508+ seen_docs : set [tuple [Optional [ str ], Optional [ str ] ]] = set ()
509509
510510 if not response .output :
511511 return documents
@@ -535,7 +535,7 @@ def parse_referenced_documents_from_responses_api(
535535
536536 # If we have at least a filename or url
537537 if filename or doc_url :
538- # Treat empty string as None for URL to satisfy AnyUrl | None
538+ # Treat empty string as None for URL to satisfy Optional[ AnyUrl]
539539 final_url = doc_url if doc_url else None
540540 if (final_url , filename ) not in seen_docs :
541541 documents .append (
@@ -692,15 +692,15 @@ def _increment_llm_call_metric(provider: str, model: str) -> None:
692692 logger .warning ("Failed to update LLM call metric: %s" , e )
693693
694694
695- def get_rag_tools (vector_store_ids : list [str ]) -> list [dict [str , Any ]] | None :
695+ def get_rag_tools (vector_store_ids : list [str ]) -> Optional [ list [dict [str , Any ]]] :
696696 """
697697 Convert vector store IDs to tools format for Responses API.
698698
699699 Args:
700700 vector_store_ids: List of vector store identifiers
701701
702702 Returns:
703- list[dict[str, Any]] | None : List containing file_search tool configuration,
703+ Optional[ list[dict[str, Any]]] : List containing file_search tool configuration,
704704 or None if no vector stores provided
705705 """
706706 if not vector_store_ids :
@@ -717,8 +717,8 @@ def get_rag_tools(vector_store_ids: list[str]) -> list[dict[str, Any]] | None:
717717
718718def get_mcp_tools (
719719 mcp_servers : list ,
720- token : str | None = None ,
721- mcp_headers : dict [str , dict [str , str ]] | None = None ,
720+ token : Optional [ str ] = None ,
721+ mcp_headers : Optional [ dict [str , dict [str , str ]]] = None ,
722722) -> list [dict [str , Any ]]:
723723 """
724724 Convert MCP servers to tools format for Responses API.
@@ -762,8 +762,8 @@ async def prepare_tools_for_responses_api(
762762 query_request : QueryRequest ,
763763 token : str ,
764764 config : AppConfig ,
765- mcp_headers : dict [str , dict [str , str ]] | None = None ,
766- ) -> list [dict [str , Any ]] | None :
765+ mcp_headers : Optional [ dict [str , dict [str , str ]]] = None ,
766+ ) -> Optional [ list [dict [str , Any ]]] :
767767 """
768768 Prepare tools for Responses API including RAG and MCP tools.
769769
@@ -778,7 +778,7 @@ async def prepare_tools_for_responses_api(
778778 mcp_headers: Per-request headers for MCP servers
779779
780780 Returns:
781- list[dict[str, Any]] | None : List of tool configurations for the
781+ Optional[ list[dict[str, Any]]] : List of tool configurations for the
782782 Responses API, or None if no_tools is True or no tools are available
783783 """
784784 if query_request .no_tools :
0 commit comments