Skip to content

[FEATURE] Add processor chain #4235

@ylwu-amzn

Description

@ylwu-amzn

Description

We need a flexible and extensible framework for processing outputs from ML models and tools using chainable processors. This is motivated by the different output formats returned by various models (e.g., Bedrock Claude vs OpenAI) and the current complexity of using Painless Script for post-processing.

Proposed Solution

Implement a processor chain framework that allows configuring multiple processors to transform tool/model outputs sequentially.

Built-in Processors

  • to_string: Converts input to string format
  • regex_replace: Performs regex-based text replacement
  • jsonpath_filter: Filters JSON using JsonPath expressions
  • extract_json: Extracts JSON objects/arrays from text
  • regex_capture: Captures text using regex groups
  • remove_jsonpath: Removes elements at specified JsonPath
  • conditional: Applies different processors based on conditions

Example Usage

Configure two output processors for ListIndexTool

  1. Use regex_replace to remove all lines contains index starting with .plugins
  2. Use regex_replace to remove first column row , since the row number will become wrong after removing lines
{
  "name": "Test Agent",
  "type": "flow",
  "description": "This is a demo agent",
  "tools": [
    {
      "type": "ListIndexTool",
      "parameters": {
        "output_processors": [
          {
            "type": "regex_replace",
            "pattern": "(?m)^(?!row,health,status).*?,.*?,.*?,\\.plugins[^\\n]*\\n",
            "replacement": ""
          },
          {
            "type": "regex_replace",
            "pattern": "(?m)^row,|^\\d+,",
            "replacement": ""
          }
        ]
      }
    }
  ]
}

Sample output

{
  "inference_results": [
    {
      "output": [
        {
          "name": "response",
          "result": """health,status,index,uuid,pri(number of primary shards),rep(number of replica shards),docs.count(number of available documents),docs.deleted(number of deleted documents),store.size(store size of primary and replica shards),pri.store.size(store size of primary shards)
yellow,open,ss4o_logs-otel-2025.09.22,aePQaQvuSmygcLXMZiZMpA,1,1,218380,0,117.8mb,117.8mb
yellow,open,jaeger-service-2025-09-20,W_c332tRQiaYyYA7Q93a5g,1,1,84,7,21.9kb,21.9kb
yellow,open,jaeger-service-2025-09-22,aG2VFQLMSVWcefCBAgo2iQ,1,1,84,0,50kb,50kb
yellow,open,jaeger-service-2025-09-23,rmO1fmMxQI2ovc_n-uHN2w,1,1,84,0,30.4kb,30.4kb
green,open,top_queries-2025.09.22-00440,lMQ-f2xtS4eLbNA19GdD2A,1,0,1755,0,639.2kb,639.2kb
yellow,open,jaeger-service-2025-09-24,zM41TnvyTEWkp1wSCwgPdQ,1,1,84,0,20kb,20kb
green,open,top_queries-2025.09.25-00443,epX66GgQSEeznqQoyglZFg,1,0,218,47,576.2kb,576.2kb
"""
        }
      ]
    }
  ]
}

Metadata

Metadata

Assignees

Type

No type

Projects

Status

In Progress

Status

New

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions