Class JevModelRouterMiddleware

java.lang.Object
io.agentscope.extensions.judge.jev.example.JevModelRouterMiddleware
All Implemented Interfaces:
io.agentscope.core.middleware.MiddlewareBase

public final class JevModelRouterMiddleware extends Object implements io.agentscope.core.middleware.MiddlewareBase
Selects one of the configured models with Jev before the agent's model call.

Routing happens in two hooks: onAgent(io.agentscope.core.agent.Agent, io.agentscope.core.agent.RuntimeContext, io.agentscope.core.middleware.AgentInput, java.util.function.Function<io.agentscope.core.middleware.AgentInput, reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>>) asks Jev once per agent invocation (using the latest user message) and stores the result in RuntimeContext; onModelCall(io.agentscope.core.agent.Agent, io.agentscope.core.agent.RuntimeContext, io.agentscope.core.middleware.ModelCallInput, java.util.function.Function<io.agentscope.core.middleware.ModelCallInput, reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>>) replaces ModelCallInput.model on every subsequent model call in that invocation. This means an intermediate tool result cannot cause the agent to switch models mid-run. When the decision is unusable (no user text, confidence below threshold, Jev failure while failOpen is set, or an unrecognized answer), the model configured on the agent is used as the fallback.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
     
    static final record 
    A model candidate and the routing criteria sent to Jev.
    static final record 
    The selected model and the calibrated values returned by Jev.
  • Method Summary

    Modifier and Type
    Method
    Description
     
    decision(io.agentscope.core.agent.RuntimeContext ctx)
    Returns the most recent routing decision for the runtime context.
    reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>
    onAgent(io.agentscope.core.agent.Agent agent, io.agentscope.core.agent.RuntimeContext ctx, io.agentscope.core.middleware.AgentInput input, Function<io.agentscope.core.middleware.AgentInput,reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>> next)
     
    reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>
    onModelCall(io.agentscope.core.agent.Agent agent, io.agentscope.core.agent.RuntimeContext ctx, io.agentscope.core.middleware.ModelCallInput input, Function<io.agentscope.core.middleware.ModelCallInput,reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>> next)
     
    int
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.agentscope.core.middleware.MiddlewareBase

    onActing, onReasoning, onSystemPrompt
  • Method Details

    • builder

      public static JevModelRouterMiddleware.Builder builder(JevClient client)
    • order

      public int order()
      Specified by:
      order in interface io.agentscope.core.middleware.MiddlewareBase
    • onAgent

      public reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> onAgent(io.agentscope.core.agent.Agent agent, io.agentscope.core.agent.RuntimeContext ctx, io.agentscope.core.middleware.AgentInput input, Function<io.agentscope.core.middleware.AgentInput,reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>> next)
      Specified by:
      onAgent in interface io.agentscope.core.middleware.MiddlewareBase
    • onModelCall

      public reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent> onModelCall(io.agentscope.core.agent.Agent agent, io.agentscope.core.agent.RuntimeContext ctx, io.agentscope.core.middleware.ModelCallInput input, Function<io.agentscope.core.middleware.ModelCallInput,reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>> next)
      Specified by:
      onModelCall in interface io.agentscope.core.middleware.MiddlewareBase
    • decision

      public static JevModelRouterMiddleware.RoutingDecision decision(io.agentscope.core.agent.RuntimeContext ctx)
      Returns the most recent routing decision for the runtime context.
      Parameters:
      ctx - the runtime context, may be null
      Returns:
      the decision, or null when the router has not run