model-orchestration.mdx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. ---
  2. title: "Model Orchestration"
  3. description: "Use multiple AI models strategically: optimize costs, reduce bias, and leverage model-specific strengths in your workflows"
  4. ---
  5. Cline CLI's `--config` and `--thinking` flags enable sophisticated multi-model workflows. Instead of using a single model for all tasks, you can route different work to different models based on cost, capability, and specialization.
  6. ## Why Orchestrate Multiple Models?
  7. **Cost Optimization**
  8. By routing work to the right model for the job, you can dramatically reduce API costs. Fast, inexpensive models like Haiku and Gemini Flash handle simple tasks such as summarization, while expensive models like Opus and O1 are reserved for complex reasoning and planning. This approach can reduce costs by 10-100x on routine operations.
  9. **Bias Reduction**
  10. Different models catch different issues, so cross-validating solutions with multiple AI perspectives helps reduce blind spots that come from relying on a single model. In code reviews especially, combining viewpoints surfaces problems that any one model might miss.
  11. **Specialization**
  12. Certain models excel in specific domains: Codex and DeepSeek are strong at code generation, while GPT-4 and Claude shine at documentation and prose. Security analysis in particular benefits from combining multiple model viewpoints, since each brings different training data and heuristics to the table.
  13. ## Pattern 1: CI/CD Code Review
  14. See our production GitHub Actions workflow that uses Cline CLI for automated PR reviews: [cline-pr-review.yml](https://github.com/cline/cline/blob/main/.github/workflows/cline-pr-review.yml)
  15. **Key capabilities demonstrated:**
  16. - **Automated inline suggestions**: Creates GitHub suggestion blocks that authors can commit with one click
  17. - **SME identification**: Analyzes git history to find subject matter experts for each file
  18. - **Related issue discovery**: Searches for context from past issues and PRs
  19. - **Security-first permissions**: Read-only codebase access, can only post reviews
  20. - **Deep code analysis**: Understands intent, compares approaches, identifies edge cases
  21. The workflow runs on every PR and provides maintainers with comprehensive context to make faster, more informed decisions.
  22. ## Pattern 2: Task Phase Optimization
  23. Use different models for different phases of work. Route simple tasks to cheap models, complex reasoning to premium models.
  24. ### Example: Issue Analysis Pipeline
  25. ```bash
  26. # Get latest issue content
  27. ISSUE_CONTENT=$(gh issue view $(gh issue list -L 1 | awk '{print $1}'))
  28. # Phase 1: Quick summary with cheap model
  29. SUMMARY=$(echo "$ISSUE_CONTENT" | cline -y --config ~/.cline-haiku \
  30. "summarize this issue in 2-3 sentences")
  31. # Phase 2: Detailed plan with expensive model + thinking
  32. PLAN=$(echo "$SUMMARY" | cline -y --thinking --config ~/.cline-opus \
  33. "create detailed implementation plan with edge cases")
  34. # Phase 3: Execute with mid-tier model
  35. echo "$PLAN" | cline -y --config ~/.cline-sonnet \
  36. "implement the plan from above"
  37. ```
  38. <Note>
  39. Each cline invocation needs to complete before passing output to the next phase. Use shell variables to store intermediate results rather than piping cline commands directly.
  40. </Note>
  41. **Cost impact:**
  42. - Haiku: $0.80 per million input tokens
  43. - Opus: $15 per million input tokens
  44. - Sonnet: $3 per million input tokens
  45. This pattern uses Opus only when needed for complex reasoning, saving ~10x on API costs compared to using Opus for everything.
  46. ### Setting Up Model Configs
  47. Create separate configuration directories for each model:
  48. ```bash
  49. # Create config directories
  50. mkdir -p ~/.cline-haiku ~/.cline-sonnet ~/.cline-opus
  51. # Configure each with different models
  52. cline --config ~/.cline-haiku auth anthropic --modelid claude-haiku-4-20250514
  53. cline --config ~/.cline-sonnet auth anthropic --modelid claude-sonnet-4-20250514
  54. cline --config ~/.cline-opus auth anthropic --modelid claude-opus-4-5-20251101
  55. # Or use different providers entirely
  56. cline --config ~/.cline-gemini auth gemini --modelid gemini-2.0-flash-exp
  57. cline --config ~/.cline-codex auth openai-codex --modelid gpt-5-latest
  58. ```
  59. Now you can switch models per-task with `--config`:
  60. ```bash
  61. cline --config ~/.cline-haiku "quick task"
  62. cline --config ~/.cline-opus "complex reasoning task"
  63. ```
  64. ## Pattern 3: Multi-Model Review & Consensus
  65. Get multiple AI perspectives on the same change, then synthesize their feedback.
  66. ### Example: Diff Review Pipeline
  67. ```bash
  68. # Get the latest commit
  69. DIFF=$(git show)
  70. # Review 1: Gemini's perspective
  71. echo "$DIFF" | cline -y --config ~/.cline-gemini \
  72. "review this diff and write your analysis to gemini-review.md"
  73. # Review 2: Codex's perspective
  74. echo "$DIFF" | cline -y --config ~/.cline-codex \
  75. "review this diff and write your analysis to codex-review.md"
  76. # Review 3: Opus's perspective
  77. echo "$DIFF" | cline -y --config ~/.cline-opus \
  78. "review this diff and write your analysis to opus-review.md"
  79. # Synthesize all reviews into a consensus
  80. cat gemini-review.md codex-review.md opus-review.md | cline -y \
  81. "summarize these 3 reviews and identify: 1) issues all models agree on, 2) issues only one model caught, 3) your final recommendation"
  82. ```
  83. **Why this works:**
  84. - **Redundancy**: Issues caught by all 3 models are high-confidence
  85. - **Coverage**: Each model has blind spots; together they cover more ground
  86. - **Prioritization**: Consensus issues should be fixed first
  87. - **Learning**: See which model types catch which issue types
  88. ### Advanced: Parallel Reviews
  89. Run reviews in parallel for faster feedback:
  90. ```bash
  91. # Run all reviews simultaneously
  92. git show | cline -y --config ~/.cline-gemini "review and save to gemini-review.md" &
  93. git show | cline -y --config ~/.cline-codex "review and save to codex-review.md" &
  94. git show | cline -y --config ~/.cline-opus "review and save to opus-review.md" &
  95. # Wait for all to complete
  96. wait
  97. # Synthesize
  98. cat *-review.md | cline -y "create consensus review"
  99. ```
  100. <Note>
  101. Parallel execution requires managing multiple Cline instances. See [Multi-instance workflows](/cline-cli/three-core-flows#3-multi-instance-run-parallel-agents) for details.
  102. </Note>
  103. ## Extended Thinking for Complex Tasks
  104. Use the `--thinking` flag when Cline needs to analyze multiple approaches:
  105. ```bash
  106. # Without thinking: Fast but may miss nuances
  107. cline -y "refactor this codebase"
  108. # With thinking: Slower but more thorough
  109. cline -y --thinking \
  110. "refactor this codebase - consider: performance, maintainability, backward compatibility"
  111. ```
  112. The `--thinking` flag allocates 1024 tokens for internal reasoning before Cline responds. Best for:
  113. - Architectural decisions
  114. - Security analysis
  115. - Complex refactoring
  116. - Multi-step planning
  117. ## Best Practices
  118. 1. **Profile your workload**: Track which tasks are simple vs. complex
  119. 2. **Match models to tasks**: Use fast models for summaries, powerful models for reasoning
  120. 3. **Automate switching**: Script model selection based on task type
  121. 4. **Monitor costs**: Different models have 10-100x price differences
  122. 5. **Validate important decisions**: Use multi-model consensus for critical changes
  123. ## Production Examples
  124. ### Cost-Optimized PR Review
  125. ```bash
  126. # Haiku: Quick summary and issue identification
  127. gh pr view $PR | cline -y --config ~/.cline-haiku \
  128. "list all issues to fix, output as JSON"
  129. # Opus with thinking: Deep analysis only if issues found
  130. if [ -s issues.json ]; then
  131. cline -y --thinking --config ~/.cline-opus \
  132. "analyze these issues and recommend fixes"
  133. fi
  134. ```
  135. ### Security-Focused Multi-Model Scan
  136. ```bash
  137. # Different models have different security perspectives
  138. git diff main | cline -y --config ~/.cline-gemini "security review" > gemini-sec.md &
  139. git diff main | cline -y --config ~/.cline-opus "security review" > opus-sec.md &
  140. git diff main | cline -y --config ~/.cline-codex "security review" > codex-sec.md &
  141. wait
  142. # High-priority: Issues all 3 models found
  143. cat *-sec.md | cline -y "find security issues all 3 reviews mentioned"
  144. ```
  145. ## Related Documentation
  146. <Columns cols={2}>
  147. <Card title="CLI Reference" icon="terminal" href="/cline-cli/cli-reference">
  148. Complete documentation for --config and --thinking flags
  149. </Card>
  150. <Card title="Headless Mode" icon="robot" href="/cline-cli/three-core-flows">
  151. Run Cline autonomously in scripts, CI/CD pipelines, and automated workflows.
  152. </Card>
  153. <Card title="Model Selection Guide" icon="brain" href="/core-features/model-selection-guide">
  154. Compare models and choose the right one for your needs
  155. </Card>
  156. <Card title="CI/CD Integration" icon="github" href="/cline-cli/samples/github-integration">
  157. Automate GitHub workflows with Cline CLI
  158. </Card>
  159. </Columns>