autogen_ext.tools.azure#
- pydantic model AzureAISearchConfig[source]#
Bases:
BaseModel
Configuration for Azure AI Search tool.
This class defines the configuration parameters for
AzureAISearchTool
. It provides options for customizing search behavior including query types, field selection, authentication, retry policies, and caching strategies.Note
This class requires the
azure
extra for theautogen-ext
package.pip install -U "autogen-ext[azure]"
Example
from azure.core.credentials import AzureKeyCredential from autogen_ext.tools.azure import AzureAISearchConfig config = AzureAISearchConfig( name="doc_search", endpoint="https://my-search.search.windows.net", index_name="my-index", credential=AzureKeyCredential("<your-key>"), query_type="vector", vector_fields=["embedding"], )
- For more details, see:
- Parameters:
name (str) – Name for the tool instance, used to identify it in the agent’s toolkit.
description (Optional[str]) – Human-readable description of what this tool does and how to use it.
endpoint (str) – The full URL of your Azure AI Search service, in the format ‘https://<service-name>.search.windows.net’.
index_name (str) – Name of the target search index in your Azure AI Search service. The index must be pre-created and properly configured.
api_version (str) – Azure AI Search REST API version to use. Defaults to ‘2023-11-01’. Only change if you need specific features from a different API version.
credential (Union[AzureKeyCredential, TokenCredential]) – Azure authentication credential: - AzureKeyCredential: For API key authentication (admin/query key) - TokenCredential: For Azure AD authentication (e.g., DefaultAzureCredential)
query_type (Literal["keyword", "fulltext", "vector", "hybrid"]) – The search query mode to use: - ‘keyword’: Basic keyword search (default) - ‘full’: Full Lucene query syntax - ‘vector’: Vector similarity search - ‘hybrid’: Hybrid search combining multiple techniques
search_fields (Optional[List[str]]) – List of index fields to search within. If not specified, searches all searchable fields. Example: [‘title’, ‘content’].
select_fields (Optional[List[str]]) – Fields to return in search results. If not specified, returns all fields. Use to optimize response size.
vector_fields (Optional[List[str]]) – Vector field names for vector search. Must be configured in your search index as vector fields. Required for vector search.
top (Optional[int]) – Maximum number of documents to return in search results. Helps control response size and processing time.
retry_enabled (bool) – Whether to enable retry policy for transient errors. Defaults to True.
retry_max_attempts (Optional[int]) – Maximum number of retry attempts for failed requests. Defaults to 3.
retry_mode (Literal["fixed", "exponential"]) – Retry backoff strategy: fixed or exponential. Defaults to “exponential”.
enable_caching (bool) – Whether to enable client-side caching of search results. Defaults to False.
cache_ttl_seconds (int) – Time-to-live for cached search results in seconds. Defaults to 300 (5 minutes).
filter (Optional[str]) – OData filter expression to refine search results.
Show JSON schema
{ "title": "AzureAISearchConfig", "description": "Configuration for Azure AI Search tool.\n\nThis class defines the configuration parameters for :class:`AzureAISearchTool`.\nIt provides options for customizing search behavior including query types,\nfield selection, authentication, retry policies, and caching strategies.\n\n.. note::\n\n This class requires the :code:`azure` extra for the :code:`autogen-ext` package.\n\n .. code-block:: bash\n\n pip install -U \"autogen-ext[azure]\"\n\nExample:\n .. code-block:: python\n\n from azure.core.credentials import AzureKeyCredential\n from autogen_ext.tools.azure import AzureAISearchConfig\n\n config = AzureAISearchConfig(\n name=\"doc_search\",\n endpoint=\"https://my-search.search.windows.net\",\n index_name=\"my-index\",\n credential=AzureKeyCredential(\"<your-key>\"),\n query_type=\"vector\",\n vector_fields=[\"embedding\"],\n )\n\nFor more details, see:\n * `Azure AI Search Overview <https://learn.microsoft.com/azure/search/search-what-is-azure-search>`_\n * `Vector Search <https://learn.microsoft.com/azure/search/vector-search-overview>`_\n\nArgs:\n name (str): Name for the tool instance, used to identify it in the agent's toolkit.\n description (Optional[str]): Human-readable description of what this tool does and how to use it.\n endpoint (str): The full URL of your Azure AI Search service, in the format\n 'https://<service-name>.search.windows.net'.\n index_name (str): Name of the target search index in your Azure AI Search service.\n The index must be pre-created and properly configured.\n api_version (str): Azure AI Search REST API version to use. Defaults to '2023-11-01'.\n Only change if you need specific features from a different API version.\n credential (Union[AzureKeyCredential, TokenCredential]): Azure authentication credential:\n - AzureKeyCredential: For API key authentication (admin/query key)\n - TokenCredential: For Azure AD authentication (e.g., DefaultAzureCredential)\n query_type (Literal[\"keyword\", \"fulltext\", \"vector\", \"hybrid\"]): The search query mode to use:\n - 'keyword': Basic keyword search (default)\n - 'full': Full Lucene query syntax\n - 'vector': Vector similarity search\n - 'hybrid': Hybrid search combining multiple techniques\n search_fields (Optional[List[str]]): List of index fields to search within. If not specified,\n searches all searchable fields. Example: ['title', 'content'].\n select_fields (Optional[List[str]]): Fields to return in search results. If not specified,\n returns all fields. Use to optimize response size.\n vector_fields (Optional[List[str]]): Vector field names for vector search. Must be configured\n in your search index as vector fields. Required for vector search.\n top (Optional[int]): Maximum number of documents to return in search results.\n Helps control response size and processing time.\n retry_enabled (bool): Whether to enable retry policy for transient errors. Defaults to True.\n retry_max_attempts (Optional[int]): Maximum number of retry attempts for failed requests. Defaults to 3.\n retry_mode (Literal[\"fixed\", \"exponential\"]): Retry backoff strategy: fixed or exponential. Defaults to \"exponential\".\n enable_caching (bool): Whether to enable client-side caching of search results. Defaults to False.\n cache_ttl_seconds (int): Time-to-live for cached search results in seconds. Defaults to 300 (5 minutes).\n filter (Optional[str]): OData filter expression to refine search results.", "type": "object", "properties": { "name": { "description": "The name of the tool", "title": "Name", "type": "string" }, "description": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "A description of the tool", "title": "Description" }, "endpoint": { "description": "The endpoint URL for your Azure AI Search service", "title": "Endpoint", "type": "string" }, "index_name": { "description": "The name of the search index to query", "title": "Index Name", "type": "string" }, "api_version": { "default": "2023-11-01", "description": "API version to use", "title": "Api Version", "type": "string" }, "credential": { "anyOf": [], "description": "The credential to use for authentication", "title": "Credential" }, "query_type": { "default": "keyword", "description": "Type of query to perform", "enum": [ "keyword", "fulltext", "vector", "hybrid" ], "title": "Query Type", "type": "string" }, "search_fields": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "description": "Optional list of fields to search in", "title": "Search Fields" }, "select_fields": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "description": "Optional list of fields to return in results", "title": "Select Fields" }, "vector_fields": { "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "type": "null" } ], "default": null, "description": "Optional list of vector fields for vector search", "title": "Vector Fields" }, "top": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "description": "Optional number of results to return", "title": "Top" }, "filter": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Optional OData filter expression to refine search results", "title": "Filter" }, "retry_enabled": { "default": true, "description": "Whether to enable retry policy for transient errors", "title": "Retry Enabled", "type": "boolean" }, "retry_max_attempts": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": 3, "description": "Maximum number of retry attempts for failed requests", "title": "Retry Max Attempts" }, "retry_mode": { "default": "exponential", "description": "Retry backoff strategy: fixed or exponential", "enum": [ "fixed", "exponential" ], "title": "Retry Mode", "type": "string" }, "enable_caching": { "default": false, "description": "Whether to enable client-side caching of search results", "title": "Enable Caching", "type": "boolean" }, "cache_ttl_seconds": { "default": 300, "description": "Time-to-live for cached search results in seconds", "title": "Cache Ttl Seconds", "type": "integer" }, "embedding_provider": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Name of embedding provider to use (e.g., 'azure_openai', 'openai')", "title": "Embedding Provider" }, "embedding_model": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "description": "Model name to use for generating embeddings", "title": "Embedding Model" }, "embedding_dimension": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": null, "description": "Dimension of embedding vectors produced by the model", "title": "Embedding Dimension" } }, "required": [ "name", "endpoint", "index_name", "credential" ] }
- Fields:
api_version (str)
cache_ttl_seconds (int)
credential (azure.core.credentials.AzureKeyCredential | azure.core.credentials.TokenCredential)
description (str | None)
embedding_dimension (int | None)
embedding_model (str | None)
embedding_provider (str | None)
enable_caching (bool)
endpoint (str)
filter (str | None)
index_name (str)
name (str)
query_type (Literal['keyword', 'fulltext', 'vector', 'hybrid'])
retry_enabled (bool)
retry_max_attempts (int | None)
retry_mode (Literal['fixed', 'exponential'])
search_fields (List[str] | None)
select_fields (List[str] | None)
top (int | None)
vector_fields (List[str] | None)
- field credential: AzureKeyCredential | TokenCredential [Required]#
The credential to use for authentication
- field embedding_provider: str | None = None#
Name of embedding provider to use (e.g., ‘azure_openai’, ‘openai’)
- field query_type: Literal['keyword', 'fulltext', 'vector', 'hybrid'] = 'keyword'#
Type of query to perform
- field retry_mode: Literal['fixed', 'exponential'] = 'exponential'#
Retry backoff strategy: fixed or exponential
- classmethod validate_credentials(data: Any) Any [source]#
Wrap a classmethod, staticmethod, property or unbound function and act as a descriptor that allows us to detect decorated items from the class’ attributes.
This class’ __get__ returns the wrapped item’s __get__ result, which makes it transparent for classmethods and staticmethods.
- wrapped#
The decorator that has to be wrapped.
- decorator_info#
The decorator info.
- shim#
A wrapper function to wrap V1 style function.
- class AzureAISearchTool(name: str, endpoint: str, index_name: str, credential: AzureKeyCredential | TokenCredential | Dict[str, str], query_type: Literal['keyword', 'fulltext', 'vector', 'hybrid'], search_fields: List[str] | None = None, select_fields: List[str] | None = None, vector_fields: List[str] | None = None, filter: str | None = None, top: int | None = 5, **kwargs: Any)[source]#
Bases:
BaseAzureAISearchTool
Azure AI Search tool for querying Azure search indexes.
This tool provides a simplified interface for querying Azure AI Search indexes using various search methods. The tool supports four main search types:
Keyword Search: Traditional text-based search using Azure’s text analysis
Full-Text Search: Enhanced text search with language-specific analyzers
Vector Search: Semantic similarity search using vector embeddings
Hybrid Search: Combines text and vector search for comprehensive results
You should use the factory methods to create instances for specific search types: - create_keyword_search() - create_full_text_search() - create_vector_search() - create_hybrid_search()
- classmethod create_full_text_search(name: str, endpoint: str, index_name: str, credential: AzureKeyCredential | TokenCredential | Dict[str, str], search_fields: List[str] | None = None, select_fields: List[str] | None = None, filter: str | None = None, top: int | None = 5, **kwargs: Any) AzureAISearchTool [source]#
Factory method to create a full-text search tool.
Full-text search uses advanced text analysis (stemming, lemmatization, etc.) to provide more comprehensive text matching than basic keyword search.
- Parameters:
name (str) – The name of the tool
endpoint (str) – The URL of your Azure AI Search service
index_name (str) – The name of the search index
credential (Union[AzureKeyCredential, TokenCredential, Dict[str, str]]) – Authentication credentials
search_fields (Optional[List[str]]) – Fields to search within
select_fields (Optional[List[str]]) – Fields to include in results
filter (Optional[str]) – OData filter expression to filter results
top (Optional[int]) – Maximum number of results to return
**kwargs (Any) – Additional configuration options
- Returns:
An initialized full-text search tool
- Example Usage:
# type: ignore # Example of using full-text search with Azure AI Search from autogen_ext.tools.azure import AzureAISearchTool from azure.core.credentials import AzureKeyCredential # Create a full-text search tool full_text_search = AzureAISearchTool.create_full_text_search( name="document_search", endpoint="https://your-search-service.search.windows.net", index_name="your-index", credential=AzureKeyCredential("your-api-key"), search_fields=["title", "content"], select_fields=["title", "content", "category", "url"], top=10, ) # The search tool can be used with an Agent # assistant = Agent("assistant", tools=[full_text_search])
- classmethod create_hybrid_search(name: str, endpoint: str, index_name: str, credential: AzureKeyCredential | TokenCredential | Dict[str, str], vector_fields: List[str], search_fields: List[str] | None = None, select_fields: List[str] | None = None, filter: str | None = None, top: int | None = 5, **kwargs: Any) AzureAISearchTool [source]#
Factory method to create a hybrid search tool.
Hybrid search combines text search (keyword or semantic) with vector similarity search to provide more comprehensive results.
This method doesn’t use a separate “hybrid” type but instead configures either a “keyword” or “semantic” text search and combines it with vector search.
- Parameters:
name (str) – The name of the tool
endpoint (str) – The URL of your Azure AI Search service
index_name (str) – The name of the search index
credential (Union[AzureKeyCredential, TokenCredential, Dict[str, str]]) – Authentication credentials
vector_fields (List[str]) – Fields containing vector embeddings for similarity search
search_fields (Optional[List[str]]) – Fields to search within for text search
select_fields (Optional[List[str]]) – Fields to include in results
filter (Optional[str]) – OData filter expression to filter results
top (Optional[int]) – Maximum number of results to return
**kwargs (Any) – Additional configuration options
- Returns:
An initialized hybrid search tool
- Example Usage:
# type: ignore # Example of using hybrid search with Azure AI Search from autogen_ext.tools.azure import AzureAISearchTool from azure.core.credentials import AzureKeyCredential # Create a hybrid search tool hybrid_search = AzureAISearchTool.create_hybrid_search( name="hybrid_search", endpoint="https://your-search-service.search.windows.net", index_name="your-index", credential=AzureKeyCredential("your-api-key"), vector_fields=["embedding_field"], search_fields=["title", "content"], select_fields=["title", "content", "url", "date"], top=10, ) # The search tool can be used with an Agent # assistant = Agent("researcher", tools=[hybrid_search])
- classmethod create_keyword_search(name: str, endpoint: str, index_name: str, credential: AzureKeyCredential | TokenCredential | Dict[str, str], search_fields: List[str] | None = None, select_fields: List[str] | None = None, filter: str | None = None, top: int | None = 5, **kwargs: Any) AzureAISearchTool [source]#
Factory method to create a keyword search tool.
Keyword search performs traditional text-based search, good for finding documents containing specific terms or exact matches to your query.
- Parameters:
name (str) – The name of the tool
endpoint (str) – The URL of your Azure AI Search service
index_name (str) – The name of the search index
credential (Union[AzureKeyCredential, TokenCredential, Dict[str, str]]) – Authentication credentials
search_fields (Optional[List[str]]) – Fields to search within for text search
select_fields (Optional[List[str]]) – Fields to include in results
filter (Optional[str]) – OData filter expression to filter results
top (Optional[int]) – Maximum number of results to return
**kwargs (Any) – Additional configuration options
- Returns:
An initialized keyword search tool
- Example Usage:
# type: ignore # Example of using keyword search with Azure AI Search from autogen_ext.tools.azure import AzureAISearchTool from azure.core.credentials import AzureKeyCredential # Create a keyword search tool keyword_search = AzureAISearchTool.create_keyword_search( name="keyword_search", endpoint="https://your-service.search.windows.net", index_name="your-index", credential=AzureKeyCredential("your-api-key"), search_fields=["title", "content"], select_fields=["id", "title", "content", "category"], top=10, ) # The search tool can be used with an Agent # assistant = Agent("assistant", tools=[keyword_search])
- classmethod create_vector_search(name: str, endpoint: str, index_name: str, credential: AzureKeyCredential | TokenCredential | Dict[str, str], vector_fields: List[str], select_fields: List[str] | None = None, filter: str | None = None, top: int | None = 5, **kwargs: Any) AzureAISearchTool [source]#
Factory method to create a vector search tool.
Vector search uses embedding vectors to find semantically similar content, enabling the discovery of related information even when different terminology is used.
- Parameters:
name (str) – The name of the tool
endpoint (str) – The URL of your Azure AI Search service
index_name (str) – The name of the search index
credential (Union[AzureKeyCredential, TokenCredential, Dict[str, str]]) – Authentication credentials
vector_fields (List[str]) – Fields containing vector embeddings for similarity search
select_fields (Optional[List[str]]) – Fields to include in results
filter (Optional[str]) – OData filter expression to filter results
top (Optional[int]) – Maximum number of results to return
**kwargs (Any) – Additional configuration options
- Returns:
An initialized vector search tool
- Example Usage:
# type: ignore # Example of using vector search with Azure AI Search from autogen_ext.tools.azure import AzureAISearchTool from azure.core.credentials import AzureKeyCredential # Create a vector search tool vector_search = AzureAISearchTool.create_vector_search( name="vector_search", endpoint="https://your-search-service.search.windows.net", index_name="your-index", credential=AzureKeyCredential("your-api-key"), vector_fields=["embedding"], select_fields=["title", "content", "url"], top=5, ) # The search tool can be used with an Agent # assistant = Agent("assistant", tools=[vector_search])
- classmethod load_component(model: ComponentModel | Dict[str, Any], expected: None = None) AzureAISearchTool [source]#
- classmethod load_component(model: ComponentModel | Dict[str, Any], expected: Type[ExpectedType]) ExpectedType
Load a component from a component model.
- Parameters:
model – The component model or dictionary with configuration
expected – Optional expected return type
- Returns:
An initialized AzureAISearchTool instance
- class BaseAzureAISearchTool(name: str, endpoint: str, index_name: str, credential: AzureKeyCredential | TokenCredential | Dict[str, str], description: str | None = None, api_version: str = '2023-11-01', query_type: Literal['keyword', 'fulltext', 'vector', 'hybrid'] = 'keyword', search_fields: List[str] | None = None, select_fields: List[str] | None = None, vector_fields: List[str] | None = None, top: int | None = None, filter: str | None = None, semantic_config_name: str | None = None, enable_caching: bool = False, cache_ttl_seconds: int = 300)[source]#
Bases:
BaseTool
[SearchQuery
,SearchResults
],ABC
Abstract base class for Azure AI Search tools.
This class defines the common interface and functionality for all Azure AI Search tools. It handles configuration management, client initialization, and the abstract methods that subclasses must implement.
- search_config#
Configuration parameters for the search service.
Note
This is an abstract base class and should not be instantiated directly. Use concrete implementations or the factory methods in AzureAISearchTool.
- dump_component() ComponentModel [source]#
Serialize the tool to a component model.
- Returns:
ComponentModel – A serialized representation of the tool
- classmethod load_component(model: ComponentModel | Dict[str, Any], expected: None = None) BaseAzureAISearchTool [source]#
- classmethod load_component(model: ComponentModel | Dict[str, Any], expected: Type[ExpectedType]) ExpectedType
Load the tool from a component model.
- Parameters:
model (Union[ComponentModel, Dict[str, Any]]) – The component configuration.
expected (Optional[Type[ExpectedType]]) – Optional component class for deserialization.
- Returns:
Union[BaseAzureAISearchTool, ExpectedType] – An instance of the tool.
- Raises:
ValueError – If the component configuration is invalid.
- return_value_as_string(value: SearchResults) str [source]#
Convert the search results to a string representation.
This method is used to format the search results in a way that’s suitable for display to the user or for consumption by language models.
- Parameters:
value (List[SearchResult]) – The search results to convert.
- Returns:
str – A formatted string representation of the search results.
- async run(args: str | Dict[str, Any] | SearchQuery, cancellation_token: CancellationToken | None = None) SearchResults [source]#
Execute a search against the Azure AI Search index.
- Parameters:
args – Search query text or SearchQuery object
cancellation_token – Optional token to cancel the operation
- Returns:
Search results
- property schema: ToolSchema#
Return the schema for the tool.
- pydantic model SearchQuery[source]#
Bases:
BaseModel
Search query parameters.
This simplified interface only requires a search query string. All other parameters (top, filters, vector fields, etc.) are specified during tool creation rather than at query time, making it easier for language models to generate structured output.
- Parameters:
query (str) – The search query text.
Show JSON schema
{ "title": "SearchQuery", "description": "Search query parameters.\n\nThis simplified interface only requires a search query string.\nAll other parameters (top, filters, vector fields, etc.) are specified during tool creation\nrather than at query time, making it easier for language models to generate structured output.\n\nArgs:\n query (str): The search query text.", "type": "object", "properties": { "query": { "description": "Search query text", "title": "Query", "type": "string" } }, "required": [ "query" ] }
- Fields:
query (str)
- pydantic model SearchResult[source]#
Bases:
BaseModel
Search result.
- Parameters:
Show JSON schema
{ "title": "SearchResult", "description": "Search result.\n\nArgs:\n score (float): The search score.\n content (Dict[str, Any]): The document content.\n metadata (Dict[str, Any]): Additional metadata about the document.", "type": "object", "properties": { "score": { "description": "The search score", "title": "Score", "type": "number" }, "content": { "description": "The document content", "title": "Content", "type": "object" }, "metadata": { "description": "Additional metadata about the document", "title": "Metadata", "type": "object" } }, "required": [ "score", "content", "metadata" ] }
- Fields:
content (Dict[str, Any])
metadata (Dict[str, Any])
score (float)
- pydantic model SearchResults[source]#
Bases:
BaseModel
Container for search results.
- Parameters:
results (List[SearchResult]) – List of search results.
Show JSON schema
{ "title": "SearchResults", "description": "Container for search results.\n\nArgs:\n results (List[SearchResult]): List of search results.", "type": "object", "properties": { "results": { "description": "List of search results", "items": { "$ref": "#/$defs/SearchResult" }, "title": "Results", "type": "array" } }, "$defs": { "SearchResult": { "description": "Search result.\n\nArgs:\n score (float): The search score.\n content (Dict[str, Any]): The document content.\n metadata (Dict[str, Any]): Additional metadata about the document.", "properties": { "score": { "description": "The search score", "title": "Score", "type": "number" }, "content": { "description": "The document content", "title": "Content", "type": "object" }, "metadata": { "description": "Additional metadata about the document", "title": "Metadata", "type": "object" } }, "required": [ "score", "content", "metadata" ], "title": "SearchResult", "type": "object" } }, "required": [ "results" ] }
- Fields:
results (List[autogen_ext.tools.azure._ai_search.SearchResult])
- field results: List[SearchResult] [Required]#
List of search results