Skip to content

Commit

Permalink
feat: add feed agent and dsl tool (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoyu authored Jan 14, 2025
1 parent 956128a commit d8a0aa6
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
3 changes: 2 additions & 1 deletion openagent/agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from phi.model.google import Gemini

from .finance import finance_agent
from .feed import feed_agent


class UnsupportedModel(Exception):
Expand Down Expand Up @@ -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),
)

Expand Down
8 changes: 8 additions & 0 deletions openagent/agents/feed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from phi.agent import Agent

from openagent.tools import DSLTools

feed_agent = Agent(
name="Feed Agent",
tools=[DSLTools()],
)
3 changes: 2 additions & 1 deletion openagent/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .coingecko import CoinGeckoTools
from .dsl import DSLTools

__all__ = [CoinGeckoTools]
__all__ = [CoinGeckoTools, DSLTools]
42 changes: 42 additions & 0 deletions openagent/tools/dsl.py
Original file line number Diff line number Diff line change
@@ -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.
"""

0 comments on commit d8a0aa6

Please sign in to comment.