Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .changeset/37292-skill-knowledge-split.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
'@objectstack/skills': patch
---

docs(skills): `objectstack-ai` teaches the knowledge source `split` key and names the two keys retired beside it

Clause-②: no
Metadata-protocol: none

`skills/objectstack-ai/SKILL.md`, *Knowledge Sources (RAG)*:

- The object source's fields gain `split?`, and a passage teaches `split: { strategy, maxChars?, minChars? }`, an object-source key: `recursive` (the default) for prose, `markdown` for documents with headings, `whole` for short records only, since a document over the embedder's input budget is removed from the index and reported, never truncated. `maxChars` overrides the **Target chunk size** setting (`knowledge.chunk_target`, else 800), the embedder's input limit can lower it, and `whole` ignores it; `minChars` defaults to 200. Changing `split` re-splits a document only when the document next changes. The key applies to an adapter that declares `capabilities.chunks` (`memory`); one that does not (`ragflow`) receives whole documents, and `split` has no effect on it.
- It names the two keys retired with the splitter, and that each is refused when written: the `knowledge.chunk_overlap` setting (`400 UNKNOWN_KEY`; passages never overlap) and `KnowledgeChunk.metadata` (a parse error; a passage takes its document's `metadata`).
- The closing note that said chunking is not platform metadata is replaced: the service splits; top-K, score thresholds and rerankers are not source metadata and belong to the adapter or application code.

Paid for by deleting restatement in the same file, with the token ceiling unchanged (6801; the file now measures 6800):

- the pitfall "Indexing everything" (the `object` row's hygiene column says the same);
- the "Skills are your entry point" paragraph under the diagram (the frontmatter description, the `tools` row and *Platform agents* say the same);
- the incident sentence after `ai-skill-tool-unresolved`;
- the sentence saying what `os validate` confirms;
- the clause of the *App AI Blueprint* registration row repeating three facts stated in their own sections;
- four clauses that repeated the sentence beside them: "A skill names a platform tool or an `action_<name>`" (*Tool metadata*), "the user never picks from a roster…" (*Platform agents*), "without one the id is unresolvable" (*Wiring*), and "exposure is never automatic" (*Actions as AI Tools*).

`evals/skills-tools-knowledge.json`: a new case 9 asks for a Markdown handbook source on the in-memory adapter, split by section at 600 characters with overlapping passages; the expected answer writes `split: { strategy: 'markdown', maxChars: 600 }` and declines the overlap. Case 3 (RAGFlow) no longer says chunking is adapter config: its expected answer writes no `split`, because that adapter receives whole documents.
59 changes: 33 additions & 26 deletions skills/objectstack-ai/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ Agent → Skill → Tool
└─ Autonomous actor with role, instructions, and guardrails
```

**Skills are your entry point** — agents are platform-internal (reference
section at the bottom), so you extend the platform by authoring skills, and a
skill reaches tools by naming them.

---

## Skill Configuration
Expand Down Expand Up @@ -85,9 +81,7 @@ A `skill.tools[]` entry resolves against the union of four sources
own hint: no in-product turn registers it.

A name none of them resolves raises **`ai-skill-tool-unresolved`** (warning,
ADR-0078 advisory-first). The rule exists because one audited app shipped 10
fictional tools across 6 skills through `validate` / `lint` clean, and became a
copilot claiming abilities it did not have.
ADR-0078 advisory-first).

### Skill Example

Expand Down Expand Up @@ -149,7 +143,7 @@ You usually **don't author tool definitions by hand** for action invocation. An
tool named `action_<actionName>` **only when it opts in** — `ai.exposed: true`
(default `false`) plus an `ai.description` of ≥ 40 chars, refused by the parse
without it (ADR-0011). `registerActionsAsTools()` walks the opted-in ones;
exposure is never automatic, and there is no opt-out key.
there is no opt-out key.

Three action types dispatch headlessly:

Expand Down Expand Up @@ -243,8 +237,7 @@ collection for them — they are registered at runtime, and the ☁️
`@objectstack/service-knowledge` registers `IKnowledgeService` with the kernel and
each source at boot (`service.registerSource` still works later). The `adapter`
id resolves against an adapter plugin — `@objectstack/knowledge-memory`
(`'memory'`, dev/test) or `@objectstack/knowledge-ragflow` (`'ragflow'`);
without one the id is unresolvable.
(`'memory'`, dev/test) or `@objectstack/knowledge-ragflow` (`'ragflow'`).

| Property | Purpose |
|:---------|:--------|
Expand All @@ -260,7 +253,7 @@ without one the id is unresolvable.

| `source.kind` | Fields | Hygiene |
|:--------------|:-------|:--------|
| `object` | `object`, `contentFields[]` (min 1; `*` = every readable text field), `metadataFields?`, `where?` (ObjectQL `where` syntax) | `where` keeps drafts and archived rows out of the index; `contentFields` takes meaningful text only (never system fields or ids, `*` sparingly); project what you will filter on at query time (`status`, `owner_id`, `tags`) into `metadataFields` |
| `object` | `object`, `contentFields[]` (min 1; `*` = every readable text field), `metadataFields?`, `where?` (ObjectQL `where` syntax), `split?` (below) | `where` keeps drafts and archived rows out of the index; `contentFields` takes meaningful text only (never system fields or ids, `*` sparingly); project what you will filter on at query time (`status`, `owner_id`, `tags`) into `metadataFields` |
| `file` | `prefix` (storage prefix, e.g. `kb/handbooks/`), `mimeTypes?` | narrow the prefix instead of indexing a whole bucket |
| `http` | `urls[]`, `userAgent?` | enumerate URLs explicitly — there is no crawler |

Expand All @@ -283,17 +276,37 @@ export const supportKb: KnowledgeSource = KnowledgeSourceSchema.parse({
});
```

> **Chunking, top-K, score thresholds and rerankers are NOT platform metadata.**
> The spec scopes them out deliberately (`embedding.zod.ts`): they belong to the
> adapter (`adapterConfig`) or application code. The platform carries only the
> embed + vector primitives, so any RAG strategy can be built on top.
**Splitting (`split`, object sources only).** The knowledge service cuts each
document into passages for an adapter declaring `capabilities.chunks`
(`memory`). Any other adapter (`ragflow`) receives whole documents; `split` has
no effect on it. `split: { strategy, maxChars?, minChars? }`:

- `recursive` (default): cuts at blank lines, then line breaks, then sentence
ends. For prose.
- `markdown`: one section per heading, each passage embedded with its heading
path. For documents with headings.
- `whole`: one passage per document. For short records only: a document over
the embedder's input budget is removed from the index and reported, never
truncated.

`maxChars`, the longest passage in characters (`whole` ignores it), overrides
the **Target chunk size** setting (`knowledge.chunk_target`, else 800); the
embedder's input limit can lower it. Adjacent pieces shorter than `minChars`
(default 200) are merged. Changing `split` re-splits a document only when it
next changes.

Retired and refused: the `knowledge.chunk_overlap` setting (`400 UNKNOWN_KEY`;
passages never overlap) and `KnowledgeChunk.metadata` (parse error; a passage
takes its document's `metadata`).

Top-K, score thresholds and rerankers are not source metadata: they belong to
the adapter or application code.

---

## Tool metadata (`defineTool`) — not the default path

**Default: declare no tool records.** A skill names a platform tool or an
`action_<name>` (ladder above). ADR-0109: a `stack.tools` record "exists only for
**Default: declare no tool records.** ADR-0109: a `stack.tools` record "exists only for
AI-presentation refinement (Phase 2: LLM description, parameter narrowing, flow
exposure) and has no runtime reader until that lands"
(`packages/spec/src/stack.zod.ts:595-602`). Author one only to refine how an
Expand Down Expand Up @@ -362,10 +375,6 @@ there is **no top-level `temperature` / `maxTokens`** on an agent
door; a `state_machine` dead-end (`closed: []`) still makes the reached
state final for every writer (**objectstack-automation**
`references/state-machines-and-approvals.md`).
3. **Indexing everything.** A knowledge source without a `where` filter and
curated `contentFields` fills the index with drafts and boilerplate that
pollute retrieval. Source hygiene is the metadata's job; relevance tuning
belongs to the adapter.

---

Expand All @@ -375,7 +384,7 @@ there is **no top-level `temperature` / `maxTokens`** on an agent
|:--|:--|:--|
| Reusable skill | `src/skills/lead-qualification.skill.ts` | `defineSkill` — `instructions` + trigger conditions + a toolset where every name resolves; pick a `surface` |
| Knowledge source | `src/knowledge/sales-kb.ts` | `KnowledgeSourceSchema` metadata, registered at boot via `KnowledgeServicePlugin({ sources })` |
| Central registration | `defineStack({ skills: [...] })` | `agents` / `tools` / `skills` are the only AI stack collections — knowledge sources have none, agents are platform-supplied, and `tools` is not the default path |
| Central registration | `defineStack({ skills: [...] })` | `agents` / `tools` / `skills` are the only AI stack collections |

---

Expand All @@ -387,8 +396,7 @@ stack-authored agent is filtered out of `listAgents()`, refused outright by
`loadAgent()`, and 404s on chat. `AgentSchema`'s full field list is in
[references/_index.md](./references/_index.md).

The runtime ships **exactly two** agents, bound by *surface* — the user never
picks from a roster, the surface they are in selects the agent. **`ask`** is the
The runtime ships **exactly two** agents, bound by *surface*. **`ask`** is the
data product (≈ Claude Chat): conversational read / query / explore over records
plus running the business actions the app exposes, end-user audience,
RLS-bounded, canonical id `ask` (`ASK_AGENT_NAME`), and the implicit copilot for
Expand Down Expand Up @@ -451,8 +459,7 @@ os validate # Zod schema + CEL predicate validation + bindings (no artifact)
# or: os build # the same gates, plus emits dist/
```

It confirms the skill / tool metadata conforms to the protocol. This
domain has no CEL site — a model-registry `promptTemplate.system` / `.user` is
This domain has no CEL site — a model-registry `promptTemplate.system` / `.user` is
the `template` dialect (`{{var}}`); `ToolSchema` carries no expression field of
any kind. In a scaffolded project the gate is `npm run validate`. See
objectstack-platform → **Verify your work**.
Expand Down
12 changes: 11 additions & 1 deletion skills/objectstack-ai/evals/skills-tools-knowledge.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{
"id": 3,
"prompt": "Index our `kb_article` records (title and body) so the assistant can answer from them with RAG. Only published articles, and we want to filter by `category` at search time. We run RAGFlow.",
"expected_output": "Emits a `KnowledgeSourceSchema.parse({...})` record with `adapter: 'ragflow'` and `source: { kind: 'object', object: 'kb_article', contentFields: ['title', 'body'], metadataFields: ['category'], where: { published: true } }`, `refresh: { onRecordChange: true }`, registered at boot through `KnowledgeServicePlugin({ sources })`. Chunking / top-K / rerankers are adapter config, not platform metadata.",
"expected_output": "Emits a `KnowledgeSourceSchema.parse({...})` record with `adapter: 'ragflow'` and `source: { kind: 'object', object: 'kb_article', contentFields: ['title', 'body'], metadataFields: ['category'], where: { published: true } }`, `refresh: { onRecordChange: true }`, registered at boot through `KnowledgeServicePlugin({ sources })`. Top-K and rerankers are not source metadata, and no `split` key is written: the RAGFlow adapter receives whole documents, so `split` would have no effect.",
"files": [],
"assertions": {
"must_contain": ["KnowledgeSourceSchema", "contentFields", "metadataFields", "where", "KnowledgeServicePlugin"],
Expand Down Expand Up @@ -80,6 +80,16 @@
"must_contain": ["elicitation", "declined", "cancelled", "timed_out", "service_account"],
"must_not_contain": ["recordId, confirm: true"]
}
},
{
"id": 9,
"prompt": "Index our `policy_doc` records (`title`, `body`) for the assistant with the in-memory adapter. Each body is a long Markdown handbook with headings; answers should cite one section, at most 600 characters, and neighbouring passages should overlap by 100 characters.",
"expected_output": "Emits a `KnowledgeSourceSchema.parse({...})` record with `adapter: 'memory'` (the adapter that takes the service's passages) and `source: { kind: 'object', object: 'policy_doc', contentFields: ['title', 'body'], split: { strategy: 'markdown', maxChars: 600 } }`: one section per heading, each passage embedded with its heading path, 600 characters at most unless the embedder's input limit is lower. Declines the overlap: passages never overlap, and the `knowledge.chunk_overlap` setting is retired (a write naming it is refused `400 UNKNOWN_KEY`), so it writes no overlap key and no `chunkSize`.",
"files": [],
"assertions": {
"must_contain": ["split", "strategy", "markdown", "maxChars"],
"must_not_contain": ["chunkSize", "chunkOverlap", "overlap: 100"]
}
}
]
}
Loading