1
+ # Tool-Use Repository Development Guidelines
2
+
3
+ ## Creating a New Script
4
+
5
+ To add a new script to the tool-use repository, you need to modify several files:
6
+
7
+ 1. Create a new script file in `src/tool_use/scripts/`:
8
+
9
+ Example: src/tool_use/scripts/my_script.py
10
+ from ..utils.ai_service import AIService
11
+ from ..config_manager import config_manager
12
+ def main(args):
13
+ config_values = config_manager.get_tool_config("script_name")
14
+ # Your script implementation
15
+ pass
16
+ if __name__ == "__main__":
17
+ try:
18
+ main()
19
+ except KeyboardInterrupt:
20
+ console.print("\n[yellow]Operation cancelled by user.[/yellow]")
21
+ sys.exit(0)
22
+ except Exception as e:
23
+ console.print(f"\n[red]An unexpected error occurred: {e}[/red]")
24
+ sys.exit(1)
25
+
26
+ 2. Add dependencies to `src/tool_use/scripts/_script_dependencies.py`:
27
+
28
+ SCRIPT_DEPENDENCIES = {
29
+ # ... existing dependencies ...
30
+ "my-script": ["required-package1", "required-package2"]
31
+ }
32
+
33
+ 3. Add configuration in `src/tool_use/utils/config_wizard.py`:
34
+ SCRIPT_INFO = {
35
+ # ... existing scripts ...
36
+ "my-script": {
37
+ "name": "My Script",
38
+ "description": "What your script does",
39
+ "config_keys": [
40
+ {
41
+ "key": "my_config_key",
42
+ "prompt": "Enter configuration value:",
43
+ "description": "What this config value does",
44
+ "required": True
45
+ }
46
+ ]
47
+ }
48
+ }
49
+
50
+ 4. Update `src/tool_use/cli.py`:
51
+ - Add to `all_scripts` dictionary
52
+ - Add to `script_modules` mapping
53
+
54
+ 5. Add script to `README.md`
55
+
56
+ ## Using AIService
57
+
58
+ The AIService utility (`src/tool_use/utils/ai_service.py`) provides a standardized way to interact with AI models. Example usage from prioritize.py:
59
+
60
+ from ..utils.ai_service import AIService
61
+ # Initialize the service
62
+ ai = AIService()
63
+ # Simple completion
64
+ response = ai.query("Your prompt here")
65
+
66
+
67
+ #Structured output
68
+
69
+ class Example(BaseModel):
70
+ example: str = Field(description="example")
71
+
72
+ class StructuredOutput(BaseModel):
73
+ """Example description for the structured output, keys can be any pydantic supported field"""
74
+ field1: str = Field(description="First field for the output")
75
+ field2: List[Example] = Field(description="List of examples")
76
+
77
+ # Structured outputs only supported by openai
78
+ ai_service = AIService(service_type="openai")
79
+ response = ai_service.query_structured(prompt, StructuredOutput, system_prompt)
80
+
81
+ field1, field2 = response
82
+
83
+ ## Script Best Practices
84
+
85
+ 1. Use config_manager for settings:
86
+
87
+ from ..config_manager import config_manager
88
+ config_values = config_manager.get_tool_config("script_name")
89
+
90
+ 2. Handle arguments properly:
91
+ def main(args):
92
+ print("Usage: tool-use my-script [args]")
93
+ return
94
+
95
+ 3. Provide clear error messages and user feedback
96
+
97
+ 4. Follow existing patterns for consistency:
98
+ - Use relative imports
99
+ - Handle dependencies through SCRIPT_DEPENDENCIES
100
+ - Provide configuration through config_wizard
101
+ - Document usage in script's docstring
102
+
103
+
104
+ # Error Handling
105
+ Make sure to handle errors gracefully and provide clear error messages to the user.
106
+
107
+
108
+ # Formatting
109
+ - Use Rich when possible to display print statements in a visually appealing way
110
+
111
+ ## Common Patterns
112
+
113
+ 1. AI Integration:
114
+ - Use AIService for AI interactions
115
+ - Structure prompts clearly
116
+ - Handle API errors gracefully
117
+
118
+ 2. Configuration:
119
+ - Use config_wizard for user settings
120
+ - Validate config values
121
+ - Provide clear configuration prompts
122
+
123
+ 3. CLI Integration:
124
+ - Follow existing argument patterns
125
+ - Provide help text
126
+ - Handle invalid inputs gracefully
0 commit comments