unique_orchestrator 2026.50.0.dev0__tar.gz → 2026.50.0.dev2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/PKG-INFO +4 -4
  2. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/pyproject.toml +4 -4
  3. unique_orchestrator-2026.50.0.dev2/unique_orchestrator/_builders/skill_file_loader.py +278 -0
  4. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/_builders/skill_setup.py +81 -38
  5. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/config.py +2 -0
  6. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/unique_ai_builder.py +6 -0
  7. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/README.md +0 -0
  8. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/__init__.py +0 -0
  9. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/_builders/__init__.py +0 -0
  10. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/_builders/history_manager.py +0 -0
  11. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/_builders/inject_tool_reminders.py +0 -0
  12. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/_builders/loop_iteration_runner.py +0 -0
  13. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/_builders/open_file_setup.py +0 -0
  14. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/prompts/generic_reference_prompt.jinja2 +0 -0
  15. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/prompts/system_prompt.jinja2 +0 -0
  16. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/prompts/user_message_prompt.jinja2 +0 -0
  17. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/settings.py +0 -0
  18. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/tests/test_agent_config_rjsf_ui_schema.py +0 -0
  19. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/tests/test_build_loop_iteration_runner.py +0 -0
  20. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/tests/test_config_services_validators.py +0 -0
  21. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/tests/test_qwen_max_loop_iterations.py +0 -0
  22. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/tests/test_register_code_interpreter_postprocessors.py +0 -0
  23. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/tests/test_unique_ai_async_modify.py +0 -0
  24. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/tests/test_unique_ai_execution_timing.py +0 -0
  25. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/tests/test_unique_ai_get_filtered_user_metadata.py +0 -0
  26. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/tests/test_unique_ai_log_tool_calls.py +0 -0
  27. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/tests/test_unique_ai_loop_debug_params.py +0 -0
  28. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/tests/test_unique_ai_persist_tool_calls.py +0 -0
  29. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/tests/test_unique_ai_plan_or_execute_include.py +0 -0
  30. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/tests/test_unique_ai_reference_order.py +0 -0
  31. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/tests/test_unique_ai_render_system_prompt_user_instructions.py +0 -0
  32. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/tests/test_unique_ai_token_usage.py +0 -0
  33. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/tests/test_utils_resolve_other_options.py +0 -0
  34. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/unique_ai.py +0 -0
  35. {unique_orchestrator-2026.50.0.dev0 → unique_orchestrator-2026.50.0.dev2}/unique_orchestrator/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: unique-orchestrator
3
- Version: 2026.50.0.dev0
3
+ Version: 2026.50.0.dev2
4
4
  Summary:
5
5
  Author: Andreas Hauri
6
6
  Author-email: Andreas Hauri <andreas.hauri@unique.ai>
@@ -8,14 +8,14 @@ License: Proprietary
8
8
  Requires-Dist: pydantic>=2.8.2,<3
9
9
  Requires-Dist: pydantic-settings>=2.10.1,<3
10
10
  Requires-Dist: typing-extensions>=4.9.0,<5
11
- Requires-Dist: unique-toolkit>=2026.50.0.dev0,<2026.50.0rc0
11
+ Requires-Dist: unique-toolkit>=2026.50.0.dev2,<2026.50.0rc0
12
12
  Requires-Dist: unique-stock-ticker>=2026.50.0.dev0,<2026.50.0rc0
13
13
  Requires-Dist: unique-follow-up-questions>=2026.50.0.dev0,<2026.50.0rc0
14
- Requires-Dist: unique-internal-search>=2026.50.0.dev0,<2026.50.0rc0
14
+ Requires-Dist: unique-internal-search>=2026.50.0.dev1,<2026.50.0rc0
15
15
  Requires-Dist: unique-deep-research>=2026.50.0.dev0,<2026.50.0rc0
16
16
  Requires-Dist: unique-web-search>=2026.50.0.dev0,<2026.50.0rc0
17
17
  Requires-Dist: unique-swot>=2026.50.0.dev0,<2026.50.0rc0
18
- Requires-Dist: unique-skill-tool>=2026.50.0.dev0,<2026.50.0rc0
18
+ Requires-Dist: unique-skill-tool>=2026.50.0.dev1,<2026.50.0rc0
19
19
  Requires-Dist: unique-user-memory>=2026.50.0.dev0,<2026.50.0rc0
20
20
  Requires-Dist: openai>=1.109.1,<3
21
21
  Requires-Python: >=3.12, <4
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "unique_orchestrator"
3
- version = "2026.50.0.dev0"
3
+ version = "2026.50.0.dev2"
4
4
  description = ""
5
5
  readme = "README.md"
6
6
  license = { text = "Proprietary" }
@@ -12,14 +12,14 @@ dependencies = [
12
12
  "pydantic>=2.8.2,<3",
13
13
  "pydantic-settings>=2.10.1,<3",
14
14
  "typing-extensions>=4.9.0,<5",
15
- "unique-toolkit>=2026.50.0.dev0,<2026.50.0rc0",
15
+ "unique-toolkit>=2026.50.0.dev2,<2026.50.0rc0",
16
16
  "unique-stock-ticker>=2026.50.0.dev0,<2026.50.0rc0",
17
17
  "unique-follow-up-questions>=2026.50.0.dev0,<2026.50.0rc0",
18
- "unique-internal-search>=2026.50.0.dev0,<2026.50.0rc0",
18
+ "unique-internal-search>=2026.50.0.dev1,<2026.50.0rc0",
19
19
  "unique-deep-research>=2026.50.0.dev0,<2026.50.0rc0",
20
20
  "unique-web-search>=2026.50.0.dev0,<2026.50.0rc0",
21
21
  "unique-swot>=2026.50.0.dev0,<2026.50.0rc0",
22
- "unique-skill-tool>=2026.50.0.dev0,<2026.50.0rc0",
22
+ "unique-skill-tool>=2026.50.0.dev1,<2026.50.0rc0",
23
23
  "unique-user-memory>=2026.50.0.dev0,<2026.50.0rc0",
24
24
  "openai>=1.109.1,<3",
25
25
  ]
@@ -0,0 +1,278 @@
1
+ """Download ``SKILL.md`` files for the Skill tool, and cache the parsed result.
2
+
3
+ The cache is only used for a skill the platform has just listed as readable
4
+ for the acting user, because a cache hit skips the access check of a download.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import asyncio
10
+ import random
11
+ import threading
12
+ from collections import OrderedDict
13
+ from collections.abc import AsyncIterator, Awaitable, Callable
14
+ from contextlib import asynccontextmanager
15
+ from logging import Logger
16
+ from typing import TYPE_CHECKING
17
+
18
+ from unique_skill_tool.loader import parse_skill_file
19
+ from unique_skill_tool.schemas import SkillDefinition
20
+ from unique_toolkit.app.schemas import SkillReference
21
+ from unique_toolkit.skills import get_readable_skill_versions_async
22
+
23
+ if TYPE_CHECKING:
24
+ from unique_toolkit.content.service import ContentService
25
+
26
+ MAX_PARALLEL_SKILL_DOWNLOADS = 10
27
+ SKILL_DOWNLOAD_TIMEOUT_S = 20.0
28
+ SKILL_DOWNLOAD_ATTEMPTS = 2
29
+ SKILL_DOWNLOAD_BACKOFF_S = 0.25
30
+ MAX_SKILL_FILE_BYTES = 1_000_000
31
+ SKILL_CACHE_MAX_ENTRIES = 2048
32
+ READABLE_SKILLS_LOOKUP_TIMEOUT_S = 5.0
33
+ # A skill not ready by then is left out of the turn. A cacheable download
34
+ # still finishes and serves the next turn.
35
+ SKILL_LOAD_BUDGET_S = 30.0
36
+
37
+ # Company, content id and the file's last-modified time. An edited file gets
38
+ # a new last-modified time, so it never matches the entry of the old text.
39
+ SkillCacheKey = tuple[str, str, str]
40
+
41
+ _TOO_MANY_REQUESTS = 429
42
+
43
+
44
+ class _DownloadLimiter:
45
+ """One limit on parallel skill downloads for every turn in this process."""
46
+
47
+ def __init__(self, *, max_parallel: int) -> None:
48
+ self._max_parallel = max_parallel
49
+ self._semaphores: dict[asyncio.AbstractEventLoop, asyncio.Semaphore] = {}
50
+ self._lock = threading.Lock()
51
+
52
+ @asynccontextmanager
53
+ async def slot(self) -> AsyncIterator[None]:
54
+ async with self._semaphore():
55
+ yield
56
+
57
+ def _semaphore(self) -> asyncio.Semaphore:
58
+ # A semaphore belongs to one event loop, so each loop gets its own.
59
+ loop = asyncio.get_running_loop()
60
+ with self._lock:
61
+ for known in [known for known in self._semaphores if known.is_closed()]:
62
+ del self._semaphores[known]
63
+ semaphore = self._semaphores.get(loop)
64
+ if semaphore is None:
65
+ semaphore = asyncio.Semaphore(self._max_parallel)
66
+ self._semaphores[loop] = semaphore
67
+ return semaphore
68
+
69
+
70
+ class SkillCache:
71
+ """Parsed skills by ``SkillCacheKey``, least recently used evicted first.
72
+
73
+ ``None`` is a valid entry: the file was read and is not a usable skill.
74
+ """
75
+
76
+ def __init__(self, *, max_entries: int) -> None:
77
+ self._max_entries = max_entries
78
+ self._entries: OrderedDict[SkillCacheKey, SkillDefinition | None] = (
79
+ OrderedDict()
80
+ )
81
+ self._loading: dict[
82
+ tuple[asyncio.AbstractEventLoop, SkillCacheKey],
83
+ asyncio.Task[SkillDefinition | None],
84
+ ] = {}
85
+ self._lock = threading.Lock()
86
+
87
+ async def get_or_load(
88
+ self,
89
+ *,
90
+ key: SkillCacheKey,
91
+ load: Callable[[], Awaitable[SkillDefinition | None]],
92
+ ) -> tuple[SkillDefinition | None, bool]:
93
+ """Return the skill and whether it came from the cache.
94
+
95
+ Turns that need the same uncached skill at the same time share one
96
+ ``load`` call. A failed ``load`` raises for each of them and stores
97
+ nothing.
98
+ """
99
+ with self._lock:
100
+ if key in self._entries:
101
+ self._entries.move_to_end(key)
102
+ return self._entries[key], True
103
+ loading_key = (asyncio.get_running_loop(), key)
104
+ task = self._loading.get(loading_key)
105
+ if task is None:
106
+ task = asyncio.ensure_future(self._load_and_store(key=key, load=load))
107
+ self._loading[loading_key] = task
108
+ task.add_done_callback(
109
+ lambda done: self._finish_loading(
110
+ loading_key=loading_key, task=done
111
+ )
112
+ )
113
+ # Shielded so a cancelled turn does not cancel the download for the
114
+ # other turns that wait on it.
115
+ return await asyncio.shield(task), False
116
+
117
+ def clear(self) -> None:
118
+ with self._lock:
119
+ self._entries.clear()
120
+
121
+ async def _load_and_store(
122
+ self,
123
+ *,
124
+ key: SkillCacheKey,
125
+ load: Callable[[], Awaitable[SkillDefinition | None]],
126
+ ) -> SkillDefinition | None:
127
+ skill = await load()
128
+ with self._lock:
129
+ self._entries[key] = skill
130
+ self._entries.move_to_end(key)
131
+ while len(self._entries) > self._max_entries:
132
+ self._entries.popitem(last=False)
133
+ return skill
134
+
135
+ def _finish_loading(
136
+ self,
137
+ *,
138
+ loading_key: tuple[asyncio.AbstractEventLoop, SkillCacheKey],
139
+ task: asyncio.Task[SkillDefinition | None],
140
+ ) -> None:
141
+ with self._lock:
142
+ self._loading.pop(loading_key, None)
143
+ if not task.cancelled():
144
+ # Read so a failure nobody awaited any more is not reported as
145
+ # "Task exception was never retrieved".
146
+ task.exception()
147
+
148
+
149
+ _download_limiter = _DownloadLimiter(max_parallel=MAX_PARALLEL_SKILL_DOWNLOADS)
150
+ _skill_cache = SkillCache(max_entries=SKILL_CACHE_MAX_ENTRIES)
151
+
152
+
153
+ def clear_skill_cache() -> None:
154
+ """Empty the process-wide skill cache."""
155
+ _skill_cache.clear()
156
+
157
+
158
+ async def fetch_readable_skill_versions(
159
+ *,
160
+ user_id: str,
161
+ company_id: str,
162
+ space_id: str,
163
+ logger: Logger,
164
+ ) -> dict[str, str]:
165
+ """Return content id to last-modified time for the skills the user can read.
166
+
167
+ Empty when the platform cannot answer in time, for example an older
168
+ platform without this endpoint. Every skill is then downloaded as the user.
169
+ """
170
+ try:
171
+ async with asyncio.timeout(READABLE_SKILLS_LOOKUP_TIMEOUT_S):
172
+ return await get_readable_skill_versions_async(
173
+ user_id=user_id, company_id=company_id, space_id=space_id
174
+ )
175
+ except Exception:
176
+ logger.warning(
177
+ "Could not list the readable skills of space '%s' — "
178
+ "loading every skill without the cache.",
179
+ space_id,
180
+ exc_info=True,
181
+ )
182
+ return {}
183
+
184
+
185
+ async def load_skill(
186
+ *,
187
+ content_service: ContentService,
188
+ reference: SkillReference,
189
+ company_id: str,
190
+ readable_version: str | None,
191
+ logger: Logger,
192
+ ) -> tuple[SkillDefinition | None, bool]:
193
+ """Return the parsed skill and whether it came from the cache.
194
+
195
+ ``readable_version`` is the skill file's last-modified time from the
196
+ platform's list of skills the acting user can read, or ``None`` when the
197
+ skill is not in that list. Only a listed skill uses the cache.
198
+
199
+ ``None`` as the skill means the file is not a usable skill. A failed
200
+ download raises.
201
+ """
202
+
203
+ async def fetch() -> SkillDefinition | None:
204
+ return await _download_and_parse(
205
+ content_service=content_service, reference=reference, logger=logger
206
+ )
207
+
208
+ if not readable_version or not company_id:
209
+ return await fetch(), False
210
+
211
+ skill, from_cache = await _skill_cache.get_or_load(
212
+ key=(company_id, reference.content_id, readable_version), load=fetch
213
+ )
214
+ # Callers get their own copy, so no turn can change the cached skill.
215
+ return (skill.model_copy() if skill is not None else None), from_cache
216
+
217
+
218
+ async def _download_and_parse(
219
+ *,
220
+ content_service: ContentService,
221
+ reference: SkillReference,
222
+ logger: Logger,
223
+ ) -> SkillDefinition | None:
224
+ label = reference.name or reference.content_id
225
+ payload = await _download(
226
+ content_service=content_service, content_id=reference.content_id
227
+ )
228
+ if len(payload) > MAX_SKILL_FILE_BYTES:
229
+ logger.warning(
230
+ "Skipping skill '%s' (%s): file is %d bytes, the limit is %d.",
231
+ label,
232
+ reference.content_id,
233
+ len(payload),
234
+ MAX_SKILL_FILE_BYTES,
235
+ )
236
+ return None
237
+ try:
238
+ file_text = payload.decode("utf-8")
239
+ except UnicodeDecodeError:
240
+ logger.warning(
241
+ "Skipping skill '%s' (%s): file is not valid UTF-8.",
242
+ label,
243
+ reference.content_id,
244
+ )
245
+ return None
246
+ return parse_skill_file(
247
+ file_text=file_text,
248
+ content_id=reference.content_id,
249
+ source_label=label,
250
+ logger=logger,
251
+ )
252
+
253
+
254
+ async def _download(*, content_service: ContentService, content_id: str) -> bytes:
255
+ for attempt in range(1, SKILL_DOWNLOAD_ATTEMPTS + 1):
256
+ try:
257
+ # The HTTP timeout applies to each read, not to the whole download.
258
+ async with (
259
+ _download_limiter.slot(),
260
+ asyncio.timeout(SKILL_DOWNLOAD_TIMEOUT_S),
261
+ ):
262
+ return await content_service.download_content_to_bytes_async(
263
+ content_id=content_id, timeout=SKILL_DOWNLOAD_TIMEOUT_S
264
+ )
265
+ except Exception as error:
266
+ if attempt == SKILL_DOWNLOAD_ATTEMPTS or not _is_retryable(error):
267
+ raise
268
+ # Outside the slot, so a waiting retry does not hold up other downloads.
269
+ await asyncio.sleep(SKILL_DOWNLOAD_BACKOFF_S * attempt * (1 + random.random()))
270
+ raise AssertionError("unreachable: the last attempt returns or raises")
271
+
272
+
273
+ def _is_retryable(error: Exception) -> bool:
274
+ """A download is safe to repeat, so only a definite client error is final."""
275
+ status_code = getattr(getattr(error, "response", None), "status_code", None)
276
+ if not isinstance(status_code, int):
277
+ return True
278
+ return status_code == _TOO_MANY_REQUESTS or 500 <= status_code <= 599
@@ -42,11 +42,11 @@ content injected when the skill is invoked.
42
42
  from __future__ import annotations
43
43
 
44
44
  import asyncio
45
+ from collections.abc import Mapping
45
46
  from logging import Logger
46
47
  from typing import TYPE_CHECKING
47
48
 
48
49
  from unique_skill_tool.config import SkillToolConfig
49
- from unique_skill_tool.loader import parse_skill_file
50
50
  from unique_skill_tool.schemas import SkillDefinition
51
51
  from unique_skill_tool.service import SkillTool
52
52
  from unique_toolkit.agentic.tools.config import ToolBuildConfig
@@ -54,6 +54,12 @@ from unique_toolkit.agentic.tools.schemas import ToolCallResponse
54
54
  from unique_toolkit.app.schemas import SkillReference
55
55
  from unique_toolkit.language_model.schemas import LanguageModelFunction
56
56
 
57
+ from unique_orchestrator._builders import skill_file_loader
58
+ from unique_orchestrator._builders.skill_file_loader import (
59
+ fetch_readable_skill_versions,
60
+ load_skill,
61
+ )
62
+
57
63
  if TYPE_CHECKING:
58
64
  from unique_toolkit.agentic.history_manager.history_manager import HistoryManager
59
65
  from unique_toolkit.agentic.tools.tool_manager import (
@@ -106,6 +112,8 @@ async def load_selectable_skills(
106
112
  content_service: ContentService,
107
113
  selectable_skills: list[SkillReference],
108
114
  logger: Logger,
115
+ company_id: str = "",
116
+ readable_skill_versions: Mapping[str, str] | None = None,
109
117
  ) -> dict[str, SkillDefinition]:
110
118
  """Load skills from an explicit list of ``SkillReference`` references.
111
119
 
@@ -113,58 +121,62 @@ async def load_selectable_skills(
113
121
  leave a blank row as a placeholder). Failures are logged and do not
114
122
  abort the rest of the registry so one broken entry cannot hide the
115
123
  rest of the skill list.
124
+
125
+ ``readable_skill_versions`` maps the content id of each skill the acting
126
+ user can read to the last-modified time of its file, as the platform
127
+ lists them. A skill in that map is served from the process-wide skill
128
+ cache when its file was parsed before; see ``skill_file_loader``. Any
129
+ other skill is downloaded as the user.
116
130
  """
131
+ versions = readable_skill_versions or {}
117
132
  valid_entries = [entry for entry in selectable_skills if entry.content_id]
118
133
  if not valid_entries:
119
134
  logger.info("SkillTool has no selectable_skills with a content_id set.")
120
135
  return {}
121
136
 
122
- download_results = await asyncio.gather(
123
- *(
124
- content_service.download_content_to_bytes_async(content_id=entry.content_id)
125
- for entry in valid_entries
126
- ),
127
- return_exceptions=True,
128
- )
137
+ tasks = [
138
+ asyncio.ensure_future(
139
+ load_skill(
140
+ content_service=content_service,
141
+ reference=entry,
142
+ company_id=company_id,
143
+ readable_version=versions.get(entry.content_id),
144
+ logger=logger,
145
+ )
146
+ )
147
+ for entry in valid_entries
148
+ ]
149
+ try:
150
+ _, pending = await asyncio.wait(
151
+ tasks, timeout=skill_file_loader.SKILL_LOAD_BUDGET_S
152
+ )
153
+ finally:
154
+ for task in tasks:
155
+ task.cancel()
156
+ if pending:
157
+ await asyncio.gather(*pending, return_exceptions=True)
129
158
 
130
159
  skill_registry: dict[str, SkillDefinition] = {}
131
- for entry, result in zip(valid_entries, download_results, strict=True):
160
+ cached_count = 0
161
+ failed_count = 0
162
+ for entry, task in zip(valid_entries, tasks, strict=True):
132
163
  label = entry.name or entry.content_id
164
+ if task in pending:
165
+ continue
166
+ result = task.exception() or task.result()
133
167
  if isinstance(result, BaseException):
168
+ failed_count += 1
134
169
  logger.warning(
135
- "Failed to download selectable skill '%s' (%s) — skipping.",
170
+ "Failed to load selectable skill '%s' (%s) — skipping.",
136
171
  label,
137
172
  entry.content_id,
138
173
  exc_info=result,
139
174
  )
140
175
  continue
141
176
 
142
- try:
143
- file_text = result.decode("utf-8")
144
- except UnicodeDecodeError:
145
- logger.warning(
146
- "Failed to decode selectable skill '%s' (%s) as UTF-8 — skipping.",
147
- label,
148
- entry.content_id,
149
- exc_info=True,
150
- )
151
- continue
152
-
153
- try:
154
- skill = parse_skill_file(
155
- file_text=file_text,
156
- content_id=entry.content_id,
157
- source_label=label,
158
- logger=logger,
159
- )
160
- except Exception:
161
- logger.warning(
162
- "Unexpected error building selectable skill '%s' (%s) — skipping.",
163
- label,
164
- entry.content_id,
165
- exc_info=True,
166
- )
167
- continue
177
+ skill, from_cache = result
178
+ if from_cache:
179
+ cached_count += 1
168
180
 
169
181
  if skill is None:
170
182
  logger.debug(
@@ -184,9 +196,21 @@ async def load_selectable_skills(
184
196
 
185
197
  skill_registry[skill.name] = skill
186
198
 
199
+ if pending:
200
+ logger.warning(
201
+ "Left out %d skill(s) not loaded within %.0f s.",
202
+ len(pending),
203
+ skill_file_loader.SKILL_LOAD_BUDGET_S,
204
+ )
187
205
  logger.info(
188
- "Loaded %d skill(s) from selectable_skills.",
206
+ "Loaded %d skill(s) from selectable_skills "
207
+ "(listed=%d, from_cache=%d, downloaded=%d, failed=%d, timed_out=%d).",
189
208
  len(skill_registry),
209
+ len(valid_entries),
210
+ cached_count,
211
+ len(valid_entries) - cached_count - failed_count - len(pending),
212
+ failed_count,
213
+ len(pending),
190
214
  )
191
215
  return skill_registry
192
216
 
@@ -198,8 +222,16 @@ async def configure_skill_tool(
198
222
  content_service: ContentService,
199
223
  tool_manager: ToolManager | ResponsesApiToolManager,
200
224
  selectable_skills: list[SkillReference] | None = None,
225
+ user_id: str = "",
226
+ company_id: str = "",
227
+ space_id: str = "",
201
228
  ) -> None:
202
- """Populate the SkillTool's skill registry when it is enabled in ``space.tools``."""
229
+ """Populate the SkillTool's skill registry when it is enabled in ``space.tools``.
230
+
231
+ With ``user_id``, ``company_id`` and ``space_id``, the platform is asked
232
+ once which skills this user can read in the space. Only those are served
233
+ from the skill cache.
234
+ """
203
235
  skill_tool_build_config = _find_skill_tool_build_config(config.space.tools)
204
236
  if skill_tool_build_config is None or not skill_tool_build_config.is_enabled:
205
237
  return
@@ -225,10 +257,21 @@ async def configure_skill_tool(
225
257
  tool_manager.exclude_tool(SkillTool.name)
226
258
  return
227
259
 
260
+ readable_skill_versions: dict[str, str] = {}
261
+ if user_id and company_id and space_id:
262
+ readable_skill_versions = await fetch_readable_skill_versions(
263
+ user_id=user_id,
264
+ company_id=company_id,
265
+ space_id=space_id,
266
+ logger=logger,
267
+ )
268
+
228
269
  skill_registry = await load_selectable_skills(
229
270
  content_service=content_service,
230
271
  selectable_skills=to_load,
231
272
  logger=logger,
273
+ company_id=company_id,
274
+ readable_skill_versions=readable_skill_versions,
232
275
  )
233
276
 
234
277
  if not skill_registry:
@@ -18,6 +18,7 @@ from unique_internal_search.service import InternalSearchTool
18
18
  from unique_internal_search.uploaded_search.config import (
19
19
  UploadedSearchConfig,
20
20
  )
21
+ from unique_skill_tool.service import SkillTool
21
22
  from unique_stock_ticker.config import StockTickerConfig
22
23
  from unique_swot import SwotAnalysisTool, SwotAnalysisToolConfig
23
24
  from unique_toolkit._common.pydantic.rjsf_tags import RJSFMetaTag
@@ -211,6 +212,7 @@ class SpaceConfigBase(BaseToolConfig, Generic[T]):
211
212
  InternalSearchTool.name,
212
213
  WebSearchTool.name,
213
214
  RetrieveSearchScopeTool.name,
215
+ SkillTool.name,
214
216
  ):
215
217
  tool.configuration.language_model_max_input_tokens = ( # type: ignore
216
218
  info.data["language_model"].token_limits.token_limit_input
@@ -702,6 +702,9 @@ async def _build_responses(
702
702
  selectable_skills=normalize_available_skills_for_tool(
703
703
  event.payload.available_skills
704
704
  ),
705
+ user_id=event.user_id,
706
+ company_id=event.company_id,
707
+ space_id=event.payload.assistant_id,
705
708
  )
706
709
 
707
710
  loop_iteration_runner = build_responses_loop_iteration_runner(
@@ -828,6 +831,9 @@ async def _build_completions(
828
831
  selectable_skills=normalize_available_skills_for_tool(
829
832
  event.payload.available_skills
830
833
  ),
834
+ user_id=event.user_id,
835
+ company_id=event.company_id,
836
+ space_id=event.payload.assistant_id,
831
837
  )
832
838
 
833
839
  postprocessor_manager = common_components.postprocessor_manager