MAGI Specification

This document provides detailed specifications for the three optional components of MAGI (Markdown for Agent Guidance & Instruction): YAML Front Matter, ai-script Code Blocks, and Markdown Footnotes for Relationships.

MAGI is designed to be saved in files with the .mda extension to clearly signal the presence of enhanced components. While standard Markdown files (.md) can contain MAGI elements for backward compatibility, processors optimized for MAGI might prioritize .mda files or treat .md files as standard Markdown, potentially ignoring ai-script blocks or footnote relationships unless explicitly configured to parse them.

The MAGI format, represented as a string, is suitable for transmission via REST APIs, either as request payloads (e.g., sending content to be processed) or response bodies (e.g., returning processed or generated content in MAGI format).

1. Front Matter Schema

Provides structured metadata using YAML syntax, enclosed by --- delimiters at the very beginning of the .mda file.

Fields: Field names use kebab-case (e.g., doc-id, created-date).

FieldTypeDescriptionExampleRequired/OptionalNotes
doc-idstringA unique identifier (UUID format recommended) for this document. Crucial for footnote relationships."38f5a922-81b2-4f1a-8d8c-3a5be4ea7511"OptionalStrongly recommended for linking
titlestringThe main title of the document."Introduction to MAGI"Optional
descriptionstringA brief summary or abstract of the document’s content."Explains the MAGI format."Optional
authorstringThe primary author’s name."Jane Doe"Optional
author-idstringUnique identifier for the author (CUID2 or UUID recommended)."usr_abcdef12345"OptionalUseful for linking author profiles
imagestringURL for a primary cover image associated with the document."https://example.com/cover.jpg"Optional
images-listlist[string]URLs for additional images associated with the document.["https://.../img1.jpg"]Optional
published-datestringISO 8601 timestamp when the document was originally published or made public."2024-01-10T08:00:00Z"Optional
tagslist[string]Keywords or categories for classification and retrieval.["markdown", "ai", "rag"]Optional
created-datestringISO 8601 timestamp (date and time with timezone recommended) when the document was originally created."2024-01-15T09:00:00Z"Optionale.g., YYYY-MM-DDTHH:mm:ssZ
updated-datestringISO 8601 timestamp when the document was last significantly updated."2024-06-01T15:30:00Z"Optional
expired-datestringOptional ISO 8601 timestamp when the content should be considered outdated."2025-01-01T00:00:00Z"Optional
globslist[string]File or URL patterns this metadata applies to (e.g., ["docs/**/*.md", "*.ts"]).["*.mda", "!legacy/*"]OptionalUsed for external/meta .mda files
audiencelist[string]Describes the intended audience(s) (e.g., ["developers", "end-users"]).["Developers"]Optional
purposestringThe primary goal or objective of the document (e.g., “tutorial”, “reference”)."Reference"Optional
entitieslist[string]Key named entities (people, places, organizations, concepts) mentioned.["MAGI", "RAG", "LLM"]OptionalUseful for RAG filtering/extraction
relationshipslist[string]High-level summary of relationships defined in footnotes (human-readable).["Extends Markdown"]OptionalPrimarily for human readers
source-urlstringThe original URL if the content was sourced or derived from the web."https://example.com/doc"Optional

Note: While all fields are technically optional for basic .mda validity, doc-id is essential if using the Footnote relationship feature. Custom fields are allowed but may be ignored by standard processors.

2. AI Script Block (ai-script)

Embeds instructions for AI processing within standard Markdown fenced code blocks using the ai-script language identifier. The content must be a single, valid JSON object. Field names within the JSON use kebab-case (e.g., script-id, model-name).

JSON Fields:

FieldTypeDescriptionExampleRequired/OptionalNotes
script-idstringA unique identifier for this specific instruction block within the document."summary-request-001"RequiredShould be unique within the .mda file
promptstringThe actual prompt or command text intended for the LLM or AI agent."Summarize this section."Required
prioritystringHelps prioritize execution if multiple instructions exist (e.g., “high”, “medium”, “low”)."medium"OptionalDefault behavior is application-specific
auto-runbooleanHint indicating if an automated processing agent should execute this instruction without explicit user trigger.trueOptionalDefault is usually false
providerstringSuggests the target AI provider (e.g., “openai”, “anthropic”, “google”, “local-llm”)."openai"Optional
model-namestringSuggests the target model name (e.g., “gpt-4o”, “claude-3-opus-20240229”)."gpt-4o"Optional
system-promptstringOptional system-level instructions or context for the AI model."Act as a helpful assistant."OptionalPrepended or handled specially by the runtime
parametersobjectA JSON object containing provider-specific parameters (e.g., temperature, max tokens).{"temperature": 0.7}OptionalPassed directly to the model API
retry-timesintegerOptional hint for the maximum number of retry attempts on failure.3OptionalRuntime should interpret this hint. Default behavior is runtime-specific.
runtime-envstringSuggests the ideal runtime context or endpoint for execution (e.g., “server”, “browser”, “edge”, API URL)."server"OptionalHint for the processing system
output-formatstringDesired format for the output (e.g., “markdown”, “text”, “json”, “image-url”)."markdown"OptionalProcessor should attempt to conform. Implied “json” if output-schema is used.
output-schemaobjectOptional JSON Schema object defining the expected structure of the output.{"type": "object", ...}OptionalStrongly implies output-format: "json". Used for structured data extraction.
streambooleanOptional hint to the runtime to stream the response if possible.trueOptionalDefault is false. Primarily for text output.
interactive-typestringType of interactive component to render if auto-run is false (e.g., “button”, “inputbox”)."button"OptionalUsed for client-side triggered execution. If “inputbox”, an input field and submit button (using interactive-label) are rendered.
interactive-labelstringLabel text for the interactive component (e.g., button text, typically for the submit button)."Run Summary"OptionalUsed when interactive-type is specified.
interactive-placeholderstringPlaceholder text for the input field when interactive-type is “inputbox”."Enter your query..."OptionalUsed only when interactive-type is “inputbox”.

Processing Hint:

A comment like <!-- AI-PROCESSOR: Content blocks marked with ```ai-script are instructions for AI systems and should not be presented to human users --> can optionally precede the block to explicitly guide processing systems, but detection should rely on the ai-script identifier.

Alternative: Instructions can also be passed externally (e.g., via API metadata alongside the MAGI content string) for separation of concerns, especially in complex multi-agent systems.

3. Footnote Relationships

Leverages standard Markdown footnote syntax ([^ref-id] and [^ref-id]: ...) to define typed relationships between the current document and other resources. The footnote definition must contain a single JSON object enclosed in backticks (`).

JSON Fields within Footnote Definition: Field names use kebab-case (e.g., rel-type, doc-id).

FieldTypeDescriptionExampleRequired/OptionalNotes
rel-typestring (Enum recommended)Nature of the relationship. Recommended values: citation, parent, child, related, contradicts, supports, extends."parent"Required
doc-idstringThe unique doc-id (from Front Matter) of the target/related .mda document. Use either doc-id or source-url."UUID-of-target-document"ConditionalRequired if not using source-url
source-urlstringThe URL of the target/related external resource. Use either doc-id or source-url."https://example.com/related-article"ConditionalRequired if not using doc-id
rel-descstringA brief, human-readable description of why the documents/resources are related."Derived from primary SEC documentation"Required
rel-strengthfloat (0.0 to 1.0)Optional confidence score or relevance strength of the relationship.0.8Optional
bi-directionalbooleanOptional: Indicates if the relationship implies a reciprocal link back (interpretation depends on processor).trueOptionalDefault is usually false
contextobjectOptional: Provides additional structured context about the link’s location/nature.{"section": "Introduction", "relevance": "High"}Optional
context.sectionstringSpecific section/heading in the source document where the link originates."Introduction"OptionalWithin context object
context.relevancestringQualitative assessment of relevance (e.g., “High”, “Medium”, “Low”)."High"OptionalWithin context object

Implementation Notes:

  • Ensure the doc-id used in footnotes corresponds accurately to a doc-id defined in the Front Matter of the target .mda document for internal links.
  • Consistent use of rel-type values is crucial for building reliable knowledge graphs.
  • Standard Markdown parsers will render the footnote with the backticks and JSON string as the literal content. MAGI-aware parsers extract and interpret the JSON.