Plugin skills¶
A plugin skill adds an intent to the consumer agent without changing the package. Set TDFS4DS_SKILLS_FOLDER to a folder holding
one sub-folder per skill:
<skills folder>/
compliance/
SKILL.md # name, intent, description; the classifier reads them
skill.py # defines node(state) -> dict
_lib/ # code shared by the plugins; not a skill
__init__.py
helpers.py
SKILL.md alone makes the skill visible to the classifier, and nothing answers it. A skill declaring an intent with no skill.py,
or a skill.py with no node, logs a warning when the agent's graph is built, and the admin app's Skills panel shows it in its
routed column.
The app's import takes the SKILL.md only. The app has no access control, so an uploaded skill.py would let anyone reaching its
port run code on the server. Copy skill.py to the folder yourself.
What a plugin can call¶
import tdfs4ds
from _lib.helpers import my_rule # any plugin can import from _lib
def node(state):
question = state.get("question") or ""
# the period the question names, with "today" read from the database clock
period = tdfs4ds.parse_period(question, "Europe/Paris")
# a statement on the session's connection, as a frame; BYTE and BLOB columns stay bytes
rows = tdfs4ds.run_sql("SELECT TOP 5 a, b FROM db.t WHERE c = ?", ["x"])
# the instruct model, returning JSON through whatever constraint the endpoint honours
verdict = tdfs4ds.llm_json("You classify requests.", question,
schema={"type": "object", "properties": {"label": {"type": "string"}},
"required": ["label"]},
expect=dict, default={"label": "unknown"})
return {"skill_result": {"answer": f"{verdict['label']}: {len(rows)} rows", "docs_sources": []}}
| Function | Returns | Notes |
|---|---|---|
llm_json(system, user, schema=, expect=, default=) |
The parsed reply | A failure logs and returns default. It honours STRUCTURED_OUTPUT_METHOD. |
run_sql(sql, params=None) |
A pandas frame | One session, so a volatile table stays visible to the next call. Teradataml only, not MCP. A database error raises. Not for a background thread. |
chart_payload(result) |
A chart for the answer | result comes from a plot_* function; put the payload in the skill's charts. |
parse_period(question, timezone='UTC', now=None) |
{"start", "end", "how"} or None |
Aware datetimes, end excluded. A date with no offset is read in timezone. It raises when the database clock is needed and cannot be read. |
deep_table_tag_documentation(database, table) |
A frame TAG_NAME, DESCRIPTION, UNIT |
Reads the documentation and DBC, never the table. |
resolve_tags(question, catalogue) |
[{tag, description, unit, score, matched, how}] |
Pure. A tag the question names wins; otherwise it matches on the descriptions. |
A complete example¶
The package ships a working plugin folder. tdfs4ds.examples_path('plugin_skills') returns its path (inside the installed
package, tdfs4ds/examples/plugin_skills); copy it and point the agent at the copy:
import shutil, tdfs4ds
shutil.copytree(tdfs4ds.examples_path('plugin_skills'), 'my_skills')
# then, before the agent is built: TDFS4DS_SKILLS_FOLDER=my_skills
plugin_skills/
_lib/
__init__.py
rules.py # the business rules: no database, no model
period_counter/
SKILL.md # intent PERIOD_COUNT, description, classifier examples
skill.py # node(state)
period_counter answers "how many events in the last 7 days?". It reads the period from the question, asks the model which measure
is meant (all events or the flagged ones), reads the daily events table and applies the rule to a BYTE column:
from tdfs4ds.plugins import llm_json, parse_period, run_sql
from _lib import rules
def node(state):
question = state.get("question") or ""
period = parse_period(question, "UTC") # "today" comes from the database clock
if period is None:
return {"skill_result": {"answer": "Which period? ...", "docs_sources": []}}
verdict = llm_json("Say which measure the user asks for ...", question,
schema=_SCHEMA, expect=dict, default={"metric": "events"}, skill_name="period_counter")
metric = verdict.get("metric") if verdict.get("metric") in rules.METRICS else "events"
first, last = rules.period_dates(period) # end excluded
rows = run_sql(f"SELECT event_count, flags FROM {rules.EVENTS_TABLE} "
"WHERE event_day >= ? AND event_day < ?", [first, last])
total = rules.count(rows, metric) # flags stay bytes: rules reads the first byte
return {"skill_result": {"answer": rules.describe(period, metric, total),
"docs_sources": [rules.EVENTS_TABLE]}}
Three things to notice. The skill returns its final answer, so the agent does not make a second model call to rewrite it. The
rules live in _lib, where a test can call them without a database. And the table (EVENTS_TABLE in _lib/rules.py) is yours to
change: the example expects event_day DATE, event_count INTEGER, flags BYTE(1).
The package tests drive this folder through the real graph with the classifier, the database and the model stubbed
(tests/test_plugin_end_to_end.py); do the same for your own skill before you rely on it. A skill.py that raises when it is
imported is skipped with a warning, and the other intents keep working.
Finding a tag by its meaning¶
deep_table_tags scans the table and returns no description, and matching on names finds nothing when a question names a measurement
by its meaning. Read the documentation once, and resolve each question against it:
catalogue = tdfs4ds.deep_table_tag_documentation('DB_SOURCE', 'HISTORIAN')
hits = tdfs4ds.resolve_tags('how hot was the furnace?', catalogue)
if len(hits) > 1 and hits[1]['score'] > 0.8:
... # the question does not decide: ask
The match is on words: a word counts more the fewer tags have it, and there is no language model and no database read. A question and
a description using different words for one thing do not match, so pass the candidates to llm_json if you need that.
A unit is read from the end of the tag's name (Length (m)) or from unit: m in its description.