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 2 |
+
import json
|
| 3 |
+
import random
|
| 4 |
+
from typing import Dict, List, Any, Tuple
|
| 5 |
+
|
| 6 |
+
# Simulate OMC Talent Market data
|
| 7 |
+
TALENT_DATABASE = {
|
| 8 |
+
"research_analyst": {
|
| 9 |
+
"name": "ResearchAnalyst",
|
| 10 |
+
"skills": ["web_search", "summarization", "fact_checking"],
|
| 11 |
+
"tools": ["browser", "search_api", "document_reader"],
|
| 12 |
+
"backend": "gpt-4-class",
|
| 13 |
+
"cost_per_task": 0.02,
|
| 14 |
+
"reliability": 0.95
|
| 15 |
+
},
|
| 16 |
+
"code_generator": {
|
| 17 |
+
"name": "CodeGenerator",
|
| 18 |
+
"skills": ["python", "javascript", "api_integration"],
|
| 19 |
+
"tools": ["code_interpreter", "git", "shell"],
|
| 20 |
+
"backend": "claude-class",
|
| 21 |
+
"cost_per_task": 0.03,
|
| 22 |
+
"reliability": 0.92
|
| 23 |
+
},
|
| 24 |
+
"data_processor": {
|
| 25 |
+
"name": "DataProcessor",
|
| 26 |
+
"skills": ["pandas", "sql", "visualization"],
|
| 27 |
+
"tools": ["sqlite", "matplotlib", "csv_parser"],
|
| 28 |
+
"backend": "local-llm",
|
| 29 |
+
"cost_per_task": 0.01,
|
| 30 |
+
"reliability": 0.88
|
| 31 |
+
},
|
| 32 |
+
"review_auditor": {
|
| 33 |
+
"name": "ReviewAuditor",
|
| 34 |
+
"skills": ["quality_check", "error_detection", "consistency_verification"],
|
| 35 |
+
"tools": ["diff_tool", "test_runner", "linter"],
|
| 36 |
+
"backend": "gpt-4-class",
|
| 37 |
+
"cost_per_task": 0.025,
|
| 38 |
+
"reliability": 0.97
|
| 39 |
+
},
|
| 40 |
+
"planner_orchestrator": {
|
| 41 |
+
"name": "PlannerOrchestrator",
|
| 42 |
+
"skills": ["task_decomposition", "dependency_analysis", "scheduling"],
|
| 43 |
+
"tools": ["graph_builder", "timeline_tracker"],
|
| 44 |
+
"backend": "o1-class",
|
| 45 |
+
"cost_per_task": 0.05,
|
| 46 |
+
"reliability": 0.93
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
TASK_TEMPLATES = [
|
| 51 |
+
{
|
| 52 |
+
"id": "t1",
|
| 53 |
+
"description": "Research competitor pricing and generate comparison report",
|
| 54 |
+
"required_skills": ["web_search", "summarization", "pandas", "visualization"],
|
| 55 |
+
"complexity": "medium",
|
| 56 |
+
"budget": 0.10
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"id": "t2",
|
| 60 |
+
"description": "Build Python API client for REST service with error handling",
|
| 61 |
+
"required_skills": ["python", "api_integration", "quality_check"],
|
| 62 |
+
"complexity": "high",
|
| 63 |
+
"budget": 0.12
|
| 64 |
+
},
|
| 65 |
+
{
|
| 66 |
+
"id": "t3",
|
| 67 |
+
"description": "Analyze CSV sales data and create trend dashboard",
|
| 68 |
+
"required_skills": ["pandas", "sql", "visualization"],
|
| 69 |
+
"complexity": "low",
|
| 70 |
+
"budget": 0.06
|
| 71 |
+
},
|
| 72 |
+
{
|
| 73 |
+
"id": "t4",
|
| 74 |
+
"description": "Review code for security vulnerabilities in authentication module",
|
| 75 |
+
"required_skills": ["quality_check", "error_detection", "python"],
|
| 76 |
+
"complexity": "high",
|
| 77 |
+
"budget": 0.15
|
| 78 |
+
}
|
| 79 |
+
]
|
| 80 |
+
|
| 81 |
+
def calculate_skill_match(talent_skills: List[str], required: List[str]) -> float:
|
| 82 |
+
if not required:
|
| 83 |
+
return 1.0
|
| 84 |
+
matches = sum(1 for skill in required if skill in talent_skills)
|
| 85 |
+
return matches / len(required)
|
| 86 |
+
|
| 87 |
+
def recruit_talents_for_task(task_idx: int) -> Tuple[str, str]:
|
| 88 |
+
if task_idx < 0 or task_idx >= len(TASK_TEMPLATES):
|
| 89 |
+
return "Invalid task selection", "{}"
|
| 90 |
+
|
| 91 |
+
task = TASK_TEMPLATES[task_idx]
|
| 92 |
+
required_skills = set(task["required_skills"])
|
| 93 |
+
budget = task["budget"]
|
| 94 |
+
|
| 95 |
+
recruited = []
|
| 96 |
+
covered_skills = set()
|
| 97 |
+
total_cost = 0.0
|
| 98 |
+
|
| 99 |
+
steps_log = [f"🎯 TASK: {task['description']}",
|
| 100 |
+
f"📋 Required skills: {', '.join(required_skills)}",
|
| 101 |
+
f"💰 Budget: ${budget:.3f}",
|
| 102 |
+
"═" * 50]
|
| 103 |
+
|
| 104 |
+
while covered_skills != required_skills and total_cost < budget:
|
| 105 |
+
best_talent = None
|
| 106 |
+
best_value = 0
|
| 107 |
+
|
| 108 |
+
for talent_id, talent in TALENT_DATABASE.items():
|
| 109 |
+
if talent_id in [r["id"] for r in recruited]:
|
| 110 |
+
continue
|
| 111 |
+
|
| 112 |
+
new_coverage = required_skills - covered_skills
|
| 113 |
+
talent_skills = set(talent["skills"])
|
| 114 |
+
covered_by_this = len(new_coverage & talent_skills)
|
| 115 |
+
|
| 116 |
+
if covered_by_this == 0:
|
| 117 |
+
continue
|
| 118 |
+
|
| 119 |
+
value = (covered_by_this / talent["cost_per_task"]) * talent["reliability"]
|
| 120 |
+
|
| 121 |
+
if value > best_value and total_cost + talent["cost_per_task"] <= budget:
|
| 122 |
+
best_value = value
|
| 123 |
+
best_talent = talent_id
|
| 124 |
+
|
| 125 |
+
if best_talent is None:
|
| 126 |
+
break
|
| 127 |
+
|
| 128 |
+
talent = TALENT_DATABASE[best_talent]
|
| 129 |
+
recruited.append({
|
| 130 |
+
"id": best_talent,
|
| 131 |
+
"name": talent["name"],
|
| 132 |
+
"cost": talent["cost_per_task"],
|
| 133 |
+
"skills_added": list(set(talent["skills"]) & required_skills - covered_skills)
|
| 134 |
+
})
|
| 135 |
+
|
| 136 |
+
for skill in talent["skills"]:
|
| 137 |
+
covered_skills.add(skill)
|
| 138 |
+
|
| 139 |
+
total_cost += talent["cost_per_task"]
|
| 140 |
+
|
| 141 |
+
steps_log.append(f"✅ RECRUITED: {talent['name']}")
|
| 142 |
+
steps_log.append(f" 💵 Cost: ${talent['cost_per_task']:.3f}")
|
| 143 |
+
steps_log.append(f" 🛠️ Skills covered: {', '.join(talent['skills'])}")
|
| 144 |
+
steps_log.append(f" 📊 Coverage: {len(covered_skills & required_skills)}/{len(required_skills)} skills")
|
| 145 |
+
steps_log.append("")
|
| 146 |
+
|
| 147 |
+
uncovered = required_skills - covered_skills
|
| 148 |
+
if uncovered:
|
| 149 |
+
steps_log.append(f"⚠️ WARNING: Uncovered skills: {', '.join(uncovered)}")
|
| 150 |
+
steps_log.append(" Consider increasing budget or adding specialized talents")
|
| 151 |
+
else:
|
| 152 |
+
steps_log.append("🎉 FULL COVERAGE ACHIEVED!")
|
| 153 |
+
|
| 154 |
+
steps_log.append("═" * 50)
|
| 155 |
+
steps_log.append(f"💵 Total Cost: ${total_cost:.3f} / ${budget:.3f}")
|
| 156 |
+
steps_log.append(f"👥 Team Size: {len(recruited)} talents")
|
| 157 |
+
|
| 158 |
+
result_json = {
|
| 159 |
+
"task": task["description"],
|
| 160 |
+
"recruited_talents": recruited,
|
| 161 |
+
"total_cost": round(total_cost, 4),
|
| 162 |
+
"budget": budget,
|
| 163 |
+
"coverage_ratio": len(covered_skills & required_skills) / len(required_skills),
|
| 164 |
+
"success": len(uncovered) == 0
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
return "\n".join(steps_log), json.dumps(result_json, indent=2)
|
| 168 |
+
|
| 169 |
+
def simulate_e2r_tree(task_description: str, exploration_width: int, max_depth: int) -> str:
|
| 170 |
+
steps = [f"🌳 E²R TREE SEARCH SIMULATION",
|
| 171 |
+
f"Task: {task_description}",
|
| 172 |
+
f"Parameters: width={exploration_width}, max_depth={max_depth}",
|
| 173 |
+
"═" * 50]
|
| 174 |
+
|
| 175 |
+
steps.append("\n📥 PHASE 1: EXPLORE (Top-down decomposition)")
|
| 176 |
+
|
| 177 |
+
subtasks = [
|
| 178 |
+
{"name": f"Subtask_{i+1}",
|
| 179 |
+
"estimated_difficulty": random.choice(["low", "medium", "high"]),
|
| 180 |
+
"candidates": min(exploration_width, 3 + i)}
|
| 181 |
+
for i in range(min(5, max_depth * 2))
|
| 182 |
+
]
|
| 183 |
+
|
| 184 |
+
for st in subtasks:
|
| 185 |
+
steps.append(f" └─ {st['name']} [{st['estimated_difficulty']}] → {st['candidates']} candidate approaches")
|
| 186 |
+
|
| 187 |
+
steps.append("\n⚡ PHASE 2: EXECUTE (Execution & branching)")
|
| 188 |
+
|
| 189 |
+
total_attempts = 0
|
| 190 |
+
successful = 0
|
| 191 |
+
|
| 192 |
+
for st in subtasks:
|
| 193 |
+
attempts = min(st["candidates"], exploration_width)
|
| 194 |
+
for j in range(attempts):
|
| 195 |
+
total_attempts += 1
|
| 196 |
+
success_prob = 0.7 if st["estimated_difficulty"] == "low" else (0.5 if st["estimated_difficulty"] == "medium" else 0.3)
|
| 197 |
+
outcome = "✓" if random.random() < success_prob else "✗"
|
| 198 |
+
if outcome == "✓":
|
| 199 |
+
successful += 1
|
| 200 |
+
steps.append(f" ├─ {st['name']}/attempt_{j+1}: {outcome}")
|
| 201 |
+
|
| 202 |
+
steps.append("\n🔍 PHASE 3: REVIEW (Bottom-up aggregation)")
|
| 203 |
+
|
| 204 |
+
completion_rate = successful / total_attempts if total_attempts > 0 else 0
|
| 205 |
+
|
| 206 |
+
if completion_rate >= 0.8:
|
| 207 |
+
verdict = "TERMINATE_SUCCESS"
|
| 208 |
+
steps.append(f" └─ Aggregate success rate: {completion_rate:.1%}")
|
| 209 |
+
steps.append(f" └─ Verdict: {verdict}")
|
| 210 |
+
steps.append(f" └─ Output: Final deliverable compiled from {successful} successful subtask executions")
|
| 211 |
+
elif completion_rate >= 0.5:
|
| 212 |
+
verdict = "REFINE_PARTIAL"
|
| 213 |
+
steps.append(f" └─ Aggregate success rate: {completion_rate:.1%}")
|
| 214 |
+
steps.append(f" └─ Verdict: {verdict}")
|
| 215 |
+
steps.append(f" └─ Action: Retry failed {total_attempts - successful} subtasks with adjusted parameters")
|
| 216 |
+
else:
|
| 217 |
+
verdict = "REFINE_ALL"
|
| 218 |
+
steps.append(f" └─ Aggregate success rate: {completion_rate:.1%}")
|
| 219 |
+
steps.append(f" └─ Verdict: {verdict}")
|
| 220 |
+
steps.append(f" └─ Action: Backtrack to EXPLORE phase with wider width")
|
| 221 |
+
|
| 222 |
+
steps.append("\n" + "═" * 50)
|
| 223 |
+
steps.append(f"📊 Summary: {successful}/{total_attempts} attempts succeeded ({completion_rate:.1%})")
|
| 224 |
+
steps.append(f"🔄 Termination guarantee: Tree depth bounded, deadlock-free by construction")
|
| 225 |
+
|
| 226 |
+
return "\n".join(steps)
|
| 227 |
+
|
| 228 |
+
def get_talent_info() -> str:
|
| 229 |
+
lines = ["📚 AVAILABLE TALENTS IN MARKET", "═" * 60]
|
| 230 |
+
|
| 231 |
+
for tid, talent in TALENT_DATABASE.items():
|
| 232 |
+
lines.append(f"\n🔹 {talent['name']} (ID: {tid})")
|
| 233 |
+
lines.append(f" Skills: {', '.join(talent['skills'])}")
|
| 234 |
+
lines.append(f" Tools: {', '.join(talent['tools'])}")
|
| 235 |
+
lines.append(f" Backend: {talent['backend']}")
|
| 236 |
+
lines.append(f" Cost: ${talent['cost_per_task']:.3f} | Reliability: {talent['reliability']:.0%}")
|
| 237 |
+
|
| 238 |
+
return "\n".join(lines)
|
| 239 |
+
|
| 240 |
+
with gr.Blocks(title="OneManCompany Explorer") as demo:
|
| 241 |
+
gr.Markdown("""
|
| 242 |
+
# 🏢 OneManCompany (OMC) - Organizational Layer Demo
|
| 243 |
+
|
| 244 |
+
Explore the framework from ["From Skills to Talent"](https://huggingface.co/papers/2604.22446) (Yu et al., 2026)
|
| 245 |
+
|
| 246 |
+
This interactive demo illustrates two core OMC concepts:
|
| 247 |
+
1. **Talent Market** - Dynamic recruitment of portable agent identities
|
| 248 |
+
2. **E²R Tree Search** - Explore-Execute-Review hierarchical decision loop
|
| 249 |
+
""")
|
| 250 |
+
|
| 251 |
+
with gr.Tab("📋 Talent Market"):
|
| 252 |
+
gr.Markdown("Simulate OMC's on-demand talent recruitment for capability gaps")
|
| 253 |
+
|
| 254 |
+
task_dropdown = gr.Dropdown(
|
| 255 |
+
choices=[(f"{t['id']}: {t['description'][:50]}...", i) for i, t in enumerate(TASK_TEMPLATES)],
|
| 256 |
+
value=0,
|
| 257 |
+
label="Select Task"
|
| 258 |
+
)
|
| 259 |
+
|
| 260 |
+
with gr.Row():
|
| 261 |
+
with gr.Column(scale=2):
|
| 262 |
+
recruit_btn = gr.Button("🎯 Recruit Optimal Team", variant="primary")
|
| 263 |
+
talent_display = gr.Textbox(label="Available Talents", value=get_talent_info(), lines=15)
|
| 264 |
+
|
| 265 |
+
with gr.Column(scale=3):
|
| 266 |
+
recruitment_log = gr.Textbox(label="Recruitment Log", lines=12)
|
| 267 |
+
json_output = gr.Textbox(label="Structured Result (JSON)", lines=8)
|
| 268 |
+
|
| 269 |
+
recruit_btn.click(
|
| 270 |
+
fn=recruit_talents_for_task,
|
| 271 |
+
inputs=task_dropdown,
|
| 272 |
+
outputs=[recruitment_log, json_output]
|
| 273 |
+
)
|
| 274 |
+
|
| 275 |
+
with gr.Tab("🌳 E²R Tree Search"):
|
| 276 |
+
gr.Markdown("Simulate the Explore-Execute-Review hierarchical loop with termination guarantees")
|
| 277 |
+
|
| 278 |
+
task_input = gr.Textbox(
|
| 279 |
+
label="Task Description",
|
| 280 |
+
value="Build a web scraper that extracts product prices and alerts on changes",
|
| 281 |
+
lines=2
|
| 282 |
+
)
|
| 283 |
+
|
| 284 |
+
with gr.Row():
|
| 285 |
+
width_slider = gr.Slider(1, 5, value=3, step=1, label="Exploration Width (branching factor)")
|
| 286 |
+
depth_slider = gr.Slider(1, 4, value=2, step=1, label="Max Tree Depth")
|
| 287 |
+
|
| 288 |
+
run_e2r_btn = gr.Button("▶️ Run E²R Simulation", variant="primary")
|
| 289 |
+
e2r_output = gr.Textbox(label="E²R Execution Trace", lines=25)
|
| 290 |
+
|
| 291 |
+
run_e2r_btn.click(
|
| 292 |
+
fn=simulate_e2r_tree,
|
| 293 |
+
inputs=[task_input, width_slider, depth_slider],
|
| 294 |
+
outputs=e2r_output
|
| 295 |
+
)
|
| 296 |
+
|
| 297 |
+
with gr.Tab("ℹ️ About OMC"):
|
| 298 |
+
gr.Markdown("""
|
| 299 |
+
### Core Contributions from the Paper
|
| 300 |
+
|
| 301 |
+
**OneManCompany** addresses a fundamental gap in multi-agent systems: the absence of a
|
| 302 |
+
principled *organizational layer* that governs how agent workforces are assembled,
|
| 303 |
+
governed, and improved over time.
|
| 304 |
+
|
| 305 |
+
#### Key Innovations:
|
| 306 |
+
|
| 307 |
+
1. **Talent Abstraction** - Encapsulates skills, tools, and runtime configs into
|
| 308 |
+
portable identities that abstract over heterogeneous backends
|
| 309 |
+
|
| 310 |
+
2. **Talent Market** - Community-driven recruitment enabling on-demand capability
|
| 311 |
+
acquisition and dynamic team reconfiguration
|
| 312 |
+
|
| 313 |
+
3. **E²R Tree Search** - Unified hierarchical loop combining:
|
| 314 |
+
- **Explore**: Top-down task decomposition into accountable units
|
| 315 |
+
- **Execute**: Mid-level plan execution with branching
|
| 316 |
+
- **Review**: Bottom-up outcome aggregation and refinement
|
| 317 |
+
|
| 318 |
+
4. **Formal Guarantees**: Termination and deadlock-freedom by construction
|
| 319 |
+
|
| 320 |
+
#### Empirical Results:
|
| 321 |
+
- **84.67%** success rate on PRDBench (surpassing SOTA by 15.48pp)
|
| 322 |
+
- Cross-domain generalization demonstrated
|
| 323 |
+
""")
|
| 324 |
+
|
| 325 |
+
if __name__ == "__main__":
|
| 326 |
+
demo.launch()
|