ART Framework API Docs
    Preparing search index...

    Class OutputParser

    Default implementation of the IOutputParser interface.

    This class provides robust parsing capabilities for structured output from LLMs. It is designed to handle variations in LLM output formatting across different providers and models. The parser uses a multi-tier strategy for extracting structured data:

    1. XML Tag Extraction: Extracts content from XML-like tags (e.g., ) using the XmlMatcher utility. This separates "thoughts" or "reasoning" from the main structured output.

    2. JSON Extraction: Attempts multiple strategies to find and parse JSON:

      • Priority 1: Explicit JSON markers (---JSON_OUTPUT_START--- ... ---JSON_OUTPUT_END---)
      • Priority 2: Markdown code blocks (json ... or ...)
      • Priority 3: Strip markdown fences and attempt direct parsing
      • Priority 4: Find JSON object by brace matching for mixed content
    3. Schema Validation: Uses Zod schemas to validate parsed structures:

      • ParsedToolCall validation ensures tool calls have required fields
      • TodoItem validation ensures todo items conform to expected structure
    4. Fallback Parsing: If JSON extraction fails, attempts to extract information from labeled sections (e.g., "Title: ...", "Intent: ...", "Plan: ...")

    The parser is resilient to:

    • Malformed or incomplete XML tags
    • Missing or malformed JSON
    • Mixed content (text + JSON)
    • Provider-specific formatting differences

    OutputParser

    IOutputParser

    Implements

    • OutputParser
    Index

    Constructors

    Methods

    • Parses the raw string output from an execution LLM call (per todo item).

      Parameters

      • output: string

        The raw string response from the execution LLM.

      Returns Promise<ExecutionOutput>

      A promise resolving to an ExecutionOutput object containing: - thoughts (string, optional): Extracted from tags - toolCalls (ParsedToolCall[], optional): Parsed tool call requests - nextStepDecision (string, optional): How to proceed - updatedPlan (object, optional): Plan modifications - content (string, optional): Freeform text response

      The execution phase generates output that may include:

      • thoughts: Reasoning extracted from tags
      • toolCalls: Structured tool call requests for the current step
      • nextStepDecision: Decision on how to proceed (continue, wait, complete_item, update_plan)
      • updatedPlan: Modifications to the execution plan
      • content: Freeform text response

      This method:

      1. Extracts thoughts from tags using XmlMatcher
      2. Attempts to parse the remaining content as JSON
      3. Validates toolCalls against Zod schema
      4. Extracts structured fields if JSON parsing succeeds
      5. Falls back to treating everything as freeform content if JSON fails

      The nextStepDecision values guide the TAEF execution:

      • 'continue': Proceed with next iteration
      • 'wait': Pause execution (rare in execution phase)
      • 'complete_item': Mark current todo item as complete
      • 'update_plan': Modify the execution plan

      Never throws; errors are handled gracefully with empty results.

    • Parses the raw string output from the planning LLM call.

      Parameters

      • output: string

        The raw string response from the planning LLM.

      Returns Promise<
          {
              intent?: string;
              plan?: string;
              thoughts?: string;
              title?: string;
              todoList?: TodoItem[];
              toolCalls?: ParsedToolCall[];
          },
      >

      A promise resolving to an object containing: - title (string, optional): Concise thread title - intent (string, optional): User's goal summary - plan (string, optional): Human-readable plan description - toolCalls (ParsedToolCall[], optional): Parsed tool call requests - todoList (TodoItem[], optional): List of execution steps - thoughts (string, optional): Extracted from tags

      The planning phase generates structured output including:

      • title: A concise thread title (<= 10 words)
      • intent: A summary of the user's goal
      • plan: A human-readable description of the approach
      • toolCalls: Structured tool call requests
      • todoList: A list of TodoItem objects representing the execution plan
      • thoughts: Content extracted from XML tags

      This method:

      1. Extracts thoughts from tags using XmlMatcher
      2. Attempts to parse the remaining content as JSON
      3. Validates toolCalls against Zod schema
      4. Validates todoList against Zod schema
      5. Falls back to section-based parsing if JSON fails

      The fallback section-based parsing looks for labeled sections like: "Title: ...", "Intent: ...", "Plan: ..." using regex patterns.

      Never throws; errors are handled gracefully with empty results.

    • Parses the raw string output from the synthesis LLM call.

      Parameters

      • output: string

        The raw string response from the synthesis LLM.

      Returns Promise<string>

      A promise resolving to the cleaned, final response string.

      The synthesis phase generates the final, user-facing response. This method typically just trims the output, as synthesis output is usually freeform text without structured components.

      Future enhancements might include:

      • Removing extraneous tags or markers
      • Formatting cleanup
      • Extracting specific sections if needed

      Never throws; always returns at least an empty string.