You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
context: Repository context (summary + tree + content)
122
+
catalog_text: Formatted catalog of available tools
123
+
user_prompt: Optional user guidance
124
+
api_key: Optional OpenAI API key
125
+
126
+
Returns:
127
+
Raw LLM response string
128
+
"""
129
+
# Get API key
130
+
ifnotapi_key:
131
+
api_key=os.getenv("OPENAI_API_KEY")
132
+
ifnotapi_key:
133
+
raiseValueError("OPENAI_API_KEY not found")
134
+
135
+
# System prompt
136
+
system_prompt="""You are "Tool Recommender for Codebases." Your job is to read a repository context and choose a minimal set of helpful tools (rules, agents, MCPs) from the provided catalog.
137
+
138
+
Hard requirements:
139
+
- Output strictly valid JSON. No markdown, no commentary.
140
+
- Use only the slugs present in the catalog below.
141
+
- Prefer minimal selections: 0–2 per category (maximum 3).
142
+
- If unsure, return empty arrays.
143
+
144
+
Selection guidelines:
145
+
- Pick items that improve correctness, safety, or developer workflow for this codebase.
146
+
- Avoid redundant overlap (e.g., don't pick both a ruleset and all its child rules).
- Base the decision solely on the given repository context and the catalog.
149
+
150
+
Catalog (one line per item, slug first):
151
+
"""+catalog_text+"""
152
+
153
+
Return JSON with this exact shape:
154
+
- rules: array of slugs
155
+
- agents: array of slugs
156
+
- mcps: array of slugs
157
+
- rationales (optional): object whose keys are "rules:<slug>", "agents:<slug>", "mcps:<slug>" and whose values are short one-line reasons.
158
+
159
+
You will now receive the repository context (summary, tree, truncated content) and an optional user focus. Choose minimal helpful tools from the catalog and return JSON only."""
160
+
161
+
# User message
162
+
user_message="Here is the codebase context (truncated). Choose minimal useful tools from the catalog above.\n\n"
163
+
user_message+=context
164
+
ifuser_prompt:
165
+
user_message+=f"\n\nUser focus: {user_prompt}"
166
+
167
+
# Prepare request
168
+
messages= [
169
+
{"role": "system", "content": system_prompt},
170
+
{"role": "user", "content": user_message}
171
+
]
172
+
173
+
url="https://api.openai.com/v1/chat/completions"
174
+
headers= {
175
+
"Authorization": f"Bearer {api_key}",
176
+
"Content-Type": "application/json"
177
+
}
178
+
179
+
data= {
180
+
"model": "gpt-4o-mini",
181
+
"messages": messages,
182
+
"temperature": 0.2, # Low temperature for consistency
0 commit comments