tree
Structured data (nested objects and lists), such as a large tool result, stored once and passed by its handle.
At a glance
- Stored as: a handle (
tree-…), kept once by its content and referred to by that handle. - Read in parts: by a range of items or by path.
- Media formats:
json. - Edited by: JSON Pointer operations.
- Search: by passage, so full-text and similarity search rank a value by its best passage.
Writing
Write a JSON object or array; YAML is accepted too. The top level is always an object or a list, so any other value is refused. Keys keep the order you wrote them in, but two trees with the same content in another key order share one handle.
A value inside the tree can be a handle of its own: a PDF, an image, a recording, a file or another tree
in a result. Write it as {"__dtype__": "pdf-…"}, or as the exact <attachment id="pdf-…"/> marker an
agent sees. Any other string is text, even one that looks like a handle.
In an entity's record a tree is written as its handle, {"__dtype__": "tree-…"}. A small one also
carries its data, as {"__dtype__": "tree-…", "__value__": …}, so it can be read without another call.
Written as
A JSON object whose schema format is tree.
__dtype__: str__value__: optional Any
Reading
get_content reads part of a tree with path, range, query or hql:
pathpicks values: a name for each level, joined by., each with selectors after it.[*]is every item of a list,[3]one item ([-1]the last),[1,4,7]those items, and[field op value]the items whose field compares with=,==,!=,>,>=,<or<=. Example:appointments[*][status=confirmed].id.=on text ignores case and==does not;>and<compare numbers only. A path can also be one JSON Pointer, such as/rows/3/name. A path that cannot be parsed is refused with the forms a path takes, and a pointer that matches nothing is answered with the top-level keys.rangecounts items of the list atpath, or of the top-level list without one, from 0 and inclusive:path="/rows"withrange=[20, 39]. These are the indexes a shortened view names. Whenpathpoints at a text of several lines, such as the text of a page,rangecounts that text's lines instead, from 1.querysearches the values underpath, in any mode.grepmatches onekey: valueline per value, tagged with its pointer; for whole matching records usebm25orhybrid.hqlfilters, groups, sorts or counts the list atpathas rows, with the steps of a query after its source:status = 'confirmed' | group by status | count(*) as n. See querying data.
Add as_handle to keep the selection as a new tree and pass its handle on instead of copying the rows.
get_media gives the whole tree as a JSON file to download.
A tree too large to show is shown in part: a list as its first items and the index range of the rest, an object as an outline of its keys and values.
Querying
HQL does not search inside trees: a tree in a field is not indexed for text. Find the records that hold one, then read it with get_content. Structured tool results are kept in the content of the tool's message as trees:
Message | role = "tool" AND content.dtype = "tree" | select id, created_at | limit 20
Every operator is in the HQL reference.
Editing
edit changes a tree with JSON Pointer ops, which address the data as path
reads it: {"op": "replace", "path": "/rows/3/status", "value": "cancelled"}. A result of a named type
keeps its type. The result is a new tree under a new handle.
In agent tools
A tool's structured result reaches the agent as a tree: shown whole when it fits, otherwise in part with
its <attachment id="tree-…"/> marker. To pass part of it to another tool without copying it, write the
argument as <ref id="tree-…" path="/rows/3"/>, which stands for the value at that pointer with its type.
For a selection of many rows, keep it with as_handle and pass the new handle. See
values and handles.
Operations
Through the dtypes resource: