Class AguiWebFluxHandler

java.lang.Object
io.agentscope.spring.boot.agui.webflux.AguiWebFluxHandler

public class AguiWebFluxHandler extends Object
WebFlux handler for AG-UI protocol requests.

This handler processes AG-UI run requests and returns Server-Sent Events (SSE) streams with AG-UI protocol events.

Agent ID Resolution Priority:

  1. URL path variable: /agui/run/{agentId}
  2. HTTP header: configurable via agentIdHeader (default: X-Agent-Id)
  3. forwardedProps.agentId in request body
  4. config.defaultAgentId
  5. "default"

Usage:


 AguiWebFluxHandler handler = AguiWebFluxHandler.builder()
     .agentRegistry(registry)
     .config(AguiAdapterConfig.defaultConfig())
     .agentIdHeader("X-Agent-Id")
     .build();

 RouterFunction<ServerResponse> routes = RouterFunctions.route()
     .POST("/agui/run", handler::handle)
     .POST("/agui/run/{agentId}", handler::handleWithAgentId)
     .build();
 
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Builder for AguiWebFluxHandler.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new builder for AguiWebFluxHandler.
    reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse>
    handle(org.springframework.web.reactive.function.server.ServerRequest request)
    Handle an AG-UI run request.
    reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse>
    handleWithAgentId(org.springframework.web.reactive.function.server.ServerRequest request)
    Handle an AG-UI run request with agent ID in the URL path.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • handle

      public reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse> handle(org.springframework.web.reactive.function.server.ServerRequest request)
      Handle an AG-UI run request.

      This method parses the request body as RunAgentInput, resolves the agent from the registry, and returns an SSE stream of AG-UI events.

      Parameters:
      request - The server request
      Returns:
      A Mono containing the server response with SSE stream
    • handleWithAgentId

      public reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse> handleWithAgentId(org.springframework.web.reactive.function.server.ServerRequest request)
      Handle an AG-UI run request with agent ID in the URL path.

      This method handles requests to /agui/run/{agentId}. The path variable takes highest priority for agent resolution.

      Parameters:
      request - The server request containing the agentId path variable
      Returns:
      A Mono containing the server response with SSE stream
    • builder

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