diff --git a/CHANGELOG.md b/CHANGELOG.md
index a480174bb..ed591d3f3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -74,6 +74,10 @@ The backend (`fastapi_backend`) and the frontend (`nextjs-frontend`) are version
language model, logged in the activity ledger; with `apply`, an editor's sure answer sets the content type, suggests
the topic or adds the tag (`POST /classify`, the MCP and assistant tool `classify`;
[Classifying](docs/processing.md#classifying)).
+- **Classify in workflows.** A Classify node on the workflow canvas picks one of your labels, a content type or a topic
+ for the asset (or for what came in) and passes on the choice, how sure and every label ranked, for a Condition
+ or Switch to branch on; set to act, a sure answer sets the content type, suggests the topic or adds the tag
+ ([Workflows and the canvas](docs/processing.md#workflows-and-the-canvas)).
## 0.13.0 October 16, 2026 {id="0.13.0"}
diff --git a/README.md b/README.md
index 83d7342d1..99d840496 100644
--- a/README.md
+++ b/README.md
@@ -61,14 +61,16 @@ Everything below is built and merged, and each item links to the checks that pro
measured numbers ([requirements and their checks](docs/requirements.md)). Work that is still in a pull request is
listed under [In progress](#in-progress), and what comes next under [Planned](#planned).
-- **Connect your agents.** Lens is an MCP server (`/mcp`): agents search, read assets' text and notes, cite exact
- moments, find similar content, explore the graph with Cypher or SPARQL or browse it as folders and files, suggest
- topics and graph changes, edit and merge entities and topics (with undo), write notes and make podcasts. They sign in
- with OAuth and see only what their person may read; the account menu copies the MCP address in one click. A namespace
- can also have an MCP server of its own (`/mcp/`) and answer OpenAI's chat completions API for any app,
- cited from that namespace alone, each off until its owner turns it on, with API keys that open that one namespace and
- nothing else. The same folders and files can be mounted read-only over S3, WebDAV, NFS or SMB, so file managers and
- scripts read Lens too. The web app runs on the same REST API, so an agent can do what a person can.
+- **Connect your agents.** Lens is an MCP server (`/mcp`): agents search, find assets by face, voice, entity, topic,
+ type, content type or date in one call, classify an asset or a text with the decision model, read assets' text and
+ notes, cite exact moments, find similar content, explore the graph with Cypher or SPARQL or browse it as folders and
+ files, suggest topics and graph changes, edit and merge entities and topics (with undo), write notes and make
+ podcasts. They sign in with OAuth and see only what their person may read; the account menu copies the MCP address in
+ one click. A namespace can also have an MCP server of its own (`/mcp/`) and answer OpenAI's chat
+ completions API for any app, cited from that namespace alone, each off until its owner turns it on, with API keys that
+ open that one namespace and nothing else. The same folders and files can be mounted read-only over S3, WebDAV, NFS or
+ SMB, so file managers and scripts read Lens too. The web app runs on the same REST API, so an agent can do what a
+ person can.
([MCP](docs/mcp.md), [one namespace's MCP server](docs/mcp.md#one-namespaces-mcp-server),
[chat completions](docs/api.md#chat-completions-for-any-app), [API](docs/api.md),
[the graph as files](docs/file-tree.md), [authentication](docs/authentication.md);
@@ -134,7 +136,8 @@ listed under [In progress](#in-progress), and what comes next under [Planned](#p
people review on the Timeline page (and Latest on Home), marking what they've seen. Automations act on that stream, on
a schedule, at a time or when their own webhook is called: they test conditions, then tell you in your own chat app,
ask the model or the agent, use a tool, call a web address (its credentials kept sealed), run a workflow, pipeline or
- routine, or change assets and notes. Anything that reaches outside Lens or changes more than what set it off asks
+ routine, or change assets and notes. A Classify node in a workflow sorts an asset into labels, content types or
+ topics, acting only on a sure answer. Anything that reaches outside Lens or changes more than what set it off asks
first, until you let it run on its own: on the Approvals page or, for a change inside Lens, with a yes in the chat it
told you in; agents can decline an approval but never give one. Each automation has limits and budgets, and agents
make, try and run them over MCP and in the assistant, or draft one from a sentence; the studio to draw them in the web
@@ -196,8 +199,6 @@ options most people leave as they are stay folded. ([Components](docs/components
These are open pull requests, not yet part of Lens:
-- **Finding:** resources found by face, voice, entity, topic, type, content type and date
- ([#398](https://github.com/adeelahmad/lense/pull/398)).
- **The assistant** answering questions about Lens itself, from its docs and this server
([#400](https://github.com/adeelahmad/lense/pull/400)).
- **Chat:** a conversation exported as Markdown, PDF or JSON ([#474](https://github.com/adeelahmad/lense/pull/474)).
diff --git a/docs/processing.md b/docs/processing.md
index 17b4d2392..5685b9b0c 100644
--- a/docs/processing.md
+++ b/docs/processing.md
@@ -362,7 +362,9 @@ does), the topic is suggested for it, waiting for someone to accept it (one it a
from stays as it is), or the label given is added as a tag (at most 40 characters). `applied` says which, and it is
in the audit log. The MCP and assistant tools never apply; the assistant can then suggest the topic (`suggest_topic`).
-Planned, not built yet: a classify step in workflows, classifying many assets at once, and labels with examples.
+Workflows classify too, with a Classify node ([Workflows and the canvas](#workflows-and-the-canvas)), so a pipeline
+can classify every asset it runs on. Planned, not built yet: classifying many assets at once from the API, and labels
+with examples.
## Background work
@@ -593,11 +595,14 @@ node passes what it makes along its connections.
regular expressions (`TYPE: pattern`); Extract entities (LLM) asks the model for structured entities and keeps,
corrects or adds to any passed in; Merge joins lists; Save entities makes them the asset's entities (people's
corrections kept) and redoes keywords and chapters.
-- **AI and logic:** LLM prompt (a prompt template, with what came in as `{{ input }}`), Pick (a path like
- `action_items.0.text`), Condition (yes and no branches; one test, or a [match tree](automations.md#match-trees) of
- several) and Merge.
-- **Keeping results:** Save output (`outputs.`), Set field (a custom field, kept in the metadata history) and
- Save entities.
+- **AI and logic:** LLM prompt (a prompt template, with what came in as `{{ input }}`), Classify (which of your
+ labels, the content types or the namespace's topics fits the asset, or what came in as text; it passes on `choice`,
+ `confidence`, `sure` and `ranked`, so a Condition or Switch can branch on them; [classifying](#classifying)), Pick
+ (a path like `action_items.0.text`), Condition (yes and no branches; one test, or a
+ [match tree](automations.md#match-trees) of several) and Merge.
+- **Keeping results:** Save output (`outputs.`), Set field (a custom field, kept in the metadata history), Save
+ entities, and a Classify node set to act on a sure answer (it sets the content type, suggests the topic or adds the
+ tag; a try on the canvas only says what it would do).
A pipeline runs a workflow as a Workflow step, pinned to the workflow's published version when the run is queued
(`POST /api/v1/workflows/{id}/run` runs one on an asset). Pipelines can be drawn on the canvas too: a connection
diff --git a/docs/requirements.md b/docs/requirements.md
index d3670a383..6fd4395cb 100644
--- a/docs/requirements.md
+++ b/docs/requirements.md
@@ -52,6 +52,8 @@ request, to another check that proves the same thing; loosening a requirement or
| Requirement | Checks |
|---|---|
| An MCP server at `/mcp`: agents search, read assets' text and notes, and cite exact moments | [test_mcp.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_mcp.py) `test_search_and_cite`, `test_reading_recordings`, `test_note_tools` |
+| Agents find assets by face, voice, entity, topic, type, content type and date in one call, each with the moments that match | [test_find.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_find.py) `test_by_face_voice_entity_and_date`, `test_by_topic_type_content_type_and_text`, `test_find_for_agents` |
+| Agents classify an asset or a text against labels, content types or topics with the decision model, acting only on a sure answer | [test_classify.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_classify.py) `test_labels_given_and_what_the_model_reads`, `test_vocabularies_and_applying_a_sure_answer`, `test_agents_classify` |
| Agents find similar content | [test_mcp.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_mcp.py) `test_search_and_cite`; [test_similar.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_similar.py) `test_like_a_text_by_its_key_words`, `test_like_a_resource_by_words_topics_and_entities` |
| Agents explore the graph with Cypher or SPARQL, or browse it as folders and files | [test_mcp.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_mcp.py) `test_graph_tools`, `test_sparql`; [test_file_tree.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_file_tree.py) `test_agents_browse_it_over_mcp` |
| Agents suggest topics and graph changes, and edit and merge entities and topics | [test_mcp.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_mcp.py) `test_topic_tools`, `test_editing_topics_and_entities` |
@@ -155,6 +157,7 @@ request, to another check that proves the same thing; loosening a requirement or
| Requirement | Checks |
|---|---|
| Pipelines and workflows on a canvas | [test_workflows.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_workflows.py) `test_workflows_run_in_pipelines_drawn_as_graphs`; [workflow-canvas.test.ts](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/workflow-canvas.test.ts); [journeys.mjs](https://github.com/adeelahmad/lense/blob/main/ci/clicks/journeys.mjs) `pipeline-create`, `workflow-create` |
+| A Classify node in workflows chooses from labels, content types or topics, and acting on a sure answer keeps something | [test_classify.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_classify.py) `test_a_workflow_classifies`; [workflow-flow.test.ts](https://github.com/adeelahmad/lense/blob/main/nextjs-frontend/__tests__/workflow-flow.test.ts) `chooses from labels, content types or topics, and acting on a sure answer keeps something` |
| Routines on a schedule | [test_routines.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_routines.py) `test_routines_are_checked_and_run_when_due`, `test_schedules`; [journeys.mjs](https://github.com/adeelahmad/lense/blob/main/ci/clicks/journeys.mjs) `routine-create`; [baseline.json](https://github.com/adeelahmad/lense/blob/main/ci/clicks/baseline.json) `routine-create` ≤ 2 clicks |
| Batch runs over a collection | [test_batches.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_batches.py) `test_collections_and_batches` |
| Notifications to webhooks, Slack, Discord and Matterbridge | [test_notifications.py](https://github.com/adeelahmad/lense/blob/main/fastapi_backend/tests/api/test_notifications.py) `test_owners_manage_targets_and_a_test_is_signed`, `test_runs_that_end_are_sent_once_to_matterbridge` |
diff --git a/fastapi_backend/app/domain/workflows.py b/fastapi_backend/app/domain/workflows.py
index 3f0b07474..d6957eb39 100644
--- a/fastapi_backend/app/domain/workflows.py
+++ b/fastapi_backend/app/domain/workflows.py
@@ -16,6 +16,9 @@
- `field`: sets a custom field of the recording to the value, checked like an edit (and kept in its history).
- `save_entities`: makes the entities passed in the recording's entities (in place of what analyze found), with
people's corrections kept, then redoes keywords and sections as analyze does.
+- `classify`: which of some labels (or the content types, or the namespace's topics) fits the asset, or what came
+ in as text, as classify.py says: passes on {choice, confidence, sure, ranked, by}. With `apply` it acts on a sure
+ answer (sets the content type, suggests the topic, adds the tag), so it keeps something.
Positions are only for the canvas.
@@ -26,11 +29,14 @@
from __future__ import annotations
+import json
import re
from . import (
analyze,
automation_nodes,
+ classify as classifymod,
+ decide,
fields as fieldmod,
flow,
llm,
@@ -44,7 +50,7 @@
)
R = store.R
-OWN_NODES = ("llm", "extract_rules", "extract_llm", "output", "field", "save_entities")
+OWN_NODES = ("llm", "extract_rules", "extract_llm", "classify", "output", "field", "save_entities")
TERMINAL = {"output", "field", "save_entities", "apply_changes"}
OPS = flow.OPS
OWN_CONFIG = {
@@ -54,6 +60,7 @@
"output": {"key"},
"field": {"field"},
"save_entities": set(),
+ "classify": {"labels", "vocabulary", "question", "of", "apply"},
}
ENTITY_TYPES = ("PERSON", "ORG", "PRODUCT", "PLACE", "EVENT", "WORK", "TERM", "DATE", "NUMBER")
PATH_RX = flow.PATH_RX
@@ -131,6 +138,29 @@ def _check_config(db, nid, t, cfg):
fieldmod.get(db, int(cfg.get("field") or 0))
except (KeyError, TypeError, ValueError):
raise ValueError(f"field node {nid}: choose a custom field") from None
+ elif t == "classify":
+ _check_classify(nid, cfg)
+
+
+def _check_classify(nid, cfg):
+ labels, vocab = cfg.get("labels"), cfg.get("vocabulary")
+ if (labels is None) == (vocab is None):
+ raise ValueError(f"classify node {nid}: give labels, or choose content types or topics")
+ try:
+ if vocab is not None and vocab not in classifymod.VOCABULARIES:
+ raise ValueError(f"choose from {' or '.join(classifymod.VOCABULARIES)}")
+ if labels is not None:
+ if not isinstance(labels, list):
+ raise ValueError("labels are lines like science: research and medicine")
+ classifymod._labels(labels)
+ except ValueError as e:
+ raise ValueError(f"classify node {nid}: {e}") from None
+ if cfg.get("question") is not None and not isinstance(cfg["question"], str):
+ raise ValueError(f"classify node {nid}: the question is text")
+ if cfg.get("of", "resource") not in ("resource", "input"):
+ raise ValueError(f"classify node {nid}: it classifies the asset or what comes in")
+ if cfg.get("apply") and cfg.get("of") == "input":
+ raise ValueError(f"classify node {nid}: only the asset's classification can be acted on")
def _check_types(nid, cfg):
@@ -366,6 +396,8 @@ def _run_node(r, f, node, value, vals):
if after != (row.get("fields") or {}):
metadata.save_fields(db, cfg, rid, after, r.extra["by"])
r.say(f"set {fd['label']}")
+ elif t == "classify":
+ return {"out": _classify(r, c, upstream, name)}
elif t == "save_entities":
if not isinstance(value, list):
raise ValueError(f"{name}: needs a list of entities")
@@ -376,6 +408,27 @@ def _run_node(r, f, node, value, vals):
return {}
+def _classify(r, c, upstream, name):
+ """A classify node: the asset, or what came in as text."""
+ rid, text, space = r.extra["rid"], None, None
+ if c.get("of") == "input": # its topics are the recording's namespace's
+ text = upstream if isinstance(upstream, str) else json.dumps(upstream, ensure_ascii=False, default=str)
+ rid, space = None, r.db.values("SELECT VALUE space FROM $r", r=R("recording", int(rid)))[0]
+ try:
+ res = classifymod.classify(
+ r.db, r.cfg, rid=rid, text=text, labels=c.get("labels"), vocab=c.get("vocabulary"), question=c.get("question"),
+ apply=bool(c.get("apply")) and not r.dry, user=r.extra.get("by"), space=space,
+ ) # fmt: skip
+ except decide.Undecided as e:
+ raise ValueError(f"{name}: nothing could answer ({e})") from None
+ sure = f"{round(res['confidence'] * 100)}% sure"
+ if c.get("apply") and r.dry and res["sure"]:
+ r.say(f"{name}: {res['choice']} ({sure}); would act on it")
+ else:
+ r.say(f"{name}: {res['choice']} ({sure}){'; ' + res['applied'].replace('_', ' ') if res['applied'] else ''}")
+ return {k: v for k, v in res.items() if k not in ("vocabulary", "question", "applied") and v is not None}
+
+
RUN_BY = {"graph": "organises the graph; a routine runs it", "event": "is what an automation does; its automation runs it"}
@@ -441,7 +494,8 @@ def _fit(f, v):
KITS = {
"recording": flow.Kit(
"recording", OWN_NODES, OWN_CONFIG, _check_config, _run_node, TERMINAL - {"apply_changes"},
- "a workflow needs an output, field or save entities node, or it keeps nothing",
+ "a workflow needs an output, field or save entities node (or a classify node that acts), or it keeps nothing",
+ keeps=lambda n: n["type"] == "classify" and bool((n.get("config") or {}).get("apply")),
),
"graph": flow.Kit(
"graph", organize.OWN_NODES, organize.CONFIG, _check_config, organize.run_node, {"apply_changes"},
diff --git a/fastapi_backend/tests/api/test_classify.py b/fastapi_backend/tests/api/test_classify.py
index 23fe170f1..e796020a4 100644
--- a/fastapi_backend/tests/api/test_classify.py
+++ b/fastapi_backend/tests/api/test_classify.py
@@ -173,3 +173,56 @@ def test_agents_classify(client, db, cfg, env, jev):
assert summary == "Classified as science (70% sure)" and got["sure"] is False
with pytest.raises(ValueError, match="isn't available"):
box.t_classify(recording_id=env["call"], labels=["a", "b"])
+
+
+def test_a_workflow_classifies(client, db, cfg, env, jev):
+ from app.domain import workflows
+
+ ep2 = env["ep2"]
+
+ def node(nid, t, **config):
+ return {"id": nid, "type": t, "config": config}
+
+ def graph(*nodes):
+ return {"nodes": [node("in", "input"), *nodes], "edges": [{"source": a["id"], "target": b["id"]} for a, b in zip(
+ [node("in", "input"), *nodes], nodes, strict=False
+ )]} # fmt: skip
+
+ # what it passes on goes on to the next node; one that acts on a sure answer keeps something by itself
+ desk = node("c", "classify", labels=["security: exploits and attacks", "health"], question="Which desk?")
+ wid = workflows.create(db, "Desk", graph(desk, node("o", "output", key="desk")))
+ jev.answer = {"type": "choice", "choice": "security", "confidence": 0.9, "probabilities": {"security": 0.9, "health": 0.1}}
+ said = []
+ workflows.run(db, cfg, ep2, wid, say=said.append)
+ out = db.one("SELECT * FROM $o", o=R("output", f"{ep2}-desk"))["value"]
+ assert (out["choice"], out["sure"], out["by"]) == ("security", True, "jev") and [x["label"] for x in out["ranked"]] == [
+ "security",
+ "health",
+ ]
+ assert "Which desk?" == jev.seen[-1][1]["questions"]["q"]["instructions"] and any("security (90% sure)" in s for s in said)
+ acts = node("c", "classify", vocabulary="topic", apply=True)
+ wid = workflows.create(db, "Topics", graph(acts))
+ jev.answer = {"type": "choice", "choice": "Gene therapy", "confidence": 0.9, "probabilities": {"Gene therapy": 0.9}}
+ # a try keeps nothing
+ tried = workflows.try_graph(db, cfg, graph(acts), rid=ep2)
+ assert tried["error"] is None and any("would act on it" in s for s in tried["log"])
+ assert not [t for t in topics.of_recording(db, ep2) if t["source"] == "classify"]
+ workflows.run(db, cfg, ep2, wid)
+ assert [(t["label"], t["status"]) for t in topics.of_recording(db, ep2) if t["source"] == "classify"] == [("Gene therapy", "suggested")]
+ # what came in, as text
+ text = node("c", "classify", labels=["question", "statement"], of="input")
+ tried = workflows.try_graph(
+ db, cfg, graph(node("t", "template", template="Is it on Friday?"), text, node("o", "output", key="k")), rid=ep2
+ )
+ assert tried["error"] is None and "Is it on" in json.loads(jev.seen[-1][1]["state"])["text"]
+ # checked when saved
+ for bad, why in (
+ (node("c", "classify"), "give labels"),
+ (node("c", "classify", labels=["one"]), "at least two"),
+ (node("c", "classify", vocabulary="colour"), "content_type or topic"),
+ (node("c", "classify", vocabulary="topic", of="input", apply=True), "only the asset"),
+ ):
+ with pytest.raises(ValueError, match=why):
+ workflows.create(db, "Bad", graph(bad, node("o", "output", key="k")))
+ with pytest.raises(ValueError, match="keeps nothing"):
+ workflows.create(db, "Keeps nothing", graph(node("c", "classify", vocabulary="topic")))
diff --git a/nextjs-frontend/__tests__/workflow-flow.test.ts b/nextjs-frontend/__tests__/workflow-flow.test.ts
index dc72c2bf4..9a7f5868d 100644
--- a/nextjs-frontend/__tests__/workflow-flow.test.ts
+++ b/nextjs-frontend/__tests__/workflow-flow.test.ts
@@ -7,6 +7,7 @@ import {
portsOf,
problems,
inScope,
+ nodeSummary,
replaceSelection,
starterTool,
withBody,
@@ -123,3 +124,32 @@ describe("tool graphs", () => {
expect(problems(recording, () => undefined, "tool", "custom").keep).toBe("This node isn’t for tools.");
});
});
+
+describe("classify", () => {
+ const names = { template: () => undefined, field: () => undefined };
+ const wf = (config: Record, keep = true): WfGraph => ({
+ nodes: [
+ { id: "in", type: "input", config: {} },
+ { id: "c", type: "classify", config },
+ ...(keep ? [{ id: "o", type: "output", config: { key: "desk" } }] : []),
+ ],
+ edges: [{ source: "in", target: "c" }, ...(keep ? [{ source: "c", target: "o" }] : [])],
+ });
+
+ it("chooses from labels, content types or topics, and acting on a sure answer keeps something", () => {
+ expect(inScope("classify", "recording")).toBe(true);
+ expect(inScope("classify", "graph")).toBe(false);
+ expect(problems(wf(defaultConfig("classify")), kind)).toEqual({});
+ expect(problems(wf({}), kind).c).toMatch(/Give labels/);
+ expect(problems(wf({ labels: ["a: one", "a: two"] }), kind).c).toMatch(/at least two/);
+ expect(problems(wf({ vocabulary: "topic", of: "input", apply: true }), kind).c).toMatch(/Only the asset/);
+ expect(problems(wf({ vocabulary: "topic" }, false), kind)[""]).toMatch(/keeps nothing/);
+ expect(problems(wf({ vocabulary: "topic", apply: true }, false), kind)).toEqual({});
+ expect(nodeSummary({ id: "c", type: "classify", config: { labels: ["security: attacks", "health"] } }, names)).toBe(
+ "security, health",
+ );
+ expect(nodeSummary({ id: "c", type: "classify", config: { vocabulary: "topic", apply: true } }, names)).toBe(
+ "The namespace’s topics · acts when sure",
+ );
+ });
+});
diff --git a/nextjs-frontend/components/workflows/node-settings.tsx b/nextjs-frontend/components/workflows/node-settings.tsx
index 94ac13ef2..7ee98c2a4 100644
--- a/nextjs-frontend/components/workflows/node-settings.tsx
+++ b/nextjs-frontend/components/workflows/node-settings.tsx
@@ -6,6 +6,7 @@ import type { FieldDef, TemplateSummary } from "@/app/openapi-client/types.gen";
import { FlowSettings } from "@/components/workflows/flow-settings";
import {
OPS,
+ VOCABULARIES,
infoFor,
paramRef,
type BodyKind,
@@ -423,6 +424,74 @@ export function NodeSettings({
>
)}
+ {node.type === "classify" && (
+ <>
+
+ {({ id, describedBy }) => (
+
+ {c.vocabulary == null && (
+ String(v)}
+ parse={(lines) => set({ labels: lines })}
+ />
+ )}
+
+ {({ id, describedBy }) => (
+ set({ question: e.target.value || undefined })}
+ />
+ )}
+
+
+ {({ id, describedBy }) => (
+
+ set({ apply: v || undefined })}
+ label="Act on a sure answer: set the content type, suggest the topic or add the label as a tag"
+ disabled={readOnly || c.of === "input"}
+ />
+ >
+ )}
+
{node.type === "output" && (
{({ id, describedBy }) => (
diff --git a/nextjs-frontend/components/workflows/workflow-model.ts b/nextjs-frontend/components/workflows/workflow-model.ts
index de8919475..ebcffdd38 100644
--- a/nextjs-frontend/components/workflows/workflow-model.ts
+++ b/nextjs-frontend/components/workflows/workflow-model.ts
@@ -22,6 +22,7 @@ import {
Save,
ScanSearch,
SearchCheck,
+ Shapes,
Sparkles,
Tags,
TextCursorInput,
@@ -127,6 +128,18 @@ export const NODES: Record = {
gives: "entity index · graph",
group: "Entities",
},
+ classify: {
+ label: "Classify",
+ describe:
+ "Says which of your labels, the content types or the namespace’s topics fits the asset (or what came in), how sure, and every label ranked; can act on a sure answer",
+ icon: Shapes,
+ tone: "gold",
+ inputs: 1,
+ outputs: ["out"],
+ takes: "asset or text",
+ gives: "choice · confidence · ranked",
+ group: "AI",
+ },
llm: {
label: "LLM prompt",
describe: "Renders a prompt template (what came in is {{ input }}) and passes on the model’s JSON",
@@ -377,7 +390,7 @@ export const PRIMITIVES = [
/** Node types per scope, for when the catalog hasn't said (it lists each type's scopes). */
const SCOPE_NODES: Record = {
- recording: [...PRIMITIVES, "extract_rules", "extract_llm", "save_entities", "llm", "output", "field"],
+ recording: [...PRIMITIVES, "extract_rules", "extract_llm", "save_entities", "llm", "classify", "output", "field"],
graph: [...PRIMITIVES, "candidates", "llm_judge", "apply_changes"],
tool: [...PRIMITIVES, "ask_model", "call_tool"],
};
@@ -389,8 +402,12 @@ export function inScope(type: string, scope: Scope, catalog?: { type: string; sc
}
export const GROUPS = ["Entities", "AI", "Logic", "Data", "Loops", "Keep"] as const;
-/** Nodes that keep something: a workflow needs one. */
+/** Nodes that keep something: a workflow needs one (or a node that keeps something as set up, see savesAsSet). */
export const KEEPS = ["output", "field", "save_entities", "apply_changes"];
+/** A node that keeps something only as it's set up: a classify node that acts on a sure answer. */
+export const savesAsSet = (n: WfNode) => n.type === "classify" && Boolean(n.config.apply);
+/** What a classify node chooses from. */
+export const VOCABULARIES: Record = { content_type: "Content types", topic: "The namespace’s topics" };
/** Nodes with a body of nodes inside, opened by double-clicking. */
export const BODIES = ["for_each", "repeat", "group"];
/** What a loop's body starts from. */
@@ -484,6 +501,7 @@ export function defaultConfig(type: string): Record {
if (type === "template") return { template: "{{ input }}" };
if (type === "ask_model") return { prompt: "{{ input }}" };
if (type === "call_tool") return { tool: "search_transcripts" };
+ if (type === "classify") return { vocabulary: "topic" };
if (type === "for_each") return { body: starterBody("for_each") };
if (type === "repeat") return { body: starterBody("repeat"), max_rounds: 5 };
if (type === "group") return { body: starterBody("group") };
@@ -806,6 +824,15 @@ export function nodeSummary(
}
case "extract_llm":
return (c.types as string[] | undefined)?.length ? (c.types as string[]).join(", ") : "all types";
+ case "classify": {
+ const labels = (c.labels as string[] | undefined) ?? [];
+ const from = c.vocabulary
+ ? (VOCABULARIES[String(c.vocabulary)] ?? String(c.vocabulary))
+ : labels.length
+ ? labels.map((l) => l.split(": ")[0]).join(", ")
+ : "Give labels";
+ return `${c.of === "input" ? "what comes in · " : ""}${from}${c.apply ? " · acts when sure" : ""}`;
+ }
case "output":
return c.key
? paramRef(c.key)
@@ -936,6 +963,16 @@ export function problems(
else if (n.type === "output" && !KEY_RX.test(String(c.key ?? "")))
fail("Name it: lowercase letters, digits and _, e.g. meeting_notes.");
else if (n.type === "field" && c.field == null) fail("Choose a custom field.");
+ else if (n.type === "classify" && (c.vocabulary == null) === (c.labels == null))
+ fail("Give labels, or choose content types or topics.");
+ else if (
+ n.type === "classify" &&
+ c.labels != null &&
+ new Set((c.labels as string[]).map((l) => l.split(": ")[0].trim())).size < 2
+ )
+ fail("Give at least two labels to choose from.");
+ else if (n.type === "classify" && c.apply && c.of === "input")
+ fail("Only the asset’s classification can be acted on.");
else if (n.type === "candidates" && !between(c.min_confidence, 0, 1, false))
fail("How sure is a number from 0 to 1.");
else if (n.type === "candidates" && !between(c.limit, 1, 1000, true)) fail("At most is 1 to 1000 pairs.");
@@ -980,7 +1017,7 @@ export function problems(
out[""] =
scope === "graph"
? "Add an Apply changes node, or the workflow changes nothing."
- : "Add a Save output, Set field or Save entities node, or the workflow keeps nothing.";
+ : "Add a Save output, Set field or Save entities node (or a Classify node that acts), or the workflow keeps nothing.";
return out;
}
@@ -990,6 +1027,7 @@ function keeps(g: WfGraph, custom?: (id: number) => CustomDef | undefined, scope
return g.nodes.some(
(n) =>
saving.includes(n.type) ||
+ (scope === "recording" && savesAsSet(n)) ||
(BODIES.includes(n.type) && n.config.body ? keeps(n.config.body as WfGraph, custom, scope) : false) ||
(n.type === "custom" && Boolean(custom?.(Number(n.config.node))?.keeps)),
);