INNER CODE UNIT · TypeScript

routeRules

agentconnect-md/agentconnect · packages/activation-policy/src/index.ts:159

export function routeRules(
  msg: ActivationMessageFacts,
  rules: ActivationRule[],
  threadOwner: (channel: string, thread: string) => string | null,
  explicitAgentId?: string,
  verifiedAgentAuthor?: string
): { agentId: string; integrationId: string; via: RouteVia } | null {
  if (explicitAgentId !== undefined) {
    // Webchat names its agent; integrationId '' because ingress is the relay data plane.
    return { agentId: explicitAgentId, integrationId: '', via: 'mention' }
  }
  // Kind-agnostic (reachability + thread continuity). The author is removed HERE, once, so every
  // rung below inherits it: an agent matching its own rule would self-loop on its own reply.
  const scopeCandidates = rules.filter(
    (r) => scopeMatches(r, msg) && (verifiedAgentAuthor === undefined || r.agentId !== verifiedAgentAuthor)
  )
  // kind-candidates: also match the message kind.
  const kindCandidates = scopeCandidates.filter((r) => kindMatches(r, msg))

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…