Skip to content

Commit f8347b9

Browse files
nshkrdotcomnshkrdotcom
authored andcommitted
add model selection to claude code
1 parent 8727126 commit f8347b9

22 files changed

+494
-27
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ Application.put_env(:pipeline, :test_mode, true)
163163

164164
### 🤖 AI Integration
165165
- 🤖 **Multi-AI Integration**: Chain Claude and Gemini APIs together
166+
- 💰 **Model Selection & Cost Control**: Choose between Claude models (sonnet ~$0.01 vs opus ~$0.26 per query)
166167
- 🔄 **Flexible Execution Modes**: Mock, Live, and Mixed modes for testing
167168
- 📋 **YAML Workflow Configuration**: Define complex multi-step workflows
168169
- 🎯 **Structured Output**: JSON-based responses with proper error handling
@@ -171,6 +172,7 @@ Application.put_env(:pipeline, :test_mode, true)
171172

172173
### ⚡ Advanced Features
173174
- **Enhanced Claude Steps**: Smart presets, sessions, extraction, batch processing, robust error handling
175+
- **Model Selection**: Automatic cost optimization (development=sonnet, production=opus+fallback, analysis=opus)
174176
- **Genesis Pipeline**: Self-improving AI system that generates other pipelines
175177
- **Session Management**: Persistent conversations with automatic checkpointing
176178
- **Fault Tolerance**: Retry mechanisms, circuit breakers, graceful degradation

docs/20250704_yaml_format_v2/01_complete_schema_reference.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ defaults:
8080
# Model configuration
8181
gemini_model: string # Default Gemini model
8282
claude_preset: enum # Default Claude preset
83+
claude_model: string # Default Claude model ("sonnet", "opus", specific version)
84+
claude_fallback_model: string # Default Claude fallback model
8385

8486
# Token configuration
8587
gemini_token_budget:

docs/20250704_yaml_format_v2/02_step_types_reference.md

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ Pipeline supports 17+ distinct step types organized into four categories:
103103
output_format: "json" # Response format
104104
verbose: true # Detailed logging
105105
106+
# Model selection
107+
model: "sonnet" # Model choice: "sonnet", "opus", or specific version
108+
fallback_model: "sonnet" # Fallback when primary model overloaded
109+
106110
# Tool permissions
107111
allowed_tools: ["Write", "Edit", "Read", "Bash", "Search"]
108112
disallowed_tools: ["Delete"] # Explicitly forbidden
@@ -151,6 +155,8 @@ Pipeline supports 17+ distinct step types organized into four categories:
151155
- Session management for continuity
152156
- Comprehensive error handling
153157
- Cost tracking and telemetry
158+
- Model selection for cost optimization (25x savings: sonnet vs opus)
159+
- Fallback model support for reliability
154160

155161
### Claude Smart
156162

@@ -177,16 +183,63 @@ Pipeline supports 17+ distinct step types organized into four categories:
177183
```
178184

179185
**Available Presets**:
180-
- `development`: Permissive settings, full tool access, verbose logging
181-
- `production`: Restricted tools, optimized for safety and performance
182-
- `analysis`: Read-only tools, optimized for code analysis
186+
- `development`: Permissive settings, full tool access, verbose logging (uses sonnet - cost-effective)
187+
- `production`: Restricted tools, optimized for safety and performance (uses opus with sonnet fallback)
188+
- `analysis`: Read-only tools, optimized for code analysis (uses opus - best capability)
183189
- `chat`: Simple conversation mode, basic tools
184190

185191
**Key Features**:
186192
- Automatic configuration based on environment
187193
- Preset-specific optimizations
188194
- Simplified configuration
189195
- Intelligent defaults
196+
- Built-in model selection for cost optimization
197+
198+
## Model Selection & Cost Control
199+
200+
All Claude step types support model selection for cost optimization and performance tuning:
201+
202+
### Model Options
203+
204+
```yaml
205+
claude_options:
206+
# Simple shortcuts (recommended)
207+
model: "sonnet" # Fast, cost-effective (~$0.01 per query)
208+
model: "opus" # Highest quality (~$0.26 per query, 25x more expensive)
209+
210+
# Specific model versions (for reproducibility)
211+
model: "claude-3-5-sonnet-20241022"
212+
model: "claude-3-opus-20240229"
213+
214+
# Production reliability with fallback
215+
model: "opus"
216+
fallback_model: "sonnet" # Falls back when opus overloaded
217+
```
218+
219+
### Cost Optimization Examples
220+
221+
```yaml
222+
# Development workflow - cost-effective
223+
- name: "dev_task"
224+
type: "claude_smart"
225+
preset: "development" # Automatically uses sonnet
226+
227+
# Production workflow - quality + reliability
228+
- name: "prod_task"
229+
type: "claude_smart"
230+
preset: "production" # Uses opus with sonnet fallback
231+
232+
# Manual cost control
233+
- name: "simple_task"
234+
type: "claude"
235+
claude_options:
236+
model: "sonnet" # 25x cheaper for simple tasks
237+
238+
- name: "complex_analysis"
239+
type: "claude"
240+
claude_options:
241+
model: "opus" # Worth the cost for complex work
242+
```
190243

191244
### Claude Session
192245

docs/20250704_yaml_format_v2/06_advanced_features.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,8 @@ Maintain conversation state:
726726
description: "Developing authentication feature"
727727
728728
claude_options:
729+
model: "opus" # High-quality for complex sessions
730+
fallback_model: "sonnet" # Fallback for reliability
729731
max_turns: 20
730732
allowed_tools: ["Write", "Edit", "Read", "Bash"]
731733
@@ -895,6 +897,7 @@ Execute operations concurrently:
895897

896898
task_template:
897899
claude_options:
900+
model: "sonnet" # Cost-effective for batch processing
898901
max_turns: 5
899902
allowed_tools: ["Read"]
900903
prompt:

docs/20250704_yaml_format_v2/08_best_practices_patterns.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,66 @@ workflow:
432432
433433
## Performance Optimization
434434
435+
### Model Selection for Cost Optimization
436+
437+
Choose appropriate models for different task complexities:
438+
439+
```yaml
440+
# GOOD: Cost-optimized workflow
441+
workflow:
442+
name: "smart_code_review"
443+
444+
steps:
445+
# Simple tasks - use cost-effective model
446+
- name: "syntax_check"
447+
type: "claude"
448+
claude_options:
449+
model: "sonnet" # ~$0.01 per query
450+
max_turns: 1
451+
prompt:
452+
- type: "static"
453+
content: "Check for basic syntax errors"
454+
455+
# Complex analysis - use high-quality model
456+
- name: "security_audit"
457+
type: "claude"
458+
claude_options:
459+
model: "opus" # ~$0.26 per query (25x more expensive)
460+
fallback_model: "sonnet" # Fallback when overloaded
461+
max_turns: 5
462+
prompt:
463+
- type: "static"
464+
content: "Perform comprehensive security analysis"
465+
466+
# Use smart presets for automatic selection
467+
- name: "development_task"
468+
type: "claude_smart"
469+
preset: "development" # Automatically uses sonnet
470+
471+
- name: "production_task"
472+
type: "claude_smart"
473+
preset: "production" # Uses opus + sonnet fallback
474+
```
475+
476+
### Model Selection Best Practices
477+
478+
1. **Development workflows**: Use `sonnet` for cost-effective iteration
479+
2. **Production workflows**: Use `opus` with `sonnet` fallback for reliability
480+
3. **Analysis tasks**: Use `opus` for best capability
481+
4. **Simple tasks**: Always use `sonnet` to minimize costs
482+
5. **Batch processing**: Consider cost per query when processing large datasets
483+
484+
```yaml
485+
# Cost comparison example
486+
defaults:
487+
# Development environment - optimize for cost
488+
claude_model: "sonnet" # $0.01/query × 100 queries = $1.00
489+
490+
# Production environment - optimize for quality + reliability
491+
claude_model: "opus" # $0.26/query × 100 queries = $26.00
492+
claude_fallback_model: "sonnet"
493+
```
494+
435495
### Lazy Loading Strategy
436496

437497
Load resources only when needed:

docs/20250704_yaml_format_v2/09_migration_guide.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,22 @@ This guide helps you migrate existing Pipeline YAML v1 configurations to the v2
4242
type: "claude_robust" # Enterprise error handling
4343
```
4444
45-
3. **Advanced Control Flow**
45+
3. **Model Selection & Cost Control**
46+
```yaml
47+
claude_options:
48+
model: "sonnet" # Cost-effective (~$0.01/query)
49+
model: "opus" # High-quality (~$0.26/query)
50+
fallback_model: "sonnet" # Reliability fallback
51+
```
52+
53+
4. **Advanced Control Flow**
4654
```yaml
4755
type: "for_loop" # Iteration
4856
type: "while_loop" # Conditional loops
4957
type: "switch" # Multi-branch logic
5058
```
5159
52-
4. **Data Operations**
60+
5. **Data Operations**
5361
```yaml
5462
type: "data_transform" # JSONPath transformations
5563
type: "file_ops" # File manipulation

docs/20250704_yaml_format_v2/10_quick_reference.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ workflow:
1818
# Defaults for all steps
1919
defaults:
2020
gemini_model: "gemini-2.5-flash"
21+
claude_model: "sonnet" # Model selection: sonnet|opus|specific_version
22+
claude_fallback_model: "sonnet" # Fallback for reliability
2123
timeout_seconds: 300
2224

2325
# Step definitions
@@ -315,6 +317,33 @@ output_schema:
315317
maximum: 100
316318
```
317319
320+
## Model Selection & Cost Control
321+
322+
```yaml
323+
# Cost-effective development (sonnet ~$0.01/query)
324+
- type: "claude"
325+
claude_options:
326+
model: "sonnet"
327+
328+
# High-quality production (opus ~$0.26/query, 25x more expensive)
329+
- type: "claude"
330+
claude_options:
331+
model: "opus"
332+
fallback_model: "sonnet" # Fallback for reliability
333+
334+
# Smart presets with automatic model selection
335+
- type: "claude_smart"
336+
preset: "development" # Uses sonnet (cost-effective)
337+
preset: "production" # Uses opus + sonnet fallback
338+
preset: "analysis" # Uses opus (best capability)
339+
340+
# Specific model versions for reproducibility
341+
- type: "claude"
342+
claude_options:
343+
model: "claude-3-5-sonnet-20241022"
344+
fallback_model: "claude-3-opus-20240229"
345+
```
346+
318347
## Environment Modes
319348
320349
```yaml

examples/model_selection_demo.yaml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
workflow:
2+
name: "model_selection_demo"
3+
description: "Demonstrate Claude model selection for cost optimization"
4+
version: "2.0"
5+
6+
defaults:
7+
claude_preset: "development"
8+
output_dir: "./outputs/model_selection_demo"
9+
10+
steps:
11+
# Example 1: Cost-effective development workflow
12+
- name: "simple_code_review"
13+
type: "claude_smart"
14+
preset: "development" # Uses sonnet automatically (cost-effective)
15+
16+
prompt:
17+
- type: "static"
18+
content: |
19+
Review this simple function for basic issues:
20+
21+
```python
22+
def add_numbers(a, b):
23+
return a + b
24+
```
25+
26+
Just check for basic syntax and style issues.
27+
28+
output_to_file: "simple_review.json"
29+
30+
# Example 2: High-quality analysis workflow
31+
- name: "complex_architecture_analysis"
32+
type: "claude_smart"
33+
preset: "analysis" # Uses opus automatically (best capability)
34+
35+
prompt:
36+
- type: "static"
37+
content: |
38+
Analyze this complex microservices architecture for:
39+
- Security vulnerabilities
40+
- Performance bottlenecks
41+
- Scalability issues
42+
- Design pattern violations
43+
- Technical debt
44+
45+
Provide detailed recommendations with specific implementation steps.
46+
47+
output_to_file: "architecture_analysis.json"
48+
49+
# Example 3: Production workflow with fallback
50+
- name: "production_deployment"
51+
type: "claude_smart"
52+
preset: "production" # Uses opus with sonnet fallback
53+
54+
prompt:
55+
- type: "static"
56+
content: |
57+
Generate a production deployment checklist for a critical banking application.
58+
Include security checks, rollback procedures, and monitoring setup.
59+
60+
output_to_file: "deployment_checklist.json"
61+
62+
# Example 4: Manual model selection - cost optimization
63+
- name: "batch_documentation"
64+
type: "claude"
65+
66+
claude_options:
67+
model: "sonnet" # Explicit cost-effective choice
68+
max_turns: 3
69+
allowed_tools: ["Read", "Write"]
70+
71+
prompt:
72+
- type: "static"
73+
content: |
74+
Generate basic documentation for these functions.
75+
Keep it simple and concise.
76+
77+
output_to_file: "basic_docs.md"
78+
79+
# Example 5: Manual model selection - high quality
80+
- name: "critical_security_audit"
81+
type: "claude"
82+
83+
claude_options:
84+
model: "opus" # Explicit high-quality choice
85+
fallback_model: "sonnet" # Fallback for reliability
86+
max_turns: 10
87+
allowed_tools: ["Read", "Glob", "Grep"]
88+
89+
prompt:
90+
- type: "static"
91+
content: |
92+
Perform a comprehensive security audit of the entire codebase.
93+
Look for:
94+
- SQL injection vulnerabilities
95+
- XSS attack vectors
96+
- Authentication bypass issues
97+
- Data exposure risks
98+
- Cryptographic weaknesses
99+
100+
Provide detailed findings with remediation steps.
101+
102+
output_to_file: "security_audit.json"
103+
104+
# Example 6: Cost comparison demonstration
105+
- name: "cost_comparison_summary"
106+
type: "gemini"
107+
model: "gemini-2.5-flash"
108+
109+
prompt:
110+
- type: "static"
111+
content: |
112+
Summarize the cost implications of this pipeline:
113+
114+
- simple_code_review: Used sonnet (~$0.01)
115+
- complex_architecture_analysis: Used opus (~$0.26)
116+
- production_deployment: Used opus with fallback (~$0.26)
117+
- batch_documentation: Used sonnet (~$0.01)
118+
- critical_security_audit: Used opus (~$0.26)
119+
120+
Total estimated cost: ~$0.80
121+
Cost if everything used opus: ~$1.30 (63% more expensive)
122+
Cost if everything used sonnet: ~$0.05 (94% cheaper, but lower quality for complex tasks)
123+
124+
Explain the cost optimization strategy.
125+
126+
output_to_file: "cost_analysis.json"

0 commit comments

Comments
 (0)