Record Class MsgContext

java.lang.Object
java.lang.Record
io.agentscope.harness.agent.gateway.MsgContext
Record Components:
channel - logical channel name (e.g. slack, discord, web)
group - optional group / team / workspace id
room - optional room / channel id
threadId - optional thread / topic id
threadTs - optional provider-specific thread timestamp or message anchor
extra - additional key/value pairs for adapters
userId - optional authenticated user identity for HarnessAgent namespace isolation

public record MsgContext(String channel, String group, String room, String threadId, String threadTs, Map<String,String> extra, String userId) extends Record
Routing context for inbound turns (direct API, channel adapter, group/room/thread). Used by the gateway to map stable conversation keys to session ids.

The userId field carries the message sender's identity for multi-tenant namespace isolation in HarnessAgent. It is derived from InboundMessage.senderId() and does not participate in canonicalKey() computation — the same user's conversations always map to the same session key regardless of how userId is set.

  • Constructor Details

    • MsgContext

      public MsgContext(String channel, String group, String room, String threadId, String threadTs, Map<String,String> extra, String userId)
      Creates an instance of a MsgContext record class.
      Parameters:
      channel - the value for the channel record component
      group - the value for the group record component
      room - the value for the room record component
      threadId - the value for the threadId record component
      threadTs - the value for the threadTs record component
      extra - the value for the extra record component
      userId - the value for the userId record component
    • MsgContext

      public MsgContext(String channel, String group, String room, String threadId, String threadTs, Map<String,String> extra)
      Convenience constructor without userId (backwards-compatible for callsites that do not carry user identity).
  • Method Details

    • defaultContext

      public static MsgContext defaultContext()
      Default single-conversation context (no channel metadata, no userId).
    • withUserId

      public MsgContext withUserId(String userId)
      Returns a copy of this context with the given userId set.
    • canonicalKey

      public String canonicalKey()
      Stable key for session routing: same logical conversation maps to the same gateway session id.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • channel

      public String channel()
      Returns the value of the channel record component.
      Returns:
      the value of the channel record component
    • group

      public String group()
      Returns the value of the group record component.
      Returns:
      the value of the group record component
    • room

      public String room()
      Returns the value of the room record component.
      Returns:
      the value of the room record component
    • threadId

      public String threadId()
      Returns the value of the threadId record component.
      Returns:
      the value of the threadId record component
    • threadTs

      public String threadTs()
      Returns the value of the threadTs record component.
      Returns:
      the value of the threadTs record component
    • extra

      public Map<String,String> extra()
      Returns the value of the extra record component.
      Returns:
      the value of the extra record component
    • userId

      public String userId()
      Returns the value of the userId record component.
      Returns:
      the value of the userId record component