Skip to main content
AI agents (Claude Code, custom tooling, etc.) can use kdx document commands to programmatically analyze, search, annotate, and extract structured data from complex documents. The CLI’s JSON output format and composable command design make it ideal for agent workflows.

The Agent Workflow

A typical agent workflow follows this pipeline:
Each step narrows focus from document-level understanding down to precise node-level annotation.

Step 1: Understand the Document

The agent learns how many pages, nodes, tags, and data objects exist before diving in.

Step 2: Read Content

The agent reads page content to understand what the document contains and identify sections of interest.

Step 3: Search for Content

These commands return JSON with node IDs and match positions for further processing.

Step 4: Locate Nodes for Tagging

The locate command returns nodeId, matchStart, matchEnd, and matchText - everything an agent needs for precise annotation.

Step 5: Tag Nodes

The output includes a tagUuid that links the tag to the node for provenance tracking.

Step 6: Create Structured Data

The --tag-uuid flag links the attribute back to its source node in the document.

Example: Processing a Financial Document

This walkthrough shows how an agent would process a 50-page financial filing to extract key figures.

1. Assess the Document

The agent sees 50 pages with no existing tags - a fresh document to process.

2. Find Key Sections

3. Read the Revenue Page

4. Locate Specific Values

5. Tag and Create Data

Output Format

All commands produce JSON Lines (JSONL) by default - one JSON object per line. This streams well and is easy for agents to parse line-by-line:
Use --pretty for human-readable debugging:

Best Practices for Agent Developers

Limit Results

Always use --max to prevent overwhelming output on large documents:

Focus by Page

Use --page to work on one page at a time instead of the entire document:

Chain Commands

The intended workflow chains outputs from one command into the next:
  1. locate returns nodeId → use with tag --node-id
  2. tag returns tagUuid → use with data set-attribute --tag-uuid
  3. data create returns id → use with data set-attribute --object-id

Use Node Type Filters

Filter by node type to get the right granularity:
  • --type word for individual tokens (amounts, dates, names)
  • --type line for full lines of text
  • --type paragraph for paragraph-level content

Verify Before Writing

Use read-only commands (info, stats, text, grep, locate, node) to understand the document before using write commands (tag, data create, data set-attribute).

Inspect Nodes Before Tagging

Use node to verify a node’s content and context before tagging:

Command Reference