mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-20 02:18:13 +00:00
Initial agno agent implementation
This commit is contained in:
1 parent
27279cb635
commit
8fbf9cec5c
4 files changed
+56
-16
No files matched your search
+1
-1
@@ -139,7 +139,7 @@ pylint.html
|
|||||||
# Serena-specific
|
# Serena-specific
|
||||||
/*.yml
|
/*.yml
|
||||||
!myproject.demo.yml
|
!myproject.demo.yml
|
||||||
|
/agent-ui
|
||||||
|
|
||||||
# Cache is in .multilspy
|
# Cache is in .multilspy
|
||||||
**/.multilspy/**
|
**/.multilspy/**
|
||||||
+8
-13
@@ -1,17 +1,12 @@
|
|||||||
from agno.agent import Agent
|
|
||||||
from agno.models.google import Gemini
|
from agno.models.google import Gemini
|
||||||
from agno.playground import Playground, serve_playground_app
|
from agno.playground import Playground, serve_playground_app
|
||||||
|
|
||||||
serena_agent = Agent(
|
from serena.agno import create_agno_agent
|
||||||
model=Gemini(id="gemini-2.5-pro-exp-03-25"),
|
|
||||||
description="Serena",
|
|
||||||
tools=[], # Add serena tools here
|
|
||||||
show_tool_calls=True,
|
|
||||||
markdown=True,
|
|
||||||
system_message="", # use PromptFactory
|
|
||||||
)
|
|
||||||
|
|
||||||
app = Playground(agents=[serena_agent]).get_app()
|
if __name__ == "__main__":
|
||||||
|
serena_agent = create_agno_agent(
|
||||||
if __name__ == "main":
|
project_file_path="myproject.yml",
|
||||||
serve_playground_app("playground:app", reload=True)
|
model=Gemini(id="gemini-2.5-pro-exp-03-25"),
|
||||||
|
)
|
||||||
|
app = Playground(agents=[serena_agent]).get_app()
|
||||||
|
serve_playground_app(app, reload=False)
|
||||||
+15
-2
@@ -10,7 +10,7 @@ import sys
|
|||||||
import traceback
|
import traceback
|
||||||
from abc import ABC
|
from abc import ABC
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from collections.abc import Iterator, Sequence
|
from collections.abc import Callable, Iterator, Sequence
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from logging import Logger
|
from logging import Logger
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -146,6 +146,19 @@ class Tool(Component):
|
|||||||
name = "".join(["_" + c.lower() if c.isupper() else c for c in name]).lstrip("_")
|
name = "".join(["_" + c.lower() if c.isupper() else c for c in name]).lstrip("_")
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
def get_apply_fn(self) -> Callable:
|
||||||
|
apply_fn = getattr(self, "apply")
|
||||||
|
if apply_fn is None:
|
||||||
|
raise Exception(f"{self} does not define method apply")
|
||||||
|
return apply_fn
|
||||||
|
|
||||||
|
def get_description(self) -> str:
|
||||||
|
apply_fn = self.get_apply_fn()
|
||||||
|
docstring = apply_fn.__doc__
|
||||||
|
if docstring is None:
|
||||||
|
raise Exception(f"Missing docstring for {self}")
|
||||||
|
return docstring
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _log_tool_application(frame: Any) -> None:
|
def _log_tool_application(frame: Any) -> None:
|
||||||
params = {}
|
params = {}
|
||||||
@@ -168,7 +181,7 @@ class Tool(Component):
|
|||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def apply_ex(self, *args, log_call: bool = True, catch_exceptions: bool = True, **kwargs) -> str:
|
def apply_ex(self, *args, log_call: bool = True, catch_exceptions: bool = True, **kwargs) -> str: # type: ignore
|
||||||
"""
|
"""
|
||||||
Applies the tool with the given arguments
|
Applies the tool with the given arguments
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
from agno.agent import Agent
|
||||||
|
from agno.models.base import Model
|
||||||
|
from agno.tools import Function
|
||||||
|
|
||||||
|
from serena.agent import SerenaAgent
|
||||||
|
|
||||||
|
|
||||||
|
def create_agno_agent(
|
||||||
|
project_file_path: str, model: Model, system_prompt: str = "", markdown: bool = True, show_tool_calls: bool = True
|
||||||
|
) -> Agent:
|
||||||
|
serena_agent = SerenaAgent(project_file_path)
|
||||||
|
tools: list[Function] = []
|
||||||
|
for tool in serena_agent.tools.values():
|
||||||
|
|
||||||
|
def entrypoint(*args, tool=tool, **kwargs): # type: ignore
|
||||||
|
tool.apply_ex(*args, log_call=True, catch_exceptions=True, **kwargs)
|
||||||
|
|
||||||
|
function = Function.from_callable(tool.get_apply_fn())
|
||||||
|
function.name = tool.get_name()
|
||||||
|
function.entrypoint = entrypoint
|
||||||
|
tools.append(function)
|
||||||
|
|
||||||
|
agno_agent = Agent(
|
||||||
|
model=model,
|
||||||
|
description="Serena",
|
||||||
|
tools=tools, # type: ignore
|
||||||
|
show_tool_calls=show_tool_calls,
|
||||||
|
markdown=markdown,
|
||||||
|
system_message=system_prompt,
|
||||||
|
)
|
||||||
|
|
||||||
|
return agno_agent
|
||||||
Reference in new issue
Block a user