MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / expand_agent_mentions

Function expand_agent_mentions

src/command_system/input_processing.py:715–759  ·  view source on GitHub ↗

Find ``@agent- `` mentions and build ``agent_mention`` attachments. Mirrors ``processAgentMentions`` in ``typescript/src/utils/attachments.ts``: each mention that resolves to a known agent type produces a single attachment; unknown agents are silently dropped so stray ``@agent-

(
    text: str,
    agents: list[Any] | None,
)

Source from the content-addressed store, hash-verified

713
714
715def expand_agent_mentions(
716 text: str,
717 agents: list[Any] | None,
718) -> list[dict[str, str]]:
719 """Find ``@agent-<type>`` mentions and build ``agent_mention`` attachments.
720
721 Mirrors ``processAgentMentions`` in
722 ``typescript/src/utils/attachments.ts``: each mention that resolves to a
723 known agent type produces a single attachment; unknown agents are
724 silently dropped so stray ``@agent-foo`` text in prompts doesn&#x27;t pollute
725 the model&#x27;s context with misleading reminders.
726 """
727 if not text or not agents:
728 return []
729
730 known_types: set[str] = set()
731 for agent in agents:
732 agent_type = getattr(agent, "agent_type", None) or (
733 agent.get("agent_type") if isinstance(agent, dict) else None
734 )
735 if isinstance(agent_type, str) and agent_type:
736 known_types.add(agent_type)
737
738 if not known_types:
739 return []
740
741 seen: set[str] = set()
742 attachments: list[dict[str, str]] = []
743
744 for match in _AGENT_MENTION_UNQUOTED_RE.finditer(text):
745 raw = match.group(1)
746 agent_type = raw[len("agent-"):] if raw.startswith("agent-") else raw
747 if agent_type in seen or agent_type not in known_types:
748 continue
749 seen.add(agent_type)
750 attachments.append({"kind": "agent_mention", "agent_type": agent_type})
751
752 for match in _AGENT_MENTION_QUOTED_RE.finditer(text):
753 agent_type = match.group(1)
754 if agent_type in seen or agent_type not in known_types:
755 continue
756 seen.add(agent_type)
757 attachments.append({"kind": "agent_mention", "agent_type": agent_type})
758
759 return attachments
760
761
762def _extract_image_paths(text: str, cwd: str | None = None) -> list[str]:

Calls 3

getMethod · 0.45
addMethod · 0.45
appendMethod · 0.45