Repository navigation
feat: route orchestration decisions through ai - #9
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis PR adds an AI routing subsystem to the detector that consults an external provider to decide multi-vs-single agent execution, optionally overriding planner decisions, and tracks routing provenance through result metadata and CLI output across all detection paths. ChangesAI Routing and Detector Enhancement
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR introduces an AI-assisted routing layer for collaboration detection, allowing an LLM to override the planner’s initial single-/multi-agent decision and emitting metadata about how and why a routing decision was made.
Changes:
- Add
ai_routingconfiguration (template + defaults) to enable AI-driven routing decisions with a configurable provider/timeout. - Extend
CollaborationDetectorto call a provider CLI for a compact JSON routing decision and apply it to the orchestration plan (including forcing single- vs multi-agent). - Surface routing decision provenance (
routing_decision_source/routing_decision_reason) in both the CLI output and tests.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
ai_collab/core/detector.py |
Adds AI routing decision execution/parsing and threads decision metadata through CollaborationResult. |
ai_collab/core/config.py |
Adds ai_routing to the default auto-collaboration configuration. |
config/config.template.json |
Exposes auto_collaboration.ai_routing in the user-facing config template. |
ai_collab/cli.py |
Prints routing decision source/reason in ai-collab detect output. |
tests/test_detector.py |
Adds a unit test asserting AI routing can force a multi-agent review plan. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| start = raw.find("{") | ||
| while start >= 0: | ||
| depth = 0 | ||
| for index in range(start, len(raw)): | ||
| char = raw[index] | ||
| if char == "{": | ||
| depth += 1 | ||
| elif char == "}": | ||
| depth -= 1 | ||
| if depth == 0: | ||
| candidate = raw[start : index + 1] | ||
| try: | ||
| value = json.loads(candidate) | ||
| except json.JSONDecodeError: | ||
| break | ||
| return value if isinstance(value, dict) else None | ||
| start = raw.find("{", start + 1) | ||
| return None |
| "ai_routing": { | ||
| "enabled": true, | ||
| "provider": "current", | ||
| "timeout": 20 | ||
| }, |
| def default_auto_collaboration_config() -> Dict[str, Any]: | ||
| return { | ||
| "enabled": True, | ||
| "auto_orchestration_enabled": True, | ||
| "ai_routing": { | ||
| "enabled": True, | ||
| "provider": "current", | ||
| "timeout": 20, | ||
| }, |
| def test_ai_routing_can_force_multi_agent_review(config, monkeypatch): | ||
| """AI routing should be able to override a single-agent planner candidate.""" | ||
| _mock_profile(monkeypatch, categories=["systems-tooling"]) | ||
| config.auto_collaboration["ai_routing"] = { | ||
| "enabled": True, | ||
| "provider": "current", | ||
| "timeout": 3, | ||
| } | ||
|
|
||
| def fake_run(*_args, **_kwargs): | ||
| return SimpleNamespace( | ||
| returncode=0, | ||
| stdout=( | ||
| '{"execution_mode":"multi-agent","intent":"documentation",' | ||
| '"trigger":"docs-writing","primary_agent":"codex",' | ||
| '"reviewer_agents":["claude"],"reason":"User asked for independent review."}' | ||
| ), | ||
| stderr="", | ||
| ) | ||
|
|
||
| monkeypatch.setattr("ai_collab.core.detector.subprocess.run", fake_run) | ||
|
|
||
| detector = CollaborationDetector(config) | ||
| result = detector.detect("扫描目录并写 md,最后让 Claude 独立审查", "codex") | ||
|
|
||
| assert result.need_collaboration is True | ||
| assert result.execution_mode == "multi-agent" | ||
| assert result.routing_decision_source == "ai" | ||
| assert result.primary == "codex" | ||
| assert result.reviewers == ["claude"] | ||
| assert {"codex", "claude"}.issubset(set(result.selected_agents)) | ||
| assert any(step["role"] == "quality-review" for step in result.orchestration_plan) | ||
|
|
| timeout = self._ai_route_timeout(ai_cfg) | ||
| try: | ||
| parts = shlex.split(provider.cli) | ||
| except ValueError: | ||
| parts = provider.cli.strip().split() | ||
| if not parts: | ||
| return None | ||
|
|
||
| command = resolve_subprocess_command(parts) + [prompt] | ||
| try: | ||
| completed = subprocess.run( | ||
| command, | ||
| capture_output=True, | ||
| text=True, | ||
| timeout=timeout, | ||
| check=False, | ||
| ) |
Summary by CodeRabbit
Release Notes
detectcommand now displays routing metadata, including routing decision source and optional reasoning.