# Create Library Item Tool

`library_create` creates a document from blocks in an existing Library folder. Folders are created with `library_create_folder`.

## When to Use

The agent uses it to save new content. Before creating, it lists the folders with `library_list` and searches with `library_search`, then puts the document in the folder it belongs to. A new folder is made first with `library_create_folder`. Existing documents are edited with the block tools; names and icons are changed with `library_update`.

`load_skill("keeping-a-library")` says how to choose where a document goes and how to grow and link documents.

## Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `name` | string | Yes | The item's name. A document's name is its title, shown in the Library tree and as the heading above its blocks, so the blocks must not repeat it as a heading |
| `path` | string[] | Yes | Required. Folder path as folder slugs or ids from the root; `[]` is the root. Every folder must already exist |
| `blocks` | array | No | The document's blocks, in order. Omit for an empty document |
| `icon` | string | No | Icon drawn in the Library tree, stored as given: a Phosphor icon as an Iconify id such as `ph:notebook`. Omit for the default icon |
| `color` | string | No | Icon color, stored as given: a hex code `#rrggbb`. Omit for the default color |

A block is BlockNode JSON: an object whose `type` names the block, with an optional `id` (10 letters and digits). A block keeps the `id` it states; a missing or malformed id gets a fresh one, and an id repeated within the document is replaced after its first holder. `library_get` returns the ids stored.

`load_skill("library-documents")` gives every block type with its fields, and `get_docs("documents")` says what a document can contain, including pages drawn from HTML or SVG. The agent reads `get_docs("documents")` before writing to a document the first time. A malformed block is refused with a message naming what is wrong.

## Returns

| Field | Type | Description |
|-------|------|-------------|
| `item` | object | The item: `id`, `slug`, `name`, `kind` (`document`, `folder` or `file`), `path` (folder slugs; `null` when unfiled), `path_names`, `icon`, `color`, `ai_access_policy`, `revision`, `created_at`, `updated_at`, `url`; a file adds `object_id`, `media_kind`, `content_type`, `filename`, `size_bytes` |

The blocks, with the ids they were stored under, are read back with `library_get`.

`url` is the item's link. The agent gives it to the user when it reports the change, labelled with the item's name rather than its folder path.

## Example Scenario

```json
{
  "name": "Q1 Research Notes",
  "path": ["projects-ab12cd"],
  "blocks": [
    { "type": "heading", "level": 2, "content": [{ "type": "text", "text": "Findings" }] },
    { "type": "paragraph", "content": [{ "type": "text", "text": "Churn fell 4%." }] }
  ]
}
```

## Notes

- A call without `path`, or with `path: null`, is refused: ``A document needs a place: give `path`, with [] for the root.``
- A folder on `path` that does not exist is refused, and nothing is created: `Folder 'nilo' not found. List the folders with library_list to find the path.` A folder's name is not a path segment
- Markdown `content` is not accepted; write blocks
- The new document's blocks are its first version
- Risk: write
