Skip to content

tool_resources missing filtered search tool during run creation using AzureAISearchTool with filter expression #41939

Open
@Deep0596

Description

@Deep0596
  • Package Name: azure-ai-agents
  • Package Version: 1.0.2
  • Operating System: Windows
  • Python Version: 3.10

Describe the bug
When using the AzureAISearchTool with a filter query such as:
filter_query="people/any(p: p eq 'Arlyn Haining')"
the tool_resources generated correctly (as shown in print statements), but the value becomes empty when passed to the run.create() API.

Expected Behavior
The tool_resources with the applied filter should persist and be available during the agent run. It should appear in the run.tool_resources property.

Code Sample

from typing import Optional
import time
import uuid
from datetime import datetime
import re
import os
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from azure.ai.agents.models import AzureAISearchTool, AzureAISearchQueryType
from Agent.project_client import project_client, azure_ai_conn_id
from azure.ai.agents.models import (
    TruncationObject,
    TruncationStrategy,
    AISearchIndexResource
)



def wait_for_run_completion(project_client, thread_id, run_id, timeout=30):
    start_time = time.time()
    while True:
        run_status = project_client.agents.runs.get(thread_id=thread_id, run_id=run_id)
        print(run_status)
        if run_status.status in ["completed", "failed"]:
            return run_status
        if time.time() - start_time > timeout:
            raise TimeoutError("Agent run did not complete in expected time.")
        
def get_filtered_tool(filter_query: str, index_name: str, conn_id: str) -> AzureAISearchTool:
    return AzureAISearchTool(
                index_connection_id=conn_id,
                index_name=index_name,
                query_type=AzureAISearchQueryType.VECTOR_SEMANTIC_HYBRID,
                top_k=50,
                filter=filter_query
    )


search_tool = get_filtered_tool(
    filter_query="people/any(p: p eq 'Arlyn Haining')",
    index_name="mom-test-index",           # your actual index name
    conn_id=azure_ai_conn_id               # comes from your project_client.py
)

print(search_tool.resources)
print(search_tool)

def chat_with_agent(question):
    try:
        agent_id = "asst_FqSlIS6pwJaqEBSz5tZbuQxp"
        thread_id = None
        thread_id = project_client.agents.threads.create().id
        print(project_client.agents.threads.get(thread_id))


        try:
            message = project_client.agents.messages.create(
                thread_id=thread_id,
                role="user",
                content=question,
            )
        except Exception as e:
            raise print(f"Message creation failed: {e}")
        
        try:
            run = project_client.agents.runs.create(
                thread_id=thread_id,
                agent_id=agent_id,
                temperature=0.2,
                top_p=0.5,
                truncation_strategy=TruncationObject(
                    type=TruncationStrategy.LAST_MESSAGES,
                    last_messages=10
                ),
                additional_instructions=(
                    f"Today's date is {datetime.utcnow().isoformat()}. "
                    "You are a document assistant. Only answer questions using the provided context. "
                    "If the answer is not in the context, respond politely."
                ),
                tools=search_tool.definitions,
                tool_resources=search_tool.resources
            )

            run = wait_for_run_completion(project_client, thread_id, run.id)

        except TimeoutError:
            raise print("Timed out waiting for agent to complete.")
        except Exception as e:
            raise print(f"Agent run failed: {e}")

        if run.status == "failed":
            raise print("Agent processing failed.")


        messages = project_client.agents.messages.get_last_message_text_by_role(
            thread_id=thread_id,
            role="assistant"
        )

        assistant_text = re.sub(r'【\d+:\d+†source】', '', messages['text']['value'])
        return assistant_text

    except Exception as e:
        raise print(f"Chat failed: {str(e)}")
    

print(chat_with_agent("CM139"))````


**Printed Output:**
```2025-07-08 20:19:13,084 - INFO - https://itlbackendapi-azhcfccqdtggbtde.eastus2-01.azurewebsites.net/auth/callback
2025-07-08 20:19:13,315 - INFO - ✅ Azure AIProjectClient initialized successfully.
2025-07-08 20:19:14,843 - INFO - 🔗 Found 2 Azure AI Search connection(s).
2025-07-08 20:19:14,846 - INFO - Available connections: ['itlaisearchservices', 'itldevaisearch']
2025-07-08 20:19:14,848 - INFO - ✅ Selected Azure AI Search connection: itlaisearchservices (ID: /subscriptions/fedf4e07-c619-48c6-a0e0-1f7f977c5557/resourceGroups/itl_rg/providers/Microsoft.CognitiveServices/accounts/itlaifoundry/projects/AI_Powered_Enterprise_Web_Portal/connections/itlaisearchservices)        
{'azure_ai_search': {'indexes': [{'index_connection_id': '/subscriptions/fedf4e07-c619-48c6-a0e0-1f7f977c5557/resourceGroups/itl_rg/providers/Microsoft.CognitiveServices/accounts/itlaifoundry/projects/AI_Powered_Enterprise_Web_Portal/connections/itlaisearchservices', 'index_name': 'mom-test-index', 'query_type': 'vector_semantic_hybrid', 'filter': "people/any(p: p eq 'Arlyn Haining')", 'top_k': 50, 'index_asset_id': ''}]}}
<azure.ai.agents.models._patch.AzureAISearchTool object at 0x000002864E953E50>
{'id': 'thread_uUTdpfJVvsgK11CtFeNs38DJ', 'object': 'thread', 'created_at': 1751986156, 'metadata': {}, 'tool_resources': {'code_interpreter': {'file_ids': []}, 'azure_ai_search': {'indexes': [{'index_connection_id': '/subscriptions/fedf4e07-c619-48c6-a0e0-1f7f977c5557/resourceGroups/itl_rg/providers/Microsoft.CognitiveServices/accounts/itlaifoundry/projects/AI_Powered_Enterprise_Web_Portal/connections/itlaisearchservices', 'index_name': 'mom-test-index', 'query_type': 'vector_semantic_hybrid', 'top_k': 50, 'filter': "people/any(p: p eq 'Arlyn Haining')", 'index_asset_id': ''}]}}}
{'id': 'run_a96JgfmBDMT5DvTUb0cxE2Fa', 'object': 'thread.run', 'created_at': 1751986159, 'assistant_id': 'asst_FqSlIS6pwJaqEBSz5tZbuQxp', 'thread_id': 'thread_uUTdpfJVvsgK11CtFeNs38DJ', 'status': 'in_progress', 'started_at': 1751986159, 'expires_at': 1751987959, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'required_action': None, 'last_error': None, 'model': 'gpt-4o', 'instructions': "Hello Today's date is 2025-07-08T14:49:18.156960. You are a document assistant. Only answer questions using the provided context. If the answer is not in the context, respond politely.", 'tools': [{'type': 'azure_ai_search'}], 'tool_resources': {}, 'metadata': {}, 'temperature': 0.2, 'top_p': 0.5, 'max_completion_tokens': None, 'max_prompt_tokens': None, 'truncation_strategy': {'type': 'last_messages', 'last_messages': 10}, 'incomplete_details': None, 'usage': None, 'response_format': 'auto', 'tool_choice': 'auto', 'parallel_tool_calls': True}
{'id': 'run_a96JgfmBDMT5DvTUb0cxE2Fa', 'object': 'thread.run', 'created_at': 1751986159, 'assistant_id': 'asst_FqSlIS6pwJaqEBSz5tZbuQxp', 'thread_id': 'thread_uUTdpfJVvsgK11CtFeNs38DJ', 'status': 'in_progress', 'started_at': 1751986159, 'expires_at': 1751987959, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'required_action': None, 'last_error': None, 'model': 'gpt-4o', 'instructions': "Hello Today's date is 2025-07-08T14:49:18.156960. You are a document assistant. Only answer questions using the provided context. If the answer is not in the context, respond politely.", 'tools': [{'type': 'azure_ai_search'}], 'tool_resources': {}, 'metadata': {}, 'temperature': 0.2, 'top_p': 0.5, 'max_completion_tokens': None, 'max_prompt_tokens': None, 'truncation_strategy': {'type': 'last_messages', 'last_messages': 10}, 'incomplete_details': None, 'usage': None, 'response_format': 'auto', 'tool_choice': 'auto', 'parallel_tool_calls': True}
{'id': 'run_a96JgfmBDMT5DvTUb0cxE2Fa', 'object': 'thread.run', 'created_at': 1751986159, 'assistant_id': 'asst_FqSlIS6pwJaqEBSz5tZbuQxp', 'thread_id': 'thread_uUTdpfJVvsgK11CtFeNs38DJ', 'status': 'in_progress', 'started_at': 1751986159, 'expires_at': 1751987959, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'required_action': None, 'last_error': None, 'model': 'gpt-4o', 'instructions': "Hello Today's date is 2025-07-08T14:49:18.156960. You are a document assistant. Only answer questions using the provided context. If the answer is not in the context, respond politely.", 'tools': [{'type': 'azure_ai_search'}], 'tool_resources': {}, 'metadata': {}, 'temperature': 0.2, 'top_p': 0.5, 'max_completion_tokens': None, 'max_prompt_tokens': None, 'truncation_strategy': {'type': 'last_messages', 'last_messages': 10}, 'incomplete_details': None, 'usage': None, 'response_format': 'auto', 'tool_choice': 'auto', 'parallel_tool_calls': True}
{'id': 'run_a96JgfmBDMT5DvTUb0cxE2Fa', 'object': 'thread.run', 'created_at': 1751986159, 'assistant_id': 'asst_FqSlIS6pwJaqEBSz5tZbuQxp', 'thread_id': 'thread_uUTdpfJVvsgK11CtFeNs38DJ', 'status': 'in_progress', 'started_at': 1751986159, 'expires_at': 1751987959, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'required_action': None, 'last_error': None, 'model': 'gpt-4o', 'instructions': "Hello Today's date is 2025-07-08T14:49:18.156960. You are a document assistant. Only answer questions using the provided context. If the answer is not in the context, respond politely.", 'tools': [{'type': 'azure_ai_search'}], 'tool_resources': {}, 'metadata': {}, 'temperature': 0.2, 'top_p': 0.5, 'max_completion_tokens': None, 'max_prompt_tokens': None, 'truncation_strategy': {'type': 'last_messages', 'last_messages': 10}, 'incomplete_details': None, 'usage': None, 'response_format': 'auto', 'tool_choice': 'auto', 'parallel_tool_calls': True}
{'id': 'run_a96JgfmBDMT5DvTUb0cxE2Fa', 'object': 'thread.run', 'created_at': 1751986159, 'assistant_id': 'asst_FqSlIS6pwJaqEBSz5tZbuQxp', 'thread_id': 'thread_uUTdpfJVvsgK11CtFeNs38DJ', 'status': 'in_progress', 'started_at': 1751986159, 'expires_at': 1751987959, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'required_action': None, 'last_error': None, 'model': 'gpt-4o', 'instructions': "Hello Today's date is 2025-07-08T14:49:18.156960. You are a document assistant. Only answer questions using the provided context. If the answer is not in the context, respond politely.", 'tools': [{'type': 'azure_ai_search'}], 'tool_resources': {}, 'metadata': {}, 'temperature': 0.2, 'top_p': 0.5, 'max_completion_tokens': None, 'max_prompt_tokens': None, 'truncation_strategy': {'type': 'last_messages', 'last_messages': 10}, 'incomplete_details': None, 'usage': None, 'response_format': 'auto', 'tool_choice': 'auto', 'parallel_tool_calls': True}
{'id': 'run_a96JgfmBDMT5DvTUb0cxE2Fa', 'object': 'thread.run', 'created_at': 1751986159, 'assistant_id': 'asst_FqSlIS6pwJaqEBSz5tZbuQxp', 'thread_id': 'thread_uUTdpfJVvsgK11CtFeNs38DJ', 'status': 'in_progress', 'started_at': 1751986159, 'expires_at': 1751987959, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'required_action': None, 'last_error': None, 'model': 'gpt-4o', 'instructions': "Hello Today's date is 2025-07-08T14:49:18.156960. You are a document assistant. Only answer questions using the provided context. If the answer is not in the context, respond politely.", 'tools': [{'type': 'azure_ai_search'}], 'tool_resources': {}, 'metadata': {}, 'temperature': 0.2, 'top_p': 0.5, 'max_completion_tokens': None, 'max_prompt_tokens': None, 'truncation_strategy': {'type': 'last_messages', 'last_messages': 10}, 'incomplete_details': None, 'usage': None, 'response_format': 'auto', 'tool_choice': 'auto', 'parallel_tool_calls': True}
{'id': 'run_a96JgfmBDMT5DvTUb0cxE2Fa', 'object': 'thread.run', 'created_at': 1751986159, 'assistant_id': 'asst_FqSlIS6pwJaqEBSz5tZbuQxp', 'thread_id': 'thread_uUTdpfJVvsgK11CtFeNs38DJ', 'status': 'in_progress', 'started_at': 1751986159, 'expires_at': 1751987959, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'required_action': None, 'last_error': None, 'model': 'gpt-4o', 'instructions': "Hello Today's date is 2025-07-08T14:49:18.156960. You are a document assistant. Only answer questions using the provided context. If the answer is not in the context, respond politely.", 'tools': [{'type': 'azure_ai_search'}], 'tool_resources': {}, 'metadata': {}, 'temperature': 0.2, 'top_p': 0.5, 'max_completion_tokens': None, 'max_prompt_tokens': None, 'truncation_strategy': {'type': 'last_messages', 'last_messages': 10}, 'incomplete_details': None, 'usage': None, 'response_format': 'auto', 'tool_choice': 'auto', 'parallel_tool_calls': True}
{'id': 'run_a96JgfmBDMT5DvTUb0cxE2Fa', 'object': 'thread.run', 'created_at': 1751986159, 'assistant_id': 'asst_FqSlIS6pwJaqEBSz5tZbuQxp', 'thread_id': 'thread_uUTdpfJVvsgK11CtFeNs38DJ', 'status': 'in_progress', 'started_at': 1751986159, 'expires_at': 1751987959, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'required_action': None, 'last_error': None, 'model': 'gpt-4o', 'instructions': "Hello Today's date is 2025-07-08T14:49:18.156960. You are a document assistant. Only answer questions using the provided context. If the answer is not in the context, respond politely.", 'tools': [{'type': 'azure_ai_search'}], 'tool_resources': {}, 'metadata': {}, 'temperature': 0.2, 'top_p': 0.5, 'max_completion_tokens': None, 'max_prompt_tokens': None, 'truncation_strategy': {'type': 'last_messages', 'last_messages': 10}, 'incomplete_details': None, 'usage': None, 'response_format': 'auto', 'tool_choice': 'auto', 'parallel_tool_calls': True}
{'id': 'run_a96JgfmBDMT5DvTUb0cxE2Fa', 'object': 'thread.run', 'created_at': 1751986159, 'assistant_id': 'asst_FqSlIS6pwJaqEBSz5tZbuQxp', 'thread_id': 'thread_uUTdpfJVvsgK11CtFeNs38DJ', 'status': 'in_progress', 'started_at': 1751986159, 'expires_at': 1751987959, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'required_action': None, 'last_error': None, 'model': 'gpt-4o', 'instructions': "Hello Today's date is 2025-07-08T14:49:18.156960. You are a document assistant. Only answer questions using the provided context. If the answer is not in the context, respond politely.", 'tools': [{'type': 'azure_ai_search'}], 'tool_resources': {}, 'metadata': {}, 'temperature': 0.2, 'top_p': 0.5, 'max_completion_tokens': None, 'max_prompt_tokens': None, 'truncation_strategy': {'type': 'last_messages', 'last_messages': 10}, 'incomplete_details': None, 'usage': None, 'response_format': 'auto', 'tool_choice': 'auto', 'parallel_tool_calls': True}
{'id': 'run_a96JgfmBDMT5DvTUb0cxE2Fa', 'object': 'thread.run', 'created_at': 1751986159, 'assistant_id': 'asst_FqSlIS6pwJaqEBSz5tZbuQxp', 'thread_id': 'thread_uUTdpfJVvsgK11CtFeNs38DJ', 'status': 'in_progress', 'started_at': 1751986159, 'expires_at': 1751987959, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'required_action': None, 'last_error': None, 'model': 'gpt-4o', 'instructions': "Hello Today's date is 2025-07-08T14:49:18.156960. You are a document assistant. Only answer questions using the provided context. If the answer is not in the context, respond politely.", 'tools': [{'type': 'azure_ai_search'}], 'tool_resources': {}, 'metadata': {}, 'temperature': 0.2, 'top_p': 0.5, 'max_completion_tokens': None, 'max_prompt_tokens': None, 'truncation_strategy': {'type': 'last_messages', 'last_messages': 10}, 'incomplete_details': None, 'usage': None, 'response_format': 'auto', 'tool_choice': 'auto', 'parallel_tool_calls': True}
{'id': 'run_a96JgfmBDMT5DvTUb0cxE2Fa', 'object': 'thread.run', 'created_at': 1751986159, 'assistant_id': 'asst_FqSlIS6pwJaqEBSz5tZbuQxp', 'thread_id': 'thread_uUTdpfJVvsgK11CtFeNs38DJ', 'status': 'in_progress', 'started_at': 1751986159, 'expires_at': 1751987959, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'required_action': None, 'last_error': None, 'model': 'gpt-4o', 'instructions': "Hello Today's date is 2025-07-08T14:49:18.156960. You are a document assistant. Only answer questions using the provided context. If the answer is not in the context, respond politely.", 'tools': [{'type': 'azure_ai_search'}], 'tool_resources': {}, 'metadata': {}, 'temperature': 0.2, 'top_p': 0.5, 'max_completion_tokens': None, 'max_prompt_tokens': None, 'truncation_strategy': {'type': 'last_messages', 'last_messages': 10}, 'incomplete_details': None, 'usage': None, 'response_format': 'auto', 'tool_choice': 'auto', 'parallel_tool_calls': True}
{'id': 'run_a96JgfmBDMT5DvTUb0cxE2Fa', 'object': 'thread.run', 'created_at': 1751986159, 'assistant_id': 'asst_FqSlIS6pwJaqEBSz5tZbuQxp', 'thread_id': 'thread_uUTdpfJVvsgK11CtFeNs38DJ', 'status': 'in_progress', 'started_at': 1751986159, 'expires_at': 1751987959, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'required_action': None, 'last_error': None, 'model': 'gpt-4o', 'instructions': "Hello Today's date is 2025-07-08T14:49:18.156960. You are a document assistant. Only answer questions using the provided context. If the answer is not in the context, respond politely.", 'tools': [{'type': 'azure_ai_search'}], 'tool_resources': {}, 'metadata': {}, 'temperature': 0.2, 'top_p': 0.5, 'max_completion_tokens': None, 'max_prompt_tokens': None, 'truncation_strategy': {'type': 'last_messages', 'last_messages': 10}, 'incomplete_details': None, 'usage': None, 'response_format': 'auto', 'tool_choice': 'auto', 'parallel_tool_calls': True}
{'id': 'run_a96JgfmBDMT5DvTUb0cxE2Fa', 'object': 'thread.run', 'created_at': 1751986159, 'assistant_id': 'asst_FqSlIS6pwJaqEBSz5tZbuQxp', 'thread_id': 'thread_uUTdpfJVvsgK11CtFeNs38DJ', 'status': 'failed', 'started_at': 1751986159, 'expires_at': None, 'cancelled_at': None, 'failed_at': 1751986165, 'completed_at': None, 'required_action': None, 'last_error': {'code': 'tool_user_error', 'message': 'Error: search_too_many_indexes; Too many indexes configured for Azure AI Search tool. Only one index can be attached to either the agent, thread, or run.'}, 'model': 'gpt-4o', 'instructions': "Hello Today's date is 2025-07-08T14:49:18.156960. You are a document assistant. Only answer questions using the provided context. If the answer is not in the context, respond politely.", 'tools': [{'type': 'azure_ai_search'}], 'tool_resources': {}, 'metadata': {}, 'temperature': 0.2, 'top_p': 0.5, 'max_completion_tokens': None, 'max_prompt_tokens': None, 'truncation_strategy': {'type': 'last_messages', 'last_messages': 10}, 'incomplete_details': None, 'usage': {'prompt_tokens': 365, 'completion_tokens': 12, 'total_tokens': 377, 'prompt_token_details': {'cached_tokens': 0}}, 'response_format': 'auto', 'tool_choice': 'auto', 'parallel_tool_calls': True}    
Agent processing failed.
Chat failed: exceptions must derive from BaseException
Traceback (most recent call last):
\Agent\temp.py", line 93, in chat_with_agent
    raise print("Agent processing failed.")
TypeError: exceptions must derive from BaseException

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
\Agent\temp.py", line 108, in <module>
    print(chat_with_agent("CM139"))
\Agent\temp.py", line 105, in chat_with_agent
    raise print(f"Chat failed: {str(e)}")
TypeError: exceptions must derive from BaseException```


**Actual Behavior**
Despite passing search_tool.resources during run creation, the tool_resources in the run remain empty. As a result, the assistant has no access to the context, causing failed or irrelevant completions.

**Steps to Reproduce**
Create a filtered AzureAISearchTool object with a filter.

Pass tool_resources to runs.create(...).

Observe run.tool_resources is {}.

**Possible Root Cause**
tool_resources with dynamic filters may not be serialized correctly during run creation.

The filter expression could be silently dropped or stripped internally by SDK or backend.

Metadata

Metadata

Assignees

Labels

AI ProjectsClientThis issue points to a problem in the data-plane of the library.Service AttentionWorkflow: This issue is responsible by Azure service team.customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions