Skip to content

parse_skill_frontmatter

autogen.beta.network.client.skill_render.parse_skill_frontmatter #

parse_skill_frontmatter(md)

Split a SKILL.md body into (frontmatter, body).

Returns {"frontmatter": {}, "body": md} when no frontmatter fence is present or the closing fence is missing — the rest of the document is treated as the body verbatim.

Source code in autogen/beta/network/client/skill_render.py
def parse_skill_frontmatter(md: str) -> ParsedSkill:
    """Split a SKILL.md body into ``(frontmatter, body)``.

    Returns ``{"frontmatter": {}, "body": md}`` when no frontmatter
    fence is present or the closing fence is missing — the rest of the
    document is treated as the body verbatim.
    """
    if not md.startswith(_FENCE):
        return ParsedSkill(frontmatter={}, body=md)
    # Find the closing fence on its own line after the opening one.
    rest = md[len(_FENCE) :]
    if rest.startswith("\n"):
        rest = rest[1:]
    closing = rest.find(f"\n{_FENCE}")
    if closing == -1:
        return ParsedSkill(frontmatter={}, body=md)
    header = rest[:closing]
    body = rest[closing + len(_FENCE) + 1 :]  # skip "\n---"
    if body.startswith("\n"):
        body = body[1:]

    frontmatter: dict[str, Any] = {}
    for line in header.splitlines():
        stripped = line.strip()
        if not stripped or stripped.startswith("#"):
            continue
        if ":" not in stripped:
            continue
        key, _, value = stripped.partition(":")
        frontmatter[key.strip()] = value.strip()

    return ParsedSkill(frontmatter=frontmatter, body=body)