> ## Documentation Index
> Fetch the complete documentation index at: https://docs.eigenpal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Share knowledge, rules, templates and skills

> Define reusable resources in TypeScript, capture their accompanying files from Git, and use them through agent tools or an optional filesystem sandbox.

Define a shared resource in `resource.ts` and import it into an agent. EigenPal
captures the accompanying files from the agent's Git commit. You do not need to
import each document or maintain a version-string dependency map.

## Resource directories

```text theme={null}
resources/
  knowledge/tax-policy/
    resource.ts
    README.md
    rates.csv
  rules/invoice-style/
    resource.ts
    RULE.md
  templates/invoice-summary/
    resource.ts
    template.md
  skills/invoice-checks/
    resource.ts
    SKILL.md
    scripts/check.py
```

`resource.ts` is a required filename, with a default export. Directory names and
import aliases are your choice. Factories accept `name` and optional `description`;
`createTemplate` also accepts an optional `file`.

## Knowledge

```ts resources/knowledge/tax-policy/resource.ts theme={null}
import { createKnowledge } from '@eigenpal/automations';
export default createKnowledge({ name: 'Tax policy', description: 'VAT reference material.' });
```

Put reference files beside the declaration, including nested directories. Knowledge
supports Markdown, UTF-8 text, CSV, JSON, PDF, DOCX and XLSX. PDF reading requires a
text layer and the deployment's text extractor; scanned-only documents need OCR
before you add them. Documents are reference data, not extra instructions.

## Rules

```ts resources/rules/invoice-style/resource.ts theme={null}
import { createRule } from '@eigenpal/automations';
export default createRule({ name: 'Invoice style' });
```

Put reusable instructions in `RULE.md`. EigenPal adds them to the agent's prompt
in both execution modes. Companion files remain available through resource tools.

## Templates

```ts resources/templates/invoice-summary/resource.ts theme={null}
import { createTemplate } from '@eigenpal/automations';
export default createTemplate({ name: 'Invoice summary' });
```

Provide exactly one conventional `template.md`, `template.docx` or `template.xlsx`.
For another filename, set `file: 'summary.docx'`. The file must remain inside the
resource directory. Missing or ambiguous template entries fail validation.

Markdown templates use `{{supplier}}` and nested `{{customer.name}}` fields;
Liquid control tags are unsupported. Office templates use single braces:

* DOCX scalar: `{supplier}`. Loop: `{#items}{name}: {amount}{/items}`.
  Conditional: `{#approved}Approved{/approved}`.
* XLSX scalar: `{supplier}`. Table columns: `{table:items.name}` and
  `{table:items.amount}`.

Template tools do not support raw XML insertion or XLSX image placeholders.
Filling creates a run artifact; it does not overwrite the original template.

## Skills

```ts resources/skills/invoice-checks/resource.ts theme={null}
import { createSkill } from '@eigenpal/automations';
export default createSkill({ name: 'Invoice checks' });
```

Keep `SKILL.md` and its scripts, references and helper assets in the directory.
Skills require `.withFilesystem({ skills })`. The agent receives a catalog and
reads the skill instructions as needed. Helpers run only when the agent invokes
them inside the filesystem sandbox; attaching a skill does not execute its scripts.

## Example companion files

For a minimal working resource set, add these beside the declarations above:

```text resources/knowledge/tax-policy/README.md theme={null}
Standard VAT rate: 20%. Calculate tax on the subtotal and round to two decimal places.
```

```text resources/rules/invoice-style/RULE.md theme={null}
Use the supplied supplier name. Report currency amounts to two decimal places.
```

```text resources/templates/invoice-summary/template.md theme={null}
Supplier: {{supplier}}
Total: {{total}}
```

```text resources/skills/invoice-checks/SKILL.md theme={null}
# Invoice checks
Read the invoice and verify its arithmetic before reporting the result.
Use the sandbox shell for any scripts in this skill's scripts directory.
```

## Attach resources

```ts agents/invoice/agent.ts theme={null}
import { createAgent } from '@eigenpal/automations';
import policy from '../../resources/knowledge/tax-policy/resource.ts';
import style from '../../resources/rules/invoice-style/resource.ts';
import summary from '../../resources/templates/invoice-summary/resource.ts';
import checks from '../../resources/skills/invoice-checks/resource.ts';

export const reviewer = createAgent({
  name: 'Invoice reviewer',
  instructions: 'Use the tax policy to review the invoice, then fill its summary.',
  resources: { policy, style, summary },
});

// Remove this extension to export a normal agent with the same portable resources.
export default reviewer.withFilesystem({ cwd: null, skills: { checks } });
```

The normal `reviewer` uses knowledge, rules and templates without a filesystem.
The default filesystem variant also receives their original directories and the
`checks` skill. Skills cannot go in the normal agent's `resources` property.

## Built-in resource tools

The model uses the imported alias, such as `policy`, as the `resource` argument:

* **`resource_list({ resource })`**: list captured paths.
* **`resource_search({ resource, query })`**: case-insensitive literal search,
  up to ten excerpts with paths and character offsets.
* **`resource_read({ resource, path, offset?, limit? })`**: read extracted text,
  up to 12,000 characters per call. Use `nextOffset` to page through long files.
  Binary companion files can produce downloadable artifacts.
* **`template_inspect({ resource })`**: inspect placeholders.
* **`template_fill({ resource, data, filename? })`**: fill the template and register
  a downloadable artifact, returning `fileId` and `name`.

EigenPal restricts aliases in these tool schemas to attached resources. Templates
and rules also expose companion files through browse tools. Model context contains
a small catalog rather than all knowledge text. Both agent modes get the tools.
These are platform operations; custom callbacks cannot call them as JavaScript functions.

Filesystem copies live under `/workspace/agent/.eigenpal-resources/<alias>/` even
when `cwd` changes or is `null`. They do not overwrite the agent's working files.

## Capture and release

Capture recursively excludes hidden files/directories, dependency folders,
`resource.ts`, package manifests/locks and private-key extensions. It preserves
asset bytes and executable flags. The compiler allows at most 128 captured files
and 2 MiB of source, with additional bounded compiled resource data. Resource maps
allow up to 32 aliases. Use an external source for larger collections.

Validate with `eigenpal agents validate` from the agent package. Resource factories
do not read your host disk; the deployment's source capture resolves their directories.
The public low-level `compileAgent` function expects already captured resource data.

An agent release pins resource content. Releasing a changed resource alone does
not update existing agent releases; release the agent again to capture the change.
Historical runs and supported resumes retain their resource snapshot.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.