|
| 1 | +""" |
| 2 | +SkillOrchestra Example |
| 3 | +
|
| 4 | +Demonstrates skill-aware agent routing where tasks are decomposed into |
| 5 | +fine-grained skills, agents are scored on competence and cost, and the |
| 6 | +best-matched agent is selected for execution. |
| 7 | +
|
| 8 | +Based on the paper: "SkillOrchestra: Learning to Route Agents via Skill Transfer" |
| 9 | +https://arxiv.org/abs/2602.19672 |
| 10 | +""" |
| 11 | + |
| 12 | +from swarms.structs.agent import Agent |
| 13 | +from swarms.structs.skill_orchestra import SkillOrchestra |
| 14 | + |
| 15 | +# --- Define agents with distinct specializations --- |
| 16 | + |
| 17 | +code_agent = Agent( |
| 18 | + agent_name="CodeExpert", |
| 19 | + description="Expert Python developer who writes clean, efficient, production-ready code", |
| 20 | + system_prompt=( |
| 21 | + "You are an expert Python developer. Write clean, well-documented, " |
| 22 | + "production-ready code with proper error handling and type hints." |
| 23 | + ), |
| 24 | + model_name="gpt-4o-mini", |
| 25 | + max_loops=1, |
| 26 | +) |
| 27 | + |
| 28 | +writer_agent = Agent( |
| 29 | + agent_name="TechWriter", |
| 30 | + description="Technical writing specialist who creates clear documentation and tutorials", |
| 31 | + system_prompt=( |
| 32 | + "You are a technical writing specialist. Write clear, comprehensive " |
| 33 | + "documentation with examples, explanations, and proper formatting." |
| 34 | + ), |
| 35 | + model_name="gpt-4o-mini", |
| 36 | + max_loops=1, |
| 37 | +) |
| 38 | + |
| 39 | +researcher_agent = Agent( |
| 40 | + agent_name="Researcher", |
| 41 | + description="Research analyst who gathers, synthesizes, and compares information", |
| 42 | + system_prompt=( |
| 43 | + "You are a research analyst. Provide thorough, well-structured analysis " |
| 44 | + "with comparisons, trade-offs, and actionable recommendations." |
| 45 | + ), |
| 46 | + model_name="gpt-4o-mini", |
| 47 | + max_loops=1, |
| 48 | +) |
| 49 | + |
| 50 | +# --- Create SkillOrchestra (auto-generates skill handbook from agent descriptions) --- |
| 51 | + |
| 52 | +orchestra = SkillOrchestra( |
| 53 | + name="DevTeamOrchestra", |
| 54 | + agents=[code_agent, writer_agent, researcher_agent], |
| 55 | + model="gpt-4o-mini", |
| 56 | + top_k_agents=1, # Select the single best agent per task |
| 57 | + learning_enabled=False, # Set True to update skill profiles after execution |
| 58 | + output_type="final", # Return only the final agent output |
| 59 | +) |
| 60 | + |
| 61 | +# The handbook was auto-generated. Inspect it: |
| 62 | +print("Generated Skill Handbook:") |
| 63 | +for skill in orchestra.skill_handbook.skills: |
| 64 | + print(f" - {skill.name}: {skill.description}") |
| 65 | +print() |
| 66 | + |
| 67 | +# --- Run tasks: each should route to the most competent agent --- |
| 68 | + |
| 69 | +# This should route to CodeExpert |
| 70 | +result = orchestra.run("Write a Python function to parse and validate JSON config files") |
| 71 | +print("=" * 60) |
| 72 | +print("Result:") |
| 73 | +print(result[:500] if isinstance(result, str) else str(result)[:500]) |
0 commit comments