Fix: Agentic Search Fails After Updating Agents In OpenSearch
Introduction
This article addresses a critical bug encountered in OpenSearch where updating conversational agents leads to the failure of agentic search. Specifically, the error manifests as "Model ID can't be null or empty" despite having a valid model ID configured. This issue arises after updating an existing conversational agent and attempting to re-run an agentic search using the updated agent. This guide will walk you through the problem, provide a step-by-step reproduction, and highlight potential causes and solutions.
Problem Description
When you update a conversational agent and subsequently attempt to perform an agentic search, the process fails with the following error message:
Error searching index: [illegal_argument_exception] Agentic search failed - Agent execution error - Agent ID: [7G6Bg5oBpAtrCWabdaOI], Error: [Model ID can't be null or empty]
The logs further reveal the root cause:
[2025-11-14T11:55:00,444][ERROR][o.o.m.e.a.a.MLAgentExecutor] [integTest-0] Failed to run conversational agent
java.lang.IllegalArgumentException: Model ID can't be null or empty
at org.opensearch.ml.engine.tools.MLModelTool.<init>(MLModelTool.java:73) ~[?:?]
This error indicates that the MLModelTool is being initialized with a null or empty model ID, even though a valid model ID is configured in the agent definition. This issue prevents the agentic search from executing correctly, rendering the updated agent unusable for search operations. Understanding the underlying cause is crucial for maintaining the functionality of conversational agents in OpenSearch.
Reproduction Steps
To reproduce this bug, follow these steps using any working model for agentic search:
1. Register a Model
First, register a conversational agent with a specified model ID. This involves creating a POST request to the /_plugins/_ml/agents/_register endpoint with the following JSON payload:
POST /_plugins/_ml/agents/_register
{
"name": "test",
"type": "conversational",
"description": "",
"tools": [
{
"type": "QueryPlanningTool"
}
],
"llm": {
"model_id": "<model-id>"
},
"memory": {
"type": "conversation_index"
},
"parameters": {
"_llm_interface": "<interface>"
}
}
Replace <model-id> with the actual ID of your registered model and <interface> with the appropriate interface. This step sets up the initial conversational agent that will be used for the subsequent steps.
2. Run Agentic Search
Next, execute an agentic search using the newly registered agent. This involves sending a GET request to the /<index>/_search endpoint with a query that utilizes the agentic query type:
GET /<index>/_search
{
"query": {
"agentic": {
"query_text": "match all",
"query_fields": []
}
},
"search_pipeline": {
"request_processors": [
{
"agentic_query_translator": {
"agent_id": "<agent-id>"
}
}
]
}
}
Replace <index> with the name of your index and <agent-id> with the ID of the agent you registered in the previous step. This step verifies that the agentic search works correctly with the initial agent configuration.
3. Update the Conversational Agent
Now, update the conversational agent by sending a PUT request to the /_plugins/_ml/agents/<agent-id> endpoint. Modify the agent definition, for example, by adding a new tool:
PUT /_plugins/_ml/agents/<agent-id>
{
"name": "test",
"type": "conversational",
"description": "",
"tools": [
{
"type": "QueryPlanningTool"
},
{
"type": "SearchIndexTool"
}
],
"llm": {
"model_id": "<model-id>"
},
"memory": {
"type": "conversation_index"
},
"parameters": {
"_llm_interface": "<interface>"
}
}
Ensure that <agent-id>, <model-id>, and <interface> are replaced with the appropriate values. This update simulates a common scenario where agents are modified to incorporate new functionalities or adjustments.
4. Verify the Update
Confirm that the agent has been successfully updated by sending a GET request to the /_plugins/_ml/agents/<agent-id> endpoint. This step ensures that the changes made in the previous step have been applied correctly.
5. Re-run Agentic Search
Attempt to re-run the agentic search using the updated agent. Use the same GET request as in step 2:
GET /<index>/_search
{
"query": {
"agentic": {
"query_text": "match all",
"query_fields": []
}
},
"search_pipeline": {
"request_processors": [
{
"agentic_query_translator": {
"agent_id": "<agent-id>"
}
}
]
}
}
6. Observe the Error
Upon executing the agentic search, you will encounter the "Model ID can't be null or empty" error, confirming the bug. This error indicates that the updated agent is not correctly passing the model ID to the MLModelTool, causing the search to fail.
Potential Causes
Several factors could contribute to this issue:
- Caching Issues: OpenSearch might be caching an outdated version of the agent configuration, leading to the
MLModelToolbeing initialized with incorrect or missing parameters. - Serialization/Deserialization Problems: The process of updating the agent might introduce issues during serialization or deserialization, causing the model ID to be lost or corrupted.
- Inconsistent State Management: The internal state management of the agent might not be correctly updated after the agent is modified, resulting in inconsistencies between the configured model ID and the actual value used during execution.
- Tool Initialization Logic: There might be a flaw in the
MLModelToolinitialization logic that fails to properly retrieve the model ID after an agent update.
Possible Solutions and Workarounds
Here are some potential solutions and workarounds to address this issue:
- Clear Caches: Try clearing any relevant caches in OpenSearch that might be storing outdated agent configurations. This can help ensure that the latest agent definition is being used.
- Restart OpenSearch Nodes: Restarting the OpenSearch nodes can force a refresh of the agent configurations and resolve any inconsistencies in the internal state. This ensures that the latest agent definitions are loaded correctly.
- Re-register the Agent: As a workaround, you can try deleting the existing agent and re-registering it with the updated configuration. While this is not ideal, it can help bypass the issue temporarily.
- Verify Agent Configuration: Double-check the agent configuration to ensure that the model ID is correctly specified and that there are no typos or other errors. This includes reviewing the agent definition and any related settings.
- Code Debugging: If you have access to the OpenSearch codebase, debugging the
MLModelToolinitialization logic can help identify the root cause of the problem and implement a proper fix. This involves tracing the execution flow and examining the values of relevant variables.
Conclusion
The bug where updating conversational agents causes agentic search to fail with a "Model ID can't be null or empty" error is a significant issue that can disrupt the functionality of OpenSearch. By following the reproduction steps and understanding the potential causes, you can better diagnose and address this problem. Implementing the suggested solutions and workarounds can help mitigate the issue and ensure the smooth operation of your conversational agents.
For more information about OpenSearch and its features, visit the official OpenSearch documentation. This resource provides comprehensive details about OpenSearch functionalities and best practices.