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:Step 1: Understand the Document
Step 2: Read Content
Step 3: Search for Content
Step 4: Locate Nodes for Tagging
locate command returns nodeId, matchStart, matchEnd, and matchText - everything an agent needs for precise annotation.
Step 5: Tag Nodes
tagUuid that links the tag to the node for provenance tracking.
Step 6: Create Structured Data
--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
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:--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:locatereturnsnodeId→ use withtag --node-idtagreturnstagUuid→ use withdata set-attribute --tag-uuiddata createreturnsid→ use withdata set-attribute --object-id
Use Node Type Filters
Filter by node type to get the right granularity:--type wordfor individual tokens (amounts, dates, names)--type linefor full lines of text--type paragraphfor 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
Usenode to verify a node’s content and context before tagging:
Command Reference
| Command | Mode | Purpose |
|---|---|---|
info | Read | Document summary |
stats | Read | Detailed statistics |
text | Read | Page text extraction |
grep | Read | Regex content search |
find | Read | Multi-criteria search |
locate | Read | Node discovery with match positions |
node | Read | Single node inspection |
tags | Read | List all tags |
tag | Write | Annotate a node |
data create | Write | Create data object |
data set-attribute | Write | Set attribute on data object |
audit | Read | Revision history |
