From 131ca8a15e5f97e07fca0f99cfa607519d641957 Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Mon, 31 Mar 2025 13:51:39 +0200 Subject: [PATCH] Add SerenaAgnoToolkit (replacing list of Functions) --- scripts/agno_agent.py | 7 ++----- src/serena/agno.py | 27 +++++++++++++++------------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/scripts/agno_agent.py b/scripts/agno_agent.py index bd7f34a3..b5efd901 100644 --- a/scripts/agno_agent.py +++ b/scripts/agno_agent.py @@ -4,22 +4,19 @@ from agno.playground import Playground, serve_playground_app from dotenv import load_dotenv from serena.agent import SerenaAgent -from serena.agno import get_agno_functions +from serena.agno import SerenaAgnoToolkit load_dotenv() project_file_path = "../myproject.yml" - serena_agent = SerenaAgent(project_file_path) -tools = get_agno_functions(serena_agent) - model = Claude(id="claude-3-7-sonnet-20250219") agno_agent = Agent( name="Serena", model=model, description="A fully-featured coding assistant", - tools=tools, # type: ignore + tools=[SerenaAgnoToolkit(serena_agent)], # type: ignore show_tool_calls=True, markdown=True, system_message="", # Todo diff --git a/src/serena/agno.py b/src/serena/agno.py index 5017b075..bbbe1a1c 100644 --- a/src/serena/agno.py +++ b/src/serena/agno.py @@ -1,18 +1,21 @@ -from agno.tools import Function +from agno.tools import Function, Toolkit from serena.agent import SerenaAgent, Tool -def serena_tool_to_agno_function(tool: Tool) -> Function: - def entrypoint(tool=tool, **kwargs): # type: ignore - tool.apply_ex(log_call=True, catch_exceptions=True, **kwargs) +class SerenaAgnoToolkit(Toolkit): + def __init__(self, serena_agent: SerenaAgent): + super().__init__("Serena") + for tool in serena_agent.tools.values(): + self.functions[tool.get_name()] = self._create_agno_function(tool) - function = Function.from_callable(tool.get_apply_fn()) - function.name = tool.get_name() - function.entrypoint = entrypoint - function.show_result = True - return function + @staticmethod + def _create_agno_function(tool: Tool) -> Function: + def entrypoint(**kwargs): # type: ignore + tool.apply_ex(log_call=True, catch_exceptions=True, **kwargs) - -def get_agno_functions(serena_agent: SerenaAgent) -> list[Function]: - return [serena_tool_to_agno_function(tool) for tool in serena_agent.tools.values()] + function = Function.from_callable(tool.get_apply_fn()) + function.name = tool.get_name() + function.entrypoint = entrypoint + function.show_result = True + return function