Skip to content

Commit bd822f6

Browse files
fix tool extraction function according to #60 (comment)
1 parent 376a425 commit bd822f6

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

mellea/backends/litellm.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def _generate_from_chat_context_standard(
244244
thinking = "medium"
245245

246246
# Append tool call information if applicable.
247-
tools = self._extract_tools(action, format, model_opts, tool_calls)
247+
tools = self._extract_tools(action, format, model_opts, tool_calls, ctx)
248248
formatted_tools = convert_tools_to_json(tools) if len(tools) > 0 else None
249249

250250
model_specific_options = self._make_backend_specific_and_remove(model_opts)
@@ -294,16 +294,23 @@ def _generate_from_chat_context_standard(
294294
return parsed_result
295295

296296
@staticmethod
297-
def _extract_tools(action, format, model_opts, tool_calls) -> dict[str, Callable]:
297+
def _extract_tools(
298+
action, format, model_opts, tool_calls, ctx
299+
) -> dict[str, Callable]:
298300
tools: dict[str, Callable] = dict()
299301
if tool_calls:
300302
if format:
301303
FancyLogger.get_logger().warning(
302304
f"Tool calling typically uses constrained generation, but you have specified a `format` in your generate call. NB: tool calling is superseded by format; we will NOT call tools for your request: {action}"
303305
)
304306
else:
305-
add_tools_from_context_actions(tools, [action])
306307
add_tools_from_model_options(tools, model_opts)
308+
add_tools_from_context_actions(tools, ctx.actions_for_available_tools())
309+
310+
# Add the tools from the action for this generation last so that
311+
# they overwrite conflicting names.
312+
add_tools_from_context_actions(tools, [action])
313+
FancyLogger.get_logger().info(f"Tools for call: {tools.keys()}")
307314
return tools
308315

309316
def _generate_from_raw(

0 commit comments

Comments
 (0)