Agent tool

Introduced 2.13

The AgentTool runs any agent.

Step 1: Set up an agent for AgentTool to run

Set up any agent. For example, set up a flow agent that runs an MLModelTool by following the steps in the ML Model Tool documentation and obtain its agent ID from Step 3:

  1. {
  2. "agent_id": "9X7xWI0Bpc3sThaJdY9i"
  3. }

Step 2: Register a flow agent that will run the AgentTool

A flow agent runs a sequence of tools in order and returns the last tool’s output. To create a flow agent, send the following register agent request, providing the agent ID from the previous step:

  1. POST /_plugins/_ml/agents/_register
  2. {
  3. "name": "Test agent tool",
  4. "type": "flow",
  5. "description": "this is a test agent",
  6. "tools": [
  7. {
  8. "type": "AgentTool",
  9. "description": "A general agent to answer any question",
  10. "parameters": {
  11. "agent_id": "9X7xWI0Bpc3sThaJdY9i"
  12. }
  13. }
  14. ]
  15. }

copy

For parameter descriptions, see Register parameters.

OpenSearch responds with an agent ID:

  1. {
  2. "agent_id": "EQyyZ40BT2tRrkdmhT7_"
  3. }

Step 3: Run the agent

Run the agent by sending the following request:

  1. POST /_plugins/_ml/agents/EQyyZ40BT2tRrkdmhT7_/_execute
  2. {
  3. "parameters": {
  4. "question": "what's the population increase of Seattle from 2021 to 2023"
  5. }
  6. }

copy

OpenSearch returns the inference results:

  1. {
  2. "inference_results": [
  3. {
  4. "output": [
  5. {
  6. "name": "response",
  7. "result": " I do not have direct data on the population increase of Seattle from 2021 to 2023 in the context provided. As a data analyst, I would need to research population statistics from credible sources like the US Census Bureau to analyze population trends and make an informed estimate. Without looking up actual data, I don't have enough information to provide a specific answer to the question."
  8. }
  9. ]
  10. }
  11. ]
  12. }

Register parameters

The following table lists all tool parameters that are available when registering an agent.

ParameterTypeRequired/OptionalDescription
agent_idStringRequiredThe agent ID of the agent to run.

Execute parameters

The following table lists all tool parameters that are available when running the agent.

ParameterTypeRequired/OptionalDescription
questionStringRequiredThe natural language question to send to the LLM.