Split a hub://<hub_id>/<agent_id> URN into its parts.
Returns (hub_id, agent_id) for valid URNs and (None, s) for any other input — including malformed URNs (missing slash, empty hub_id, empty agent_id). Idempotent: callers that pass the agent_id half back in get the same value out.
The canonical inverse is f"hub://{hub_id}/{agent_id}" — there is no helper for that direction because the format is trivial and keeping it inline at call sites makes intent obvious.
Source code in autogen/beta/network/ids.py
| def parse_hub_urn(s: str) -> tuple[str | None, str]:
"""Split a ``hub://<hub_id>/<agent_id>`` URN into its parts.
Returns ``(hub_id, agent_id)`` for valid URNs and ``(None, s)`` for
any other input — including malformed URNs (missing slash, empty
hub_id, empty agent_id). Idempotent: callers that pass the
``agent_id`` half back in get the same value out.
The canonical inverse is ``f"hub://{hub_id}/{agent_id}"`` — there
is no helper for that direction because the format is trivial and
keeping it inline at call sites makes intent obvious.
"""
if not isinstance(s, str) or not s.startswith(_HUB_URN_PREFIX):
return None, s
rest = s[len(_HUB_URN_PREFIX) :]
hub_id, sep, agent_id = rest.partition("/")
if not sep or not hub_id or not agent_id:
return None, s
return hub_id, agent_id
|