Class TeamsMiddleware

java.lang.Object
io.agentscope.harness.agent.middleware.TeamsMiddleware
All Implemented Interfaces:
io.agentscope.core.middleware.MiddlewareBase, HarnessRuntimeMiddleware

public final class TeamsMiddleware extends Object implements HarnessRuntimeMiddleware
Injects AgentTeams context into the system prompt and exposes a role-clipped TeamTool.

Optional wireMessageBus(MessageBus, String) pushes mailbox wakeups into the session inbox path used by InboxMiddleware.

  • Constructor Summary

    Constructors
    Constructor
    Description
    TeamsMiddleware(TeamClient teamClient, TeamContext teamContext)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    bindSession(String sessionId)
    Registers this middleware under a runtime session id for TeamEvent delivery.
    Tools to register on the agent toolkit at build time.
    boolean
    Reports whether the shared board still has non-terminal tasks, so blocking waits know that teammates are still working even when this session owns no background subagent tasks.
    void
    notifyWakeup(String sessionId)
    Notifies this teammate session that a team event arrived (message / task settled).
    void
    notifyWakeup(String sessionId, String notice)
    Notifies this teammate session, injecting notice so the woken turn starts with the event content instead of an empty prompt.
    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)
    Gives the lead the board as it stands when its turn starts, and settles a worker's tasks when its turn ends.
    reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>
    onReasoning(io.agentscope.core.agent.Agent agent, io.agentscope.core.agent.RuntimeContext ctx, io.agentscope.core.middleware.ReasoningInput input, Function<io.agentscope.core.middleware.ReasoningInput,reactor.core.publisher.Flux<io.agentscope.core.event.AgentEvent>> next)
     
    static void
    registerSession(String sessionId, TeamsMiddleware middleware)
    Registers sessionId against an already-built middleware instance.
    static String
    Renders the system-prompt team section (also used by BYO team_join kickoff).
     
     
    static void
    Drops every registry entry for a session that is gone for good, so a later team reusing the same team and member names cannot wake this dead session.
    static boolean
    wakeupSession(String sessionId)
    Wakes the teammate bound to sessionId.
    static boolean
    wakeupSession(String sessionId, String notice)
    Wakes the teammate bound to sessionId, injecting notice into its next turn.
    static boolean
    wakeupTeamMember(String teamName, String memberName)
    Wakes a teammate identified by team + member name.
    static boolean
    wakeupTeamMember(String teamName, String memberName, String notice)
    Wakes a teammate by team + member name, injecting notice into its next turn.
    void
    wireMessageBus(MessageBus messageBus, String agentId)
    Wires mailbox wakeups.

    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, onModelCall, onSystemPrompt, order
  • Constructor Details

  • Method Details

    • bindSession

      public void bindSession(String sessionId)
      Registers this middleware under a runtime session id for TeamEvent delivery.
    • registerSession

      public static void registerSession(String sessionId, TeamsMiddleware middleware)
      Registers sessionId against an already-built middleware instance.
    • unregisterSession

      public static void unregisterSession(String sessionId)
      Drops every registry entry for a session that is gone for good, so a later team reusing the same team and member names cannot wake this dead session. Call it only when the session was deleted, not when it merely went idle.

      The member entry is removed only while it still points at this instance: a member that was rebuilt under a new session has already replaced it.

    • wakeupSession

      public static boolean wakeupSession(String sessionId)
      Wakes the teammate bound to sessionId. Returns false when unknown.
    • wakeupSession

      public static boolean wakeupSession(String sessionId, String notice)
      Wakes the teammate bound to sessionId, injecting notice into its next turn.
    • wakeupTeamMember

      public static boolean wakeupTeamMember(String teamName, String memberName)
      Wakes a teammate identified by team + member name. Returns false when unknown.
    • wakeupTeamMember

      public static boolean wakeupTeamMember(String teamName, String memberName, String notice)
      Wakes a teammate by team + member name, injecting notice into its next turn.
    • getTools

      public List<Object> getTools()
      Tools to register on the agent toolkit at build time.
    • teamContext

      public TeamContext teamContext()
    • teamClient

      public TeamClient teamClient()
    • wireMessageBus

      public void wireMessageBus(MessageBus messageBus, String agentId)
      Wires mailbox wakeups. agentId is passed to MessageBus.enqueueWakeup(java.lang.String, java.lang.String, java.lang.String) so the gateway can route idle rounds.
    • notifyWakeup

      public void notifyWakeup(String sessionId)
      Notifies this teammate session that a team event arrived (message / task settled).
    • notifyWakeup

      public void notifyWakeup(String sessionId, String notice)
      Notifies this teammate session, injecting notice so the woken turn starts with the event content instead of an empty prompt. Safe to call from adapters or team client hooks.

      When no session is bound yet the notice is buffered and injected on the next reasoning step, so events that race session binding are not lost.

    • 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)
      Gives the lead the board as it stands when its turn starts, and settles a worker's tasks when its turn ends. The lead's tasks are left alone: it answers to a user who can pick the conversation back up, so its turn ending is not the end of its execution.
      Specified by:
      onAgent in interface io.agentscope.core.middleware.MiddlewareBase
    • onReasoning

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

      public boolean hasOutstandingTeamWork()
      Reports whether the shared board still has non-terminal tasks, so blocking waits know that teammates are still working even when this session owns no background subagent tasks.
    • renderTeamSection

      public static String renderTeamSection(TeamContext ctx)
      Renders the system-prompt team section (also used by BYO team_join kickoff).