Skip to content

Enhance Tools Template with Conditional Tool Selection #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [0.1.10] - 2025-03-12

### Added
- Enhanced tools_template functionality: Variables set with `.with_var()` are now accessible in tools_template for conditional tool selection
- Added example showcasing conditional tools selection based on variables
- Added comprehensive tests for conditional tools feature

## [0.1.9] - 2025-03-03

## Changed
Expand All @@ -12,19 +19,19 @@
- Updated PyProject.toml and Added MANIFEST.in
- Making the Promptix Studio fully functional.

## [0.1.7] - 2024-05-18
## [0.1.7] - 2025-03-02

### Changed
- Updated code with latest improvements
- Fixed minor issues from previous release

## [0.1.6] - 2024-05-17
## [0.1.6] - 2025-03-02

### Added
- Improved Promptix Studio with enhanced user interface and functionality
- Updated License with additional clarifications

## [0.1.5] - 2024-05-15
## [0.1.5] - 2025-02-27

### Added
- Improved documentation for builder patterns
Expand All @@ -35,7 +42,7 @@
- Refined API interface for better developer experience
- Optimized template rendering for better performance

## [0.1.4] - 2024-02-02
## [0.1.4] - 2025-02-02

### Added
- Builder pattern support for creating model configurations
Expand All @@ -49,7 +56,7 @@
- Improved documentation with builder pattern examples
- Added type hints and validation for builder methods

## [0.1.3] - 2024-01-26
## [0.1.3] - 2025-02-26

### Added
- OpenAI integration support with prepare_model_config functionality
Expand All @@ -61,7 +68,7 @@
- Improved error handling for invalid memory formats
- Updated documentation with OpenAI integration examples

## [0.1.2] - 2024-03-19
## [0.1.2] - 2025-02-19

### Added
- New DungeonMaster template for RPG scenario generation
Expand All @@ -74,7 +81,7 @@
- Improved test coverage for complex scenarios
- Updated template validation for optional fields

## [0.1.1] - 2024-01-20
## [0.1.1] - 2025-01-20

### Added
- Enhanced schema validation with warning system for missing fields
Expand All @@ -92,7 +99,7 @@
- Fixed handling of custom_data and nested fields
- Fixed test environment cleanup and prompts.json handling

## [0.1.0] - 2024-01-19
## [0.1.0] - 2025-01-19

### Added
- Initial release of Promptix Library
Expand Down
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,36 @@ system_instruction = (
)
```

### 🔧 Conditional Tool Selection
Variables set using `.with_var()` are available in tools_template allowing for dynamic tool selection based on variables:

```python
# Conditionally select tools based on variables
config = (
Promptix.builder("ComplexCodeReviewer")
.with_var({
'programming_language': 'Python', # This affects which tools are selected
'severity': 'high',
'review_focus': 'security'
})
.build()
)

# Explicitly added tools will override template selections
config = (
Promptix.builder("ComplexCodeReviewer")
.with_var({
'programming_language': 'Java',
'severity': 'medium'
})
.with_tool("complexity_analyzer") # This tool will be included regardless of template logic
.with_tool_parameter("complexity_analyzer", "thresholds", {"cyclomatic": 10})
.build()
)
```

This allows you to create sophisticated tools configurations that adapt based on input variables, with the ability to override the template logic when needed.

## 🚀 Getting Started

### Installation
Expand Down
43 changes: 43 additions & 0 deletions examples/03_builder_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,48 @@ def main():
)
print_config(config4)

# Example 6: Using with_var for multiple variables at once
print("Example 6: Using with_var Method")
config5 = (
Promptix.builder("ComplexCodeReviewer")
.with_var({
'programming_language': 'Python',
'severity': 'high',
'review_focus': 'security and performance'
})
.build()
)
print_config(config5)

# Example 7: Using with_var for multiple variables which dicpates tools structure
print("Example 7: Using with_var Method")
config6 = (
Promptix.builder("ComplexCodeReviewer")
.with_var({
'programming_language': 'Java',
'severity': 'high',
'review_focus': 'security and performance'
})
.with_tool_parameter("complexity_analyzer", "thresholds", {"cyclomatic": 8, "cognitive": 5})
.build()

)
print_config(config6)

# Example 8: Using with_var for multiple variables which dicpates tools structure
print("Example 8: Using with_var Method")
config7 = (
Promptix.builder("ComplexCodeReviewer")
.with_var({
'programming_language': 'Java',
'severity': 'high',
'review_focus': 'security and performance'
})
.build()

)
print_config(config7)


if __name__ == "__main__":
main()
92 changes: 92 additions & 0 deletions examples/06_conditional_tools_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env python3
"""
Example demonstrating how to use variables with tools_template in Promptix.

This example shows how variables set with .with_var() can be used in tools_template
for conditional tool selection based on variable values.
"""

import sys
import os
import json

# Add the src directory to the path so we can import promptix
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

from src.promptix import Promptix

def print_config(config):
"""Print a configuration in a readable format."""
if isinstance(config, dict):
print(json.dumps(config, indent=2))
else:
print(config)
print()

def main():
"""Run the examples."""
# Example 1: Using variables to conditionally select tools via tools_template
print("Example 1: Conditional Tools with Python")
print("(Tools template automatically selects complexity_analyzer and security_scanner for Python)")
config1 = (
Promptix.builder("ComplexCodeReviewer")
.with_var({
'programming_language': 'Python', # This will activate Python tools
'severity': 'high',
'review_focus': 'security and performance'
})
.build()
)
print_config(config1)

# Example 2: Using different variables to select different tools
print("Example 2: Conditional Tools with Java")
print("(Tools template automatically selects style_checker for Java)")
config2 = (
Promptix.builder("ComplexCodeReviewer")
.with_var({
'programming_language': 'Java', # This will activate Java tools
'severity': 'medium',
'review_focus': 'security'
})
.build()
)
print_config(config2)

# Example 3: Overriding tools_template with explicit tool selection
print("Example 3: Overriding tools_template with explicit tool selection")
print("(Explicitly adding tools that wouldn't be selected by the template)")
config3 = (
Promptix.builder("ComplexCodeReviewer")
.with_var({
'programming_language': 'JavaScript', # No tools defined for JavaScript in template
'severity': 'low',
'review_focus': 'performance'
})
.with_tool("complexity_analyzer") # Explicitly adding tools
.with_tool("security_scanner")
.with_tool_parameter("complexity_analyzer", "thresholds", {"cyclomatic": 8, "cognitive": 5})
.build()
)
print_config(config3)

# Example 4: Combining template-selected and explicitly-selected tools
print("Example 4: Combining template and explicit tool selection")
print("(Template selects style_checker for Java, and we explicitly add complexity_analyzer)")
config4 = (
Promptix.builder("ComplexCodeReviewer")
.with_var({
'programming_language': 'Java', # Template selects style_checker for Java
'severity': 'high',
'review_focus': 'security and performance'
})
.with_extra({
'temperature': 0.9
})
.with_tool("complexity_analyzer") # Explicitly add another tool
.build()
)
print_config(config4)

if __name__ == "__main__":
main()
Loading