Class AguiRequestProcessor

java.lang.Object
io.agentscope.core.agui.processor.AguiRequestProcessor

public class AguiRequestProcessor extends Object
Core processor for AG-UI requests.

This class encapsulates the common logic for processing AG-UI requests, extracting it from MVC and WebFlux handlers to avoid code duplication.

Responsibilities:

  • Agent ID resolution from multiple sources
  • Message extraction for server-side memory scenarios
  • Agent resolution via AgentResolver
  • Event stream generation via AguiAgentAdapter

Usage:


 AguiRequestProcessor processor = AguiRequestProcessor.builder()
     .agentResolver(resolver)
     .config(AguiAdapterConfig.defaultConfig())
     .build();

 ProcessResult result = processor.process(input, headerAgentId, pathAgentId);
 Flux<AguiEvent> events = result.events();
 Agent agent = result.agent(); // For interrupt handling
 
  • Method Details

    • process

      public AguiRequestProcessor.ProcessResult process(RunAgentInput input, String headerAgentId, String pathAgentId)
      Process an AG-UI request and return the result containing agent and event stream.
      Parameters:
      input - The run agent input
      headerAgentId - The agent ID from HTTP header (may be null)
      pathAgentId - The agent ID from URL path variable (may be null)
      Returns:
      A ProcessResult containing the agent and event stream
    • resolveAgentId

      public String resolveAgentId(RunAgentInput input, String headerAgentId, String pathAgentId)
      Resolve the agent ID from multiple sources.

      The agent ID is resolved in the following priority order:

      1. URL path variable (if provided)
      2. HTTP header (if provided)
      3. forwardedProps.agentId in request body
      4. config.defaultAgentId
      5. "default"
      Parameters:
      input - The request input
      headerAgentId - The agent ID from HTTP header (may be null)
      pathAgentId - The agent ID from URL path variable (may be null)
      Returns:
      The resolved agent ID
    • extractLatestUserMessage

      public RunAgentInput extractLatestUserMessage(RunAgentInput input)
      Extract only the latest user message from the input.

      This is used when server-side memory is enabled and the agent already has conversation history. Only the latest user message needs to be passed.

      Parameters:
      input - The original input
      Returns:
      A new input with only the latest user message
    • builder

      public static AguiRequestProcessor.Builder builder()
      Creates a new builder for AguiRequestProcessor.
      Returns:
      A new builder instance