Compile a single skill from the KB's wiki. Returns the path to the produced skill directory. Raises ``RuntimeError`` if the agent finishes without writing ``SKILL.md``, or if the SDK hits its turn cap before the agent declares done.
(
*,
kb_dir: Path,
skill_name: str,
intent: str,
model: str,
)
| 170 | |
| 171 | |
| 172 | async def run_skill_create( |
| 173 | *, |
| 174 | kb_dir: Path, |
| 175 | skill_name: str, |
| 176 | intent: str, |
| 177 | model: str, |
| 178 | ) -> Path: |
| 179 | """Compile a single skill from the KB's wiki. |
| 180 | |
| 181 | Returns the path to the produced skill directory. Raises |
| 182 | ``RuntimeError`` if the agent finishes without writing ``SKILL.md``, |
| 183 | or if the SDK hits its turn cap before the agent declares done. |
| 184 | """ |
| 185 | wiki_root = str(kb_dir / "wiki") |
| 186 | skill_root = skill_dir(kb_dir, skill_name) |
| 187 | |
| 188 | agent = build_skill_create_agent( |
| 189 | wiki_root=wiki_root, |
| 190 | skill_root=str(skill_root), |
| 191 | skill_name=skill_name, |
| 192 | intent=intent, |
| 193 | model=model, |
| 194 | ) |
| 195 | |
| 196 | # Single user message kicks off the compile. The system prompt already |
| 197 | # contains the intent — this just nudges the agent to start. |
| 198 | seed = ( |
| 199 | f"Compile the skill '{skill_name}'. Follow the system prompt's " |
| 200 | f"working method. Read the wiki, then write the skill files." |
| 201 | ) |
| 202 | |
| 203 | # Lazy import: keeps the top of this module independent of the SDK's |
| 204 | # internal exception layout in case its export path moves. |
| 205 | from agents.exceptions import MaxTurnsExceeded |
| 206 | |
| 207 | try: |
| 208 | await Runner.run(agent, seed, max_turns=MAX_TURNS) |
| 209 | except MaxTurnsExceeded as exc: |
| 210 | raise RuntimeError( |
| 211 | f"Skill compilation hit the {MAX_TURNS}-step cap before finishing. " |
| 212 | f"The wiki may be too large for a single skill, or the intent may " |
| 213 | f"be too broad. Try splitting into multiple skills with narrower " |
| 214 | f"intents, or pass a smaller wiki subset." |
| 215 | ) from exc |
| 216 | |
| 217 | if not (skill_root / "SKILL.md").exists(): |
| 218 | raise RuntimeError( |
| 219 | f"Skill compilation finished but agent did not write SKILL.md " |
| 220 | f"at {skill_root}. The skill is incomplete; check the wiki has " |
| 221 | f"content related to your intent." |
| 222 | ) |
| 223 | |
| 224 | return skill_root |