UCP LLM
ucp-llm contains helpers for turning UCM documents into LLM-friendly prompts and UCL command scaffolds. It focuses on token efficiency, deterministic mappings, and safe prompt composition.
Features
| Component | Description |
|---|---|
IdMapper |
Maps long BlockIds (blk_…) to short numeric IDs to save tokens, and converts UCL in both directions |
PromptBuilder |
Builds capability-scoped system instructions, task context, and rule sets for LLM agents |
presets |
Ready-made prompt configurations (basic editing, structure manipulation, etc.) |
Installation
[]
= { = "crates/ucp-llm" }
IdMapper
Token budgets collapse quickly when every UCL command references blk_a1b2…. IdMapper provides a deterministic mapping so prompts can use 1, 2, 3, … instead. Key APIs:
use IdMapper;
use ;
let mut doc = create;
let root = doc.root.clone;
let heading = doc.add_block?;
let mapper = from_document;
assert_eq!;
assert!;
let long = "EDIT blk_ff00000000000000000000 SET text = \"Hello\"";
let short = mapper.shorten_ucl;
assert_eq!;
Highlights:
- Deterministic ordering (root first, remaining blocks sorted by ID)
shorten_ucl/expand_uclfor round-tripping commandsdocument_to_prompthelper for hierarchical summariesestimate_token_savingsfor quick what-if analysis
PromptBuilder
PromptBuilder assembles the system/task instructions LLMs need to safely emit UCL.
use ;
let builder = new
.with_capability
.with_capability
.with_rule
.with_short_ids;
let system_prompt = builder.build_system_prompt;
let doc_context = "[1] heading1 - Intro\n [2] paragraph - Hello";
let final_prompt = builder.build_prompt;
Capabilities gate which command documentation is included (EDIT, APPEND, MOVE, DELETE, LINK, SNAPSHOT, TRANSACTION). Short-ID mode automatically updates rule text so the model knows IDs like 1, 2, 3 will appear.
Presets
use presets;
let editing = basic_editing; // EDIT/APPEND/DELETE
let structural = structure_manipulation;
let token_efficient = token_efficient;
Use these as starting points for common workflows.
When to Use ucp-llm
- Building an agent that reads a UCM document and must output UCL
- Preparing evaluation prompts for benchmarking
- Any time you need short IDs, consistent command references, or prebuilt rule sets for LLM instructions
Public API
pub use IdMapper;
pub use ;
See Also
- Getting Started › Concepts – background on BlockIds and deterministic IDs
- UCL Commands – reference for the actual command syntax