fix: use Path for pydantic validation

This commit is contained in:
Greyson Lalonde
2026-03-05 21:08:30 -05:00
parent 15f7a2ccd8
commit 2baebb935a
3 changed files with 16 additions and 12 deletions

View File

@@ -215,9 +215,10 @@ class BaseAgent(BaseModel, ABC, metaclass=AgentMeta):
"If not set, falls back to crew memory."
),
)
skills: list[str | Path | Skill] | None = Field(
skills: list[Path | Skill] | None = Field(
default=None,
description="Agent Skills. Accepts paths (str or Path) for discovery or pre-loaded Skill objects.",
description="Agent Skills. Accepts paths for discovery or pre-loaded Skill objects.",
min_length=1,
)
@field_validator("skills", mode="before")

View File

@@ -5,6 +5,7 @@ Events emitted during skill discovery, loading, and activation.
from __future__ import annotations
from pathlib import Path
from typing import Any
from crewai.events.base_events import BaseEvent
@@ -14,7 +15,7 @@ class SkillEvent(BaseEvent):
"""Base event for skill operations."""
skill_name: str = ""
skill_path: str | None = None
skill_path: Path | None = None
from_agent: Any | None = None
from_task: Any | None = None
@@ -28,13 +29,14 @@ class SkillDiscoveryStartedEvent(SkillEvent):
"""Event emitted when skill discovery begins."""
type: str = "skill_discovery_started"
search_path: str
search_path: Path
class SkillDiscoveryCompletedEvent(SkillEvent):
"""Event emitted when skill discovery completes."""
type: str = "skill_discovery_completed"
search_path: Path
skills_found: int
skill_names: list[str]

View File

@@ -41,16 +41,17 @@ def discover_skills(
Returns:
List of Skill instances at METADATA level.
"""
skills: list[Skill] = []
if not search_path.is_dir():
return skills
msg = f"Skill search path does not exist or is not a directory: {search_path}"
raise FileNotFoundError(msg)
skills: list[Skill] = []
if source is not None:
crewai_event_bus.emit(
source,
event=SkillDiscoveryStartedEvent(
search_path=str(search_path),
search_path=search_path,
),
)
@@ -68,7 +69,7 @@ def discover_skills(
source,
event=SkillLoadedEvent(
skill_name=skill.name,
skill_path=str(skill.path),
skill_path=skill.path,
disclosure_level=skill.disclosure_level.value,
),
)
@@ -78,7 +79,7 @@ def discover_skills(
source,
event=SkillLoadFailedEvent(
skill_name=child.name,
skill_path=str(child),
skill_path=child,
error=str(e),
),
)
@@ -87,7 +88,7 @@ def discover_skills(
crewai_event_bus.emit(
source,
event=SkillDiscoveryCompletedEvent(
search_path=str(search_path),
search_path=search_path,
skills_found=len(skills),
skill_names=[s.name for s in skills],
),
@@ -121,7 +122,7 @@ def activate_skill(
source,
event=SkillActivatedEvent(
skill_name=activated.name,
skill_path=str(activated.path),
skill_path=activated.path,
disclosure_level=activated.disclosure_level.value,
),
)