|
8 | 8 | from typing import Any, Awaitable, Dict, List, Optional, Tuple, TypeVar, Union |
9 | 9 |
|
10 | 10 | from ldai_optimizer._slug_words import _ADJECTIVES, _NOUNS |
11 | | -from ldai_optimizer.dataclasses import ToolDefinition |
12 | 11 |
|
13 | 12 | logger = logging.getLogger(__name__) |
14 | 13 |
|
@@ -51,47 +50,6 @@ def generate_slug() -> str: |
51 | 50 | return f"{random.choice(_ADJECTIVES)}-{random.choice(_NOUNS)}" |
52 | 51 |
|
53 | 52 |
|
54 | | -def handle_evaluation_tool_call(score: float, rationale: str) -> str: |
55 | | - """ |
56 | | - Process the return_evaluation tool call from the judge LLM. |
57 | | -
|
58 | | - Serialises the score and rationale to a JSON string. The caller |
59 | | - (handle_judge_call implementor) should return this string as the result of |
60 | | - the judge turn; the framework will then parse it via _parse_judge_response |
61 | | - to extract the score and rationale. |
62 | | -
|
63 | | - :param score: The evaluation score (0.0 to 1.0) |
64 | | - :param rationale: Explanation of the evaluation decision |
65 | | - :return: JSON string of the score and rationale |
66 | | - """ |
67 | | - return json.dumps({"score": score, "rationale": rationale}) |
68 | | - |
69 | | - |
70 | | -def handle_variation_tool_call( |
71 | | - current_instructions: str, |
72 | | - current_parameters: Dict[str, Any], |
73 | | - model: str, |
74 | | -) -> str: |
75 | | - """ |
76 | | - Process the return_improved_configuration tool call from the variation LLM. |
77 | | -
|
78 | | - Serialises the improved configuration to a JSON string. The caller |
79 | | - (handle_agent_call implementor) should return this string as the result of |
80 | | - the variation agent turn; the framework will then parse it via |
81 | | - extract_json_from_response and apply it in _apply_new_variation_response. |
82 | | -
|
83 | | - :param current_instructions: The improved agent instructions |
84 | | - :param current_parameters: The improved agent parameters (e.g. temperature, max_tokens) |
85 | | - :param model: The model to use for the improved agent |
86 | | - :return: JSON string of the improved configuration |
87 | | - """ |
88 | | - return json.dumps({ |
89 | | - "current_instructions": current_instructions, |
90 | | - "current_parameters": current_parameters, |
91 | | - "model": model, |
92 | | - }) |
93 | | - |
94 | | - |
95 | 53 | def interpolate_variables(text: str, variables: Dict[str, Any]) -> str: |
96 | 54 | """ |
97 | 55 | Interpolate ``{{variable}}`` placeholders in text using the provided variables. |
@@ -211,98 +169,6 @@ async def await_if_needed(result: Union[_T, Awaitable[_T]]) -> _T: |
211 | 169 | return result # type: ignore[return-value] |
212 | 170 |
|
213 | 171 |
|
214 | | -def create_evaluation_tool() -> ToolDefinition: |
215 | | - """ |
216 | | - Create the structured output tool for judge evaluations. |
217 | | -
|
218 | | - :return: A ToolDefinition for evaluation responses |
219 | | - """ |
220 | | - return ToolDefinition( |
221 | | - type="function", |
222 | | - name="return_evaluation", |
223 | | - description="Returns an evaluation with a score and rationale.", |
224 | | - input_schema={ |
225 | | - "type": "object", |
226 | | - "properties": { |
227 | | - "score": { |
228 | | - "type": "number", |
229 | | - "description": "The evaluation score (typically 0.0 to 1.0)", |
230 | | - }, |
231 | | - "rationale": { |
232 | | - "type": "string", |
233 | | - "description": "Explanation of the evaluation", |
234 | | - }, |
235 | | - }, |
236 | | - "required": ["score", "rationale"], |
237 | | - }, |
238 | | - ) |
239 | | - |
240 | | - |
241 | | -def create_boolean_tool() -> ToolDefinition: |
242 | | - """ |
243 | | - Create the structured output tool for acceptance judges. |
244 | | -
|
245 | | - :return: A ToolDefinition for boolean evaluation responses |
246 | | - """ |
247 | | - return ToolDefinition( |
248 | | - type="function", |
249 | | - name="return_boolean", |
250 | | - description="Returns a boolean value and reasoning for the evaluation.", |
251 | | - input_schema={ |
252 | | - "type": "object", |
253 | | - "properties": { |
254 | | - "passed": { |
255 | | - "type": "boolean", |
256 | | - "description": "Whether the response passes the evaluation criteria", |
257 | | - }, |
258 | | - "rationale": { |
259 | | - "type": "string", |
260 | | - "description": "Explanation of the evaluation decision", |
261 | | - }, |
262 | | - }, |
263 | | - "required": ["passed", "rationale"], |
264 | | - }, |
265 | | - ) |
266 | | - |
267 | | - |
268 | | -def create_variation_tool(model_choices: List[str]) -> ToolDefinition: |
269 | | - """ |
270 | | - Create the structured output tool for variation generation. |
271 | | -
|
272 | | - :param model_choices: List of model IDs the LLM may select from |
273 | | - :return: A ToolDefinition for variation generation responses |
274 | | - """ |
275 | | - return ToolDefinition( |
276 | | - type="function", |
277 | | - name="return_improved_configuration", |
278 | | - description=( |
279 | | - "Returns the improved agent configuration with updated instructions and parameters. " |
280 | | - "This tool enforces structured output to ensure the response can be parsed and validated." |
281 | | - ), |
282 | | - input_schema={ |
283 | | - "type": "object", |
284 | | - "properties": { |
285 | | - "current_instructions": { |
286 | | - "type": "string", |
287 | | - "description": "The improved agent instructions based on the evaluation feedback", |
288 | | - }, |
289 | | - "current_parameters": { |
290 | | - "type": "object", |
291 | | - "description": "The improved agent parameters (e.g., temperature, max_tokens, etc.)", |
292 | | - "additionalProperties": True, |
293 | | - }, |
294 | | - "model": { |
295 | | - "type": "string", |
296 | | - "description": "The model to use for the improved agent", |
297 | | - "enum": model_choices, |
298 | | - }, |
299 | | - }, |
300 | | - "required": ["current_instructions", "current_parameters", "model"], |
301 | | - "additionalProperties": False, |
302 | | - }, |
303 | | - ) |
304 | | - |
305 | | - |
306 | 172 | def validate_variation_response(response_data: Dict[str, Any]) -> List[str]: |
307 | 173 | """Validate the shape of a parsed LLM variation response. |
308 | 174 |
|
|
0 commit comments