From d8a0aa6357095ab60d9af0aa482ce2bfd2ae754d Mon Sep 17 00:00:00 2001 From: pseudoyu Date: Tue, 14 Jan 2025 11:47:00 +0800 Subject: [PATCH] feat: add feed agent and dsl tool (#44) --- openagent/agents/__init__.py | 3 ++- openagent/agents/feed.py | 8 +++++++ openagent/tools/__init__.py | 3 ++- openagent/tools/dsl.py | 42 ++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 openagent/agents/feed.py create mode 100644 openagent/tools/dsl.py diff --git a/openagent/agents/__init__.py b/openagent/agents/__init__.py index 7027a645..5e86a3f3 100644 --- a/openagent/agents/__init__.py +++ b/openagent/agents/__init__.py @@ -8,6 +8,7 @@ from phi.model.google import Gemini from .finance import finance_agent +from .feed import feed_agent class UnsupportedModel(Exception): @@ -41,7 +42,7 @@ def build_model(model: str) -> Model: def build_agent_team(model: str) -> Agent: return Agent( - team=[finance_agent], + team=[finance_agent, feed_agent], model=build_model(model), ) diff --git a/openagent/agents/feed.py b/openagent/agents/feed.py new file mode 100644 index 00000000..eeb8f7fb --- /dev/null +++ b/openagent/agents/feed.py @@ -0,0 +1,8 @@ +from phi.agent import Agent + +from openagent.tools import DSLTools + +feed_agent = Agent( + name="Feed Agent", + tools=[DSLTools()], +) diff --git a/openagent/tools/__init__.py b/openagent/tools/__init__.py index 0ba00606..13ec0fe7 100644 --- a/openagent/tools/__init__.py +++ b/openagent/tools/__init__.py @@ -1,3 +1,4 @@ from .coingecko import CoinGeckoTools +from .dsl import DSLTools -__all__ = [CoinGeckoTools] +__all__ = [CoinGeckoTools, DSLTools] diff --git a/openagent/tools/dsl.py b/openagent/tools/dsl.py new file mode 100644 index 00000000..b32479a1 --- /dev/null +++ b/openagent/tools/dsl.py @@ -0,0 +1,42 @@ +import requests +from phi.tools import Toolkit + + +class DSLTools(Toolkit): + base_url = "https://gi.rss3.io" + + def __init__(self): + super().__init__(name="dsl_tools") + + self.register(self.fetch_decentralized_feed) + + def fetch_decentralized_feed(self, address: str, type: str = "all") -> str: + """ + Fetch feed activities for a given address and activity type. + + Args: + address (str): The wallet address or blockchain domain name to fetch activities for + type (str): The type of activities to fetch (all, post, comment, share) + Returns: + A string containing the fetched activities formatted using FEED_PROMPT + """ + url = f"{self.base_url}/decentralized/{address}?limit=5&action_limit=10&tag=social" + if type in ["post", "comment", "share"]: + url += f"&type={type}" + + headers = {"Accept": "application/json"} + data = requests.get(url, headers=headers).json() + + result = FEED_PROMPT.format(activities_data=data) + return result + + +FEED_PROMPT = """ +Here are the raw activities: + +{activities_data} + +- Before answering, please first summarize how many actions the above activities have been carried out. +- Display the key information in each operation, such as time, author, specific content, etc., and display this information in a markdown list format. +- Finally, give a specific answer to the question. +"""