agent0-sdk 0.31__py3-none-any.whl

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.
@@ -0,0 +1,98 @@
1
+ """
2
+ OASF taxonomy validation utilities.
3
+ """
4
+
5
+ import json
6
+ import os
7
+ from pathlib import Path
8
+ from typing import Optional
9
+
10
+ # Cache for loaded taxonomy data
11
+ _skills_cache: Optional[dict] = None
12
+ _domains_cache: Optional[dict] = None
13
+
14
+
15
+ def _get_taxonomy_path(filename: str) -> Path:
16
+ """Get the path to a taxonomy file."""
17
+ # Get the directory where this file is located
18
+ current_dir = Path(__file__).parent
19
+ # Go up one level to agent0_sdk, then into taxonomies
20
+ taxonomy_dir = current_dir.parent / "taxonomies"
21
+ return taxonomy_dir / filename
22
+
23
+
24
+ def _load_skills() -> dict:
25
+ """Load skills taxonomy file with caching."""
26
+ global _skills_cache
27
+ if _skills_cache is None:
28
+ skills_path = _get_taxonomy_path("all_skills.json")
29
+ try:
30
+ with open(skills_path, "r", encoding="utf-8") as f:
31
+ _skills_cache = json.load(f)
32
+ except FileNotFoundError:
33
+ raise FileNotFoundError(
34
+ f"Skills taxonomy file not found: {skills_path}"
35
+ )
36
+ except json.JSONDecodeError as e:
37
+ raise ValueError(
38
+ f"Invalid JSON in skills taxonomy file: {e}"
39
+ )
40
+ return _skills_cache
41
+
42
+
43
+ def _load_domains() -> dict:
44
+ """Load domains taxonomy file with caching."""
45
+ global _domains_cache
46
+ if _domains_cache is None:
47
+ domains_path = _get_taxonomy_path("all_domains.json")
48
+ try:
49
+ with open(domains_path, "r", encoding="utf-8") as f:
50
+ _domains_cache = json.load(f)
51
+ except FileNotFoundError:
52
+ raise FileNotFoundError(
53
+ f"Domains taxonomy file not found: {domains_path}"
54
+ )
55
+ except json.JSONDecodeError as e:
56
+ raise ValueError(
57
+ f"Invalid JSON in domains taxonomy file: {e}"
58
+ )
59
+ return _domains_cache
60
+
61
+
62
+ def validate_skill(slug: str) -> bool:
63
+ """
64
+ Validate if a skill slug exists in the OASF taxonomy.
65
+
66
+ Args:
67
+ slug: The skill slug to validate (e.g., "natural_language_processing/summarization")
68
+
69
+ Returns:
70
+ True if the skill exists in the taxonomy, False otherwise
71
+
72
+ Raises:
73
+ FileNotFoundError: If the taxonomy file cannot be found
74
+ ValueError: If the taxonomy file is invalid JSON
75
+ """
76
+ skills_data = _load_skills()
77
+ skills = skills_data.get("skills", {})
78
+ return slug in skills
79
+
80
+
81
+ def validate_domain(slug: str) -> bool:
82
+ """
83
+ Validate if a domain slug exists in the OASF taxonomy.
84
+
85
+ Args:
86
+ slug: The domain slug to validate (e.g., "finance_and_business/investment_services")
87
+
88
+ Returns:
89
+ True if the domain exists in the taxonomy, False otherwise
90
+
91
+ Raises:
92
+ FileNotFoundError: If the taxonomy file cannot be found
93
+ ValueError: If the taxonomy file is invalid JSON
94
+ """
95
+ domains_data = _load_domains()
96
+ domains = domains_data.get("domains", {})
97
+ return slug in domains
98
+