Coverage for app / services / system_resources / skillsets.py: 100%
25 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-10-31 11:21 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-10-31 11:21 +0000
1"""
2The built-in skillsets — skills every user can grant to their own agents or
3run on their own, with nothing to build first.
5Data only, like :mod:`.definition`: :mod:`.provision` writes it. Every graph
6here is held to the rules a user's skill is held to. It must pass
7``_GraphDefinitionSchema``, and it may run only svc-ai's built-in workers,
8the names in :data:`BUILTIN_WORKERS_USED`, which svc-ai's own test pins
9against its registry.
11Two conventions keep a skill working in both places it can run:
13* **Prompts read ``{input}`` and nothing else.** In a chat turn the skill
14 receives the user's message and no interface inputs. In a standalone run
15 svc-core writes the form's values into that same task text
16 (``skill_runs.schema.compose_task``). A template naming an interface input
17 would render the literal placeholder in chat, because svc-ai leaves unknown
18 placeholders untouched. So interface inputs exist to give the Run form its
19 fields, and the text is what the workers read.
20* **Reports share one shape.** :data:`REPORT_FIELDS` is the structured
21 artifact a report-producing skill returns: a title, a summary, findings, a
22 markdown body with ``[n]`` citations and the sources those cite. It is
23 svc-ai's ``DocumentSpec``, so a report skill ends in a ``render_document``
24 tool node (:func:`_document_node`) and its result arrives as a document
25 with a PDF download, with no model involved in the layout.
26"""
28from __future__ import annotations
30from typing import Any
31from uuid import UUID
33from .definition import SystemSkillSpec, SystemSkillsetSpec
35#: Every svc-ai worker a built-in graph may name. svc-core cannot see svc-ai's
36#: registry, so svc-ai's ``test_system_skill_workers`` asserts each of these
37#: exists there, and svc-core's tests assert no graph names anything else.
38BUILTIN_WORKERS_USED: frozenset[str] = frozenset(
39 {"task_planner", "time_sensitive_web_researcher", "general_worker"}
40)
41#: Every svc-ai built-in tool a built-in graph's tool nodes call, pinned the
42#: same way (svc-ai ``test_system_skill_workers``).
43BUILTIN_TOOLS_USED: frozenset[str] = frozenset({"render_document"})
46def _field(name: str, type_: str, description: str, **extra: Any) -> dict[str, Any]:
47 return {"name": name, "type": type_, "description": description, **extra}
50def _input(name: str, description: str, *, required: bool = False) -> dict[str, Any]:
51 return _field(name, "string", description, required=required)
54_CONFIDENCE = _field(
55 "confidence",
56 "enum",
57 "How well the evidence supports the conclusions.",
58 values=["low", "medium", "high"],
59 required=True,
60)
62#: The structured report every report-producing skill returns.
63REPORT_FIELDS: list[dict[str, Any]] = [
64 _field("title", "string", "A specific, descriptive title.", required=True),
65 _field(
66 "summary",
67 "string",
68 "An executive summary of two to four sentences that stands on its own.",
69 required=True,
70 ),
71 _field(
72 "key_findings",
73 "array",
74 "The most important findings, one sentence each, most important first.",
75 items="string",
76 ),
77 _field(
78 "body",
79 "string",
80 "The full report in Markdown, organised under ## section headings. "
81 "Cite each source inline by the id it was shown with, e.g. [S3]: the "
82 "numbered sources list is built from those ids.",
83 required=True,
84 ),
85 _field(
86 "sources",
87 "array",
88 "Leave empty when the report cites source ids: the list is built "
89 "from them. Otherwise numbered sources as 'Title — URL (date if "
90 "known)', in citation order; empty when the report draws only on "
91 "material supplied in the request.",
92 items="string",
93 ),
94 _CONFIDENCE,
95 _field(
96 "open_questions",
97 "array",
98 "What the evidence could not settle, and would be worth checking next.",
99 items="string",
100 ),
101]
104def _outputs(node_id: str, names: list[str]) -> list[dict[str, str]]:
105 """Interface outputs projecting ``names`` from one structured node."""
106 return [{"name": name, "from": f"{node_id}.{name}"} for name in names]
109_REPORT_NAMES = [f["name"] for f in REPORT_FIELDS]
112def _document_node(source: str) -> dict[str, Any]:
113 """A tool node turning ``source``'s structured report into a document.
115 Deterministic — no model: svc-ai's ``render_document`` validates the
116 fields and returns a ```document fence, which reaches the reply as a card
117 with a PDF download (in chat, and on a standalone run's page). Each
118 argument is a single placeholder, so lists stay lists.
119 """
120 return {
121 "type": "tool",
122 "description": "Attach the report as a downloadable document.",
123 "tool": {
124 "name": "render_document",
125 "args": {name: f"{{{source}.{name}}}" for name in _REPORT_NAMES},
126 },
127 "output_key": "document",
128 }
131_WRITING_RULES = (
132 "Write in clear, plain British English for a professional reader. Never "
133 "state a figure, date, name or quotation that the material in front of you "
134 "does not support. Where sources disagree, say so and say which you rely "
135 "on. Put uncertainty in open_questions rather than hedging every sentence."
136)
139# ── Research & Reports ───────────────────────────────────────────────────────
141RESEARCH_BRIEF = SystemSkillSpec(
142 id=UUID("c4a1b0e7-0000-4000-8000-000000000101"),
143 name="Research brief",
144 description=(
145 "Researches a topic on the web and returns a structured, cited brief: "
146 "title, summary, key findings, a sectioned report, numbered sources "
147 "and a confidence rating."
148 ),
149 tags=("research", "web", "report"),
150 graph_definition={
151 "nodes": {
152 "plan": {
153 "type": "agent",
154 "agent_name": "task_planner",
155 "description": "Turn the request into a short research plan.",
156 "prompt_template": "Research request:\n{input}",
157 "config_overrides": {
158 "temperature": 0.2,
159 "system_prompt": (
160 "You plan web research. Identify the question actually "
161 "being asked, who the brief is for, and any focus or "
162 "timeframe the request gives. Then list three to five "
163 "specific, non-overlapping search queries that together "
164 "answer it, each with what it should establish. Be brief."
165 ),
166 },
167 "output_key": "research_plan",
168 },
169 "research": {
170 "type": "agent",
171 "agent_name": "time_sensitive_web_researcher",
172 "description": "Run the plan's searches and gather dated, sourced facts.",
173 "prompt_template": (
174 "Research request:\n{input}\n\nResearch plan:\n{research_plan}"
175 ),
176 "output_key": "findings",
177 },
178 "write": {
179 "type": "agent",
180 "agent_name": "general_worker",
181 "description": "Write the findings up as a structured brief.",
182 "prompt_template": (
183 "Research request:\n{input}\n\n"
184 "Findings, with their sources:\n{findings}"
185 ),
186 "config_overrides": {
187 "temperature": 0.2,
188 "system_prompt": (
189 "You write research briefs from findings you are given. "
190 "Use only those findings — do not add facts of your own. "
191 "Cite each finding by the source id it carries, e.g. "
192 "[S3]; never number sources yourself. " + _WRITING_RULES
193 ),
194 },
195 "output_schema": REPORT_FIELDS,
196 "output_key": "brief",
197 },
198 "publish": _document_node("write"),
199 },
200 "edges": [["plan", "research"], ["research", "write"], ["write", "publish"]],
201 "start_node": "plan",
202 "end_nodes": ["publish"],
203 "interface": {
204 "inputs": [
205 _input("topic", "What to research.", required=True),
206 _input("audience", "Who the brief is for, e.g. 'the board'."),
207 _input("focus", "Anything to concentrate on or leave out."),
208 ],
209 "outputs": _outputs("write", _REPORT_NAMES),
210 },
211 },
212)
214DOCUMENT_SUMMARY = SystemSkillSpec(
215 id=UUID("c4a1b0e7-0000-4000-8000-000000000102"),
216 name="Summarise a document",
217 description=(
218 "Summarises text you supply — a report, a policy, a contract — into "
219 "the same structured report shape, drawing on nothing but the text."
220 ),
221 tags=("summary", "report"),
222 graph_definition={
223 "nodes": {
224 "summarise": {
225 "type": "agent",
226 "agent_name": "general_worker",
227 "description": "Summarise the supplied text as a structured report.",
228 "prompt_template": "{input}",
229 "config_overrides": {
230 "temperature": 0.1,
231 "tools_enabled": False,
232 "system_prompt": (
233 "You summarise documents the user supplies. Work only "
234 "from the document text in the request: do not search, "
235 "and do not add outside knowledge. Quote section names "
236 "or clause numbers where they help a reader find the "
237 "passage. Leave sources empty. " + _WRITING_RULES
238 ),
239 },
240 "output_schema": REPORT_FIELDS,
241 "output_key": "summary_report",
242 },
243 "publish": _document_node("summarise"),
244 },
245 "edges": [["summarise", "publish"]],
246 "start_node": "summarise",
247 "end_nodes": ["publish"],
248 "interface": {
249 "inputs": [
250 _input("document", "The text to summarise.", required=True),
251 _input("focus", "What the reader needs from it, if anything."),
252 ],
253 "outputs": _outputs("summarise", _REPORT_NAMES),
254 },
255 },
256)
258RESEARCH_AND_REPORTS = SystemSkillsetSpec(
259 id=UUID("c4a1b0e7-0000-4000-8000-000000000010"),
260 name="Research & Reports",
261 description=(
262 "Turns a question or a document into a structured, cited "
263 "report. Grant it to an agent, or run either skill on its own."
264 ),
265 skills=(RESEARCH_BRIEF, DOCUMENT_SUMMARY),
266)
269# ── Decisions & Actions ──────────────────────────────────────────────────────
271COMPARE_OPTIONS = SystemSkillSpec(
272 id=UUID("c4a1b0e7-0000-4000-8000-000000000103"),
273 name="Compare options",
274 description=(
275 "Researches the options for a decision against your criteria and "
276 "returns a recommendation, a comparison table, the risks and sources."
277 ),
278 tags=("decision", "comparison", "research"),
279 graph_definition={
280 "nodes": {
281 "research": {
282 "type": "agent",
283 "agent_name": "time_sensitive_web_researcher",
284 "description": "Gather current facts on each option.",
285 "prompt_template": (
286 "Gather the facts needed to compare the options in this "
287 "decision, covering each option against each criterion "
288 "(or, if none are given, the criteria that matter most "
289 "for a decision like this).\n\n{input}"
290 ),
291 "output_key": "evidence",
292 },
293 "decide": {
294 "type": "agent",
295 "agent_name": "general_worker",
296 "description": "Weigh the options and recommend one.",
297 "prompt_template": (
298 "Decision:\n{input}\n\nEvidence, with its sources:\n{evidence}"
299 ),
300 "config_overrides": {
301 "temperature": 0.2,
302 "system_prompt": (
303 "You advise on decisions. Compare every option on every "
304 "criterion using only the evidence given, then recommend "
305 "one — or say plainly that the evidence does not "
306 "separate them. " + _WRITING_RULES
307 ),
308 },
309 "output_schema": [
310 _field(
311 "recommendation",
312 "string",
313 "The option recommended, or 'No clear winner'.",
314 required=True,
315 ),
316 _field(
317 "rationale",
318 "string",
319 "Why, in a short paragraph, citing sources as [n].",
320 required=True,
321 ),
322 _field(
323 "comparison",
324 "string",
325 "A Markdown table: one row per option, one column per "
326 "criterion.",
327 required=True,
328 ),
329 _field(
330 "risks",
331 "array",
332 "The main risks of the recommended option.",
333 items="string",
334 ),
335 _field(
336 "sources",
337 "array",
338 "Numbered sources as 'Title — URL', in citation order.",
339 items="string",
340 ),
341 _CONFIDENCE,
342 ],
343 "output_key": "decision",
344 },
345 },
346 "edges": [["research", "decide"]],
347 "start_node": "research",
348 "end_nodes": ["decide"],
349 "interface": {
350 "inputs": [
351 _input("decision", "The decision to make.", required=True),
352 _input("options", "The options, one per line.", required=True),
353 _input("criteria", "What matters, most important first."),
354 ],
355 "outputs": _outputs(
356 "decide",
357 [
358 "recommendation",
359 "rationale",
360 "comparison",
361 "risks",
362 "sources",
363 "confidence",
364 ],
365 ),
366 },
367 },
368)
370EXTRACT_ACTIONS = SystemSkillSpec(
371 id=UUID("c4a1b0e7-0000-4000-8000-000000000104"),
372 name="Extract actions",
373 description=(
374 "Reads meeting notes, a transcript or an email thread and returns the "
375 "decisions made, the action items with owners and dates, and what is "
376 "still open."
377 ),
378 tags=("actions", "meetings", "summary"),
379 graph_definition={
380 "nodes": {
381 "extract": {
382 "type": "agent",
383 "agent_name": "general_worker",
384 "description": "Pull decisions, actions and open questions out.",
385 "prompt_template": "{input}",
386 "config_overrides": {
387 "temperature": 0.1,
388 "tools_enabled": False,
389 "system_prompt": (
390 "You turn notes into a record of what was agreed. Work "
391 "only from the text supplied. Record an owner or date "
392 "only when the text gives one; otherwise write "
393 "'unassigned' or 'no date' — never guess."
394 ),
395 },
396 "output_schema": [
397 _field(
398 "summary",
399 "string",
400 "What the discussion was about, in two or three sentences.",
401 required=True,
402 ),
403 _field(
404 "decisions",
405 "array",
406 "Each decision that was made, one sentence each.",
407 items="string",
408 ),
409 _field(
410 "action_items",
411 "array",
412 "Each action as 'Owner — action — due date'.",
413 items="string",
414 ),
415 _field(
416 "open_questions",
417 "array",
418 "Questions raised and not resolved.",
419 items="string",
420 ),
421 ],
422 "output_key": "actions",
423 },
424 },
425 "edges": [],
426 "start_node": "extract",
427 "end_nodes": ["extract"],
428 "interface": {
429 "inputs": [
430 _input("notes", "The notes, transcript or thread.", required=True),
431 ],
432 "outputs": _outputs(
433 "extract", ["summary", "decisions", "action_items", "open_questions"]
434 ),
435 },
436 },
437)
439DECISIONS_AND_ACTIONS = SystemSkillsetSpec(
440 id=UUID("c4a1b0e7-0000-4000-8000-000000000011"),
441 name="Decisions & Actions",
442 description=(
443 "Compares options for a decision, and turns notes into "
444 "decisions and owned action items. Grant it to an agent, or run either "
445 "skill on its own."
446 ),
447 skills=(COMPARE_OPTIONS, EXTRACT_ACTIONS),
448)
451#: Every built-in skillset, in the order they are provisioned and listed.
452SYSTEM_SKILLSETS: tuple[SystemSkillsetSpec, ...] = (
453 RESEARCH_AND_REPORTS,
454 DECISIONS_AND_ACTIONS,
455)