@@ -205,7 +205,17 @@ def get_system_prompt(query_request: QueryRequest, config: AppConfig) -> str:
205205
206206
207207def get_topic_summary_system_prompt (config : AppConfig ) -> str :
208- """Get the topic summary system prompt."""
208+ """
209+ Get the topic summary system prompt.
210+
211+ Parameters:
212+ config (AppConfig): Application configuration from which to read
213+ customization/profile settings.
214+
215+ Returns:
216+ str: The topic summary system prompt from the active custom profile if
217+ set, otherwise the default prompt.
218+ """
209219 # profile takes precedence for setting prompt
210220 if (
211221 config .customization is not None
@@ -223,8 +233,9 @@ def validate_model_provider_override(
223233) -> None :
224234 """Validate whether model/provider overrides are allowed by RBAC.
225235
226- Raises HTTP 403 if the request includes model or provider and the caller
227- lacks Action.MODEL_OVERRIDE permission.
236+ Raises:
237+ HTTPException: HTTP 403 if the request includes model or provider and
238+ the caller lacks Action.MODEL_OVERRIDE permission.
228239 """
229240 if (query_request .model is not None or query_request .provider is not None ) and (
230241 Action .MODEL_OVERRIDE not in authorized_actions
@@ -242,7 +253,24 @@ def store_conversation_into_cache(
242253 _skip_userid_check : bool ,
243254 topic_summary : str | None ,
244255) -> None :
245- """Store one part of conversation into conversation history cache."""
256+ """
257+ Store one part of conversation into conversation history cache.
258+
259+ If a conversation cache type is configured but the cache instance is not
260+ initialized, the function logs a warning and returns without persisting
261+ anything.
262+
263+ Parameters:
264+ config (AppConfig): Application configuration that may contain
265+ conversation cache settings and instance.
266+ user_id (str): Owner identifier used as the cache key.
267+ conversation_id (str): Conversation identifier used as the cache key.
268+ cache_entry (CacheEntry): Entry to insert or append to the conversation history.
269+ _skip_userid_check (bool): When true, bypasses enforcing that the cache
270+ operation must match the user id.
271+ topic_summary (str | None): Optional topic summary to store alongside
272+ the conversation; ignored if None or empty.
273+ """
246274 if config .conversation_cache_configuration .type is not None :
247275 cache = config .conversation_cache
248276 if cache is None :
@@ -366,10 +394,12 @@ async def get_temp_agent(
366394 This function creates a new agent without persistence, shields, or tools.
367395 Useful for temporary operations or one-off queries, such as validating a
368396 question or generating a summary.
369- Args:
397+
398+ Parameters:
370399 client: The AsyncLlamaStackClient to use for the request.
371400 model_id: The ID of the model to use.
372401 system_prompt: The system prompt/instructions for the agent.
402+
373403 Returns:
374404 tuple[AsyncAgent, str]: A tuple containing the agent and session_id.
375405 """
@@ -412,7 +442,23 @@ def create_rag_chunks_dict(summary: TurnSummary) -> list[dict[str, Any]]:
412442def _process_http_source (
413443 src : str , doc_urls : set [str ]
414444) -> tuple [AnyUrl | None , str ] | None :
415- """Process HTTP source and return (doc_url, doc_title) tuple."""
445+ """
446+ Process HTTP source and return (doc_url, doc_title) tuple.
447+
448+ Parameters:
449+ src (str): The source URL string to process.
450+ doc_urls (set[str]): Set of already-seen source strings; the function
451+ will add `src` to this set when it is new.
452+
453+ Returns:
454+ tuple[AnyUrl | None, str] | None: A tuple (validated_url, doc_title)
455+ when `src` was not previously seen:
456+ - `validated_url`: an `AnyUrl` instance if `src` is a valid URL, or
457+ `None` if validation failed.
458+ - `doc_title`: the last path segment of the URL or `src` if no path
459+ segment is present.
460+ Returns `None` if `src` was already present in `doc_urls`.
461+ """
416462 if src not in doc_urls :
417463 doc_urls .add (src )
418464 try :
@@ -433,7 +479,29 @@ def _process_document_id(
433479 metas_by_id : dict [str , dict [str , Any ]],
434480 metadata_map : dict [str , Any ] | None ,
435481) -> tuple [AnyUrl | None , str ] | None :
436- """Process document ID and return (doc_url, doc_title) tuple."""
482+ """
483+ Process document ID and return (doc_url, doc_title) tuple.
484+
485+ Parameters:
486+ src (str): Document identifier to process.
487+ doc_ids (set[str]): Set of already-seen document IDs; the function adds `src` to this set.
488+ doc_urls (set[str]): Set of already-seen document URLs; the function
489+ adds discovered URLs to this set to avoid duplicates.
490+ metas_by_id (dict[str, dict[str, Any]]): Mapping of document IDs to
491+ metadata dicts that may
492+ contain `docs_url` and
493+ `title`.
494+ metadata_map (dict[str, Any] | None): If provided (truthy), indicates
495+ metadata is available and enables
496+ metadata lookup; when falsy,
497+ metadata lookup is skipped.
498+
499+ Returns:
500+ tuple[AnyUrl | None, str] | None: `(validated_url, doc_title)` where
501+ `validated_url` is a validated `AnyUrl` or `None` and `doc_title` is
502+ the chosen title string; returns `None` if the `src` or its URL was
503+ already processed.
504+ """
437505 if src in doc_ids :
438506 return None
439507 doc_ids .add (src )
@@ -500,6 +568,17 @@ def _process_rag_chunks_for_documents(
500568 Process RAG chunks and return a list of (doc_url, doc_title) tuples.
501569
502570 This is the core logic shared between both return formats.
571+
572+ Parameters:
573+ rag_chunks (list): Iterable of RAG chunk objects; each chunk must
574+ provide a `source` attribute (e.g., an HTTP URL or a document ID).
575+ metadata_map (dict[str, Any] | None): Optional mapping of document IDs
576+ to metadata dictionaries used to resolve titles and document URLs.
577+
578+ Returns:
579+ list[tuple[AnyUrl | None, str]]: Ordered list of tuples where the first
580+ element is a validated URL object or `None` (if no URL is available)
581+ and the second element is the document title.
503582 """
504583 doc_urls : set [str ] = set ()
505584 doc_ids : set [str ] = set ()
@@ -547,7 +626,7 @@ def create_referenced_documents(
547626 optional metadata enrichment, deduplication, and proper URL handling. It can return
548627 either ReferencedDocument objects (for query endpoint) or dictionaries (for streaming).
549628
550- Args :
629+ Parameters :
551630 rag_chunks: List of RAG chunks with source information
552631 metadata_map: Optional mapping containing metadata about referenced documents
553632 return_dict_format: If True, returns list of dicts; if False, returns list of
@@ -580,6 +659,16 @@ def create_referenced_documents_with_metadata(
580659 Create referenced documents from RAG chunks with metadata enrichment for streaming.
581660
582661 This function now returns ReferencedDocument objects for consistency with the query endpoint.
662+
663+ Parameters:
664+ summary (TurnSummary): Summary object containing `rag_chunks` to be processed.
665+ metadata_map (dict[str, Any]): Metadata keyed by document id used to
666+ derive or enrich document `doc_url` and `doc_title`.
667+
668+ Returns:
669+ list[ReferencedDocument]: ReferencedDocument objects with `doc_url` and
670+ `doc_title` populated; `doc_url` may be `None` if no valid URL could be
671+ determined.
583672 """
584673 document_entries = _process_rag_chunks_for_documents (
585674 summary .rag_chunks , metadata_map
@@ -598,6 +687,14 @@ def create_referenced_documents_from_chunks(
598687
599688 This is a backward compatibility wrapper around the unified
600689 create_referenced_documents function.
690+
691+ Parameters:
692+ rag_chunks (list): List of RAG chunk entries containing source and metadata information.
693+
694+ Returns:
695+ list[ReferencedDocument]: ReferencedDocument instances created from the
696+ chunks; each contains `doc_url` (validated URL or `None`) and
697+ `doc_title`.
601698 """
602699 document_entries = _process_rag_chunks_for_documents (rag_chunks )
603700 return [
0 commit comments