Skip to content

Commit 3bce893

Browse files
committed
chore: removes cleanup unused tool function, remove additionalProperties
1 parent 542c135 commit 3bce893

2 files changed

Lines changed: 0 additions & 175 deletions

File tree

packages/optimization/src/ldai_optimizer/util.py

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from typing import Any, Awaitable, Dict, List, Optional, Tuple, TypeVar, Union
99

1010
from ldai_optimizer._slug_words import _ADJECTIVES, _NOUNS
11-
from ldai_optimizer.dataclasses import ToolDefinition
1211

1312
logger = logging.getLogger(__name__)
1413

@@ -51,47 +50,6 @@ def generate_slug() -> str:
5150
return f"{random.choice(_ADJECTIVES)}-{random.choice(_NOUNS)}"
5251

5352

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-
9553
def interpolate_variables(text: str, variables: Dict[str, Any]) -> str:
9654
"""
9755
Interpolate ``{{variable}}`` placeholders in text using the provided variables.
@@ -211,98 +169,6 @@ async def await_if_needed(result: Union[_T, Awaitable[_T]]) -> _T:
211169
return result # type: ignore[return-value]
212170

213171

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-
306172
def validate_variation_response(response_data: Dict[str, Any]) -> List[str]:
307173
"""Validate the shape of a parsed LLM variation response.
308174

packages/optimization/tests/test_client.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
)
3434
from ldai_optimizer.util import interpolate_variables
3535
from ldai_optimizer.util import (
36-
handle_evaluation_tool_call,
37-
handle_variation_tool_call,
3836
restore_variable_placeholders,
3937
)
4038

@@ -119,45 +117,6 @@ def _make_client(ldai: MagicMock | None = None) -> OptimizationClient:
119117
# ---------------------------------------------------------------------------
120118

121119

122-
class TestHandleEvaluationToolCall:
123-
def test_returns_json_with_score_and_rationale(self):
124-
result = handle_evaluation_tool_call(score=0.8, rationale="Good answer.")
125-
data = json.loads(result)
126-
assert data["score"] == 0.8
127-
assert data["rationale"] == "Good answer."
128-
129-
def test_score_zero_is_valid(self):
130-
result = handle_evaluation_tool_call(score=0.0, rationale="No match.")
131-
assert json.loads(result)["score"] == 0.0
132-
133-
def test_result_is_valid_json_string(self):
134-
result = handle_evaluation_tool_call(score=0.5, rationale="Partial.")
135-
assert isinstance(result, str)
136-
json.loads(result) # must not raise
137-
138-
139-
class TestHandleVariationToolCall:
140-
def test_returns_json_with_all_fields(self):
141-
result = handle_variation_tool_call(
142-
current_instructions="Do X.",
143-
current_parameters={"temperature": 0.7},
144-
model="gpt-4o",
145-
)
146-
data = json.loads(result)
147-
assert data["current_instructions"] == "Do X."
148-
assert data["current_parameters"] == {"temperature": 0.7}
149-
assert data["model"] == "gpt-4o"
150-
151-
def test_result_is_valid_json_string(self):
152-
result = handle_variation_tool_call(
153-
current_instructions="Do Y.",
154-
current_parameters={},
155-
model="gpt-4o-mini",
156-
)
157-
assert isinstance(result, str)
158-
json.loads(result)
159-
160-
161120
# ---------------------------------------------------------------------------
162121
# _find_model_config
163122
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)