feat!: unify prompts and skills into shared templates and registry#20
feat!: unify prompts and skills into shared templates and registry#20SalemBajjali wants to merge 34 commits into
Conversation
…emplates and registry
korikuzma
left a comment
There was a problem hiding this comment.
Quick review - also I think we need to change the PR title since it is a breaking change. refactor -> feat!:
See https://www.conventionalcommits.org/en/v1.0.0/
Will do a deep dive later this week
There was a problem hiding this comment.
We should think about the case where PromptTemplate and SkillTemplate share the same name/version. Currently, one would overwrite the other in the registry. We should consider adding a template_type optional parameter to help distinguish which to use (if this is valid use case) or raise ValueError if name/version already exists in the registry (if this is invalid use case)
There was a problem hiding this comment.
- I updated the registry to include task_type as part of the registry key, so templates are now stored by (name, version, task_type) instead of just (name, version).
- This allows a PromptTemplate and SkillTemplate to share the same name/version without overwriting each other. The registry determines the task type internally during registration based on the template instance, and get() now requires the task type so retrieval is explicit.
- I also added a duplicate check so registering the same (name, version, task_type) combination raises a ValueError instead of silently replacing the existing template.
- I added tests to cover both behaviors: one test confirms that a prompt and skill can share the same name/version, and another confirms that registering a duplicate skill with the same name/version raises a ValueError.
- NOTE: I noticed the registry tests may be a bit scattered, such as test_registry.py and test_skill_registry.py. We may want to combine them or move them under a dedicated registry test folder. I can open a separate issue for this or update it directly in this PR if preferred.
korikuzma
left a comment
There was a problem hiding this comment.
Talked about this yesterday, but posting in GH too:
- Need to pull in changes from main branch, update the skills nb
- Proposals for registry name/version conflict
| MAX_LOG_CHARS = int(getenv("MAX_LOG_CHARS", "500")) | ||
|
|
||
|
|
||
| class TaskKind(Enum): |
There was a problem hiding this comment.
This would be my preference
| class TaskKind(Enum): | |
| class TaskType(Enum): |
There was a problem hiding this comment.
What are your thoughts of changing the attribute name from kind to type as well in _execute?
| _logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class TaskType(Enum): |
There was a problem hiding this comment.
Thinking about this more... I change my mind and think we should rename task type to template type. The registry doesn't need to care about tasks and is only concerned with templates.
| class TaskType(Enum): | |
| class TemplateType(Enum): |
This leads into a larger change that I think would clean this up.
- Move TemplateType enum to templates/base.py
- Change the current PromptTemplate to BaseTemplate, with a new class variable (
template_class: ClassVar[TemplateType]) - Create new module for PromptTemplate (templates/prompt_template.py), which would only include:
class PromptTemplate(BaseTemplate):
template_type = TemplateType.PROMPT- Update SkillTemplate to follow similar approach to PromptTemplate (inherit from BaseTemplate and include new template_type class var)
- Then in here (registry), we could do the following:
_TEMPLATE_CLASS_TO_TYPE = MappingProxyType({
SkillTemplate: TemplateType.SKILL,
PromptTemplate: TemplateType.PROMPT,
})Then in the register method, we could do the following
try:
template_type = _TEMPLATE_CLASS_TO_TYPE[type(template)]
except KeyError:
msg = f"Unsupported template type: {type(template)}"
raise TypeError(msg) from Noneand remove the helper method
| task_type.value, | ||
| ) | ||
|
|
||
| if key in self._templates: |
There was a problem hiding this comment.
Good. Update docstring with this error please
| import re | ||
| from collections.abc import Mapping | ||
|
|
||
| # NEW |
Closes #17
This PR addresses the structural changes discussed in #17.
Changes
Templates
Registry
StructuredTaskRunner
Tests
Notebooks