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();

 AguiRuntimeContextRequest<?> request = AguiRuntimeContextRequest.builder()
         .input(input)
         .build();
 ProcessResult result = processor.process(request);
 Flux<AguiEvent> events = result.events();
 
  • Method Details

    • process

      Process an AG-UI request and return the result containing agent and event stream.

      The AguiRuntimeContextResolver (if configured on this processor) is invoked with the given request to obtain a caller-provided RuntimeContext. That context is copied and enriched by AguiAgentAdapter, so callers can provide custom attributes without replacing the standard AG-UI metadata.

      Parameters:
      request - The AG-UI request context carrying input, agent IDs, transport details and the native request
      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 messages that arrived after the last assistant turn.

      When server-side memory is enabled the agent already holds prior turns. CopilotKit (and similar clients) still send the full transcript, including HITL tool results that follow the last assistant message. Only those trailing messages should be appended.

      If the transcript has no assistant message yet, the original input is returned unchanged. If the transcript ends with an assistant turn (regenerate/continue flows) and there are no trailing follow-up messages, the last user message before that turn is returned so the agent has a prompt to regenerate from instead of receiving an empty input.

      Parameters:
      input - The original input
      Returns:
      A new input containing only the follow-up messages, or the original input
    • builder

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