Class AguiRequestProcessor
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();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for AguiRequestProcessor.static final recordResult of processing an AG-UI request. -
Method Summary
Modifier and TypeMethodDescriptionstatic AguiRequestProcessor.Builderbuilder()Creates a new builder for AguiRequestProcessor.Extract messages that arrived after the last assistant turn.process(AguiRuntimeContextRequest<?> request) Process an AG-UI request and return the result containing agent and event stream.resolveAgentId(RunAgentInput input, String headerAgentId, String pathAgentId) Resolve the agent ID from multiple sources.
-
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-providedRuntimeContext. That context is copied and enriched byAguiAgentAdapter, 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
Resolve the agent ID from multiple sources.The agent ID is resolved in the following priority order:
- URL path variable (if provided)
- HTTP header (if provided)
- forwardedProps.agentId in request body
- config.defaultAgentId
- "default"
- Parameters:
input- The request inputheaderAgentId- 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
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
Creates a new builder for AguiRequestProcessor.- Returns:
- A new builder instance
-