Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pytest Report #37

Merged
merged 22 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7bd94f7
chore: Added pytest-xdist, pytest-repeat, and allure-pytest dependencies
naaive Aug 12, 2024
041827f
chore: Add test cases for next_role function using pytest
naaive Aug 12, 2024
fd3354d
chore: Refactor asset management tests to use pytest
naaive Aug 12, 2024
54da784
chore: Refactor block_explore test setup and add pytest fixtures
naaive Aug 12, 2024
4929a91
chore: Refactor test functions for feed exploration
naaive Aug 12, 2024
f286678
chore: Refactor test cases for market analysis agent
naaive Aug 12, 2024
0bdc6d0
chores: Change the current model settings
naaive Aug 12, 2024
c2484a3
feat: run unit test concurrently
naaive Aug 12, 2024
f6f6859
chore: Update README to simplify test and report generation
naaive Aug 12, 2024
3faabcd
chore: Add model option for test execution
naaive Aug 12, 2024
b7e8d57
chore: Add detailed log
naaive Aug 12, 2024
b64a730
chore: change asset provider from COVALENT to MORALIS
naaive Aug 19, 2024
4b4dae0
chore: lint
naaive Aug 19, 2024
a297221
chore: update test docs
naaive Aug 19, 2024
4001393
fix: asset_management.py test
naaive Aug 19, 2024
0be6fef
chore: remove useless package
naaive Aug 19, 2024
2fbaf1a
chore: remove useless conf
naaive Aug 19, 2024
c7a4f47
chore: replace nft rank from nftscan to moralis
naaive Aug 21, 2024
cfd3df1
chore: lint
naaive Aug 21, 2024
1ee0bb0
chore: prompt improvement
naaive Aug 21, 2024
3c73f3b
chore: prompt optimization to pass 'pytest --count=2 -n 32 agent_traj…
naaive Aug 21, 2024
5ffbc19
chore: Update widget height to 400
naaive Aug 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ GOOGLE_GEMINI_API_KEY=
OLLAMA_HOST=http://ollama:11434

# Optional API keys for additional features
# Sign up for NFTScan API key at: https://developer.nftscan.com/
NFTSCAN_API_KEY=
# Get your Tavily API key at: https://www.tavily.com/
TAVILY_API_KEY=
# Get your Covalent API key at: https://www.covalenthq.com/platform/auth/register/
COVALENT_API_KEY=
# Get your Moralis API key at: https://moralis.io/
MORALIS_API_KEY=
# Register for a RootData API key at: https://www.rootdata.com/
ROOTDATA_API_KEY=
# Sign up for a CoinGecko API key at: https://www.coingecko.com/en/api/pricing
Expand All @@ -32,3 +30,8 @@ CHAINLIT_AUTH_SECRET=
OAUTH_AUTH0_CLIENT_ID=
OAUTH_AUTH0_CLIENT_SECRET=
OAUTH_AUTH0_DOMAIN=

#run unit test concurrently
#run unit test with repeat count
#simplify test and report generation
#Change the current model settings
52 changes: 27 additions & 25 deletions openagent/agents/asset_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,37 @@

from openagent.agents.agent_factory import create_agent
from openagent.conf.env import settings
from openagent.conf.llm_provider import get_current_llm
from openagent.executors.nft_balance_executor import NFTBalanceExecutor
from openagent.executors.swap_executor import SwapExecutor
from openagent.executors.token_balance_executor import TokenBalanceExecutor
from openagent.executors.transfer_executor import TransferExecutor

load_dotenv()

executors = [SwapExecutor(), TransferExecutor()]
if settings.COVALENT_API_KEY:
executors.extend([TokenBalanceExecutor(), NFTBalanceExecutor()])

asset_management_agent = create_agent(
get_current_llm(),
executors,
"""
You are AssetManager, an AI assistant for crypto asset management. Your responsibilities include:

1. Query and report on users' token balances
2. Check and inform about users' NFT holdings
3. Handle user requests to swap or transfer tokens

When interacting with users:
- Provide accurate and detailed information
- Maintain a friendly and enthusiastic tone
- Use occasional puns or jokes to keep the conversation engaging
- Include relevant emojis to enhance your messages
- For privacy reasons, do not include address information when generating widgets

Prioritize clarity and efficiency in your responses while keeping the interaction enjoyable for the user.
""".strip(),
)

def build_asset_management_agent(llm):
executors = [SwapExecutor(), TransferExecutor()]
if settings.MORALIS_API_KEY:
executors.extend([TokenBalanceExecutor(), NFTBalanceExecutor()])

asset_management_agent = create_agent(
llm,
executors,
"""
You are AssetManager, an AI assistant for crypto asset management. Your responsibilities include:

1. Query and report on users' token balances
2. Check and inform about users' NFT holdings
3. Handle user requests to swap or transfer tokens

When interacting with users:
- Provide accurate and detailed information
- Maintain a friendly and enthusiastic tone
- Use occasional puns or jokes to keep the conversation engaging
- Include relevant emojis to enhance your messages
- For privacy reasons, do not include address information when generating widgets

Prioritize clarity and efficiency in your responses while keeping the interaction enjoyable for the user.
""".strip(),
)
return asset_management_agent
26 changes: 14 additions & 12 deletions openagent/agents/block_explore.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from dotenv import load_dotenv

from openagent.agents.agent_factory import create_agent
from openagent.conf.llm_provider import get_current_llm
from openagent.executors.block_stat_executor import BlockStatExecutor
from openagent.executors.search_executor import search_executor

Expand All @@ -10,15 +9,18 @@
executors = [BlockStatExecutor(), search_executor]


block_explorer_agent = create_agent(
get_current_llm(),
executors,
"""
You are BlockExplorer, dedicated to exploring and presenting detailed blockchain information.
Help users query transaction details, block data, gas fees, block height, and other blockchain-related information.
Use the available tools to gather and display accurate blockchain data.
def build_block_explorer_agent(llm):
block_explorer_agent = create_agent(
llm,
executors,
"""
You are BlockExplorer, dedicated to exploring and presenting detailed blockchain information.
Help users query transaction details, block data, gas fees, block height, and other blockchain-related information.
Use the available tools to gather and display accurate blockchain data.

Your answer should be detailed and include puns or jokes where possible \
And keep a lively, enthusiastic, and energetic tone, maybe include some emojis.
""".strip(),
)
Your answer should be detailed and include puns or jokes where possible \
And keep a lively, enthusiastic, and energetic tone, maybe include some emojis.
""".strip(),
)

return block_explorer_agent
96 changes: 49 additions & 47 deletions openagent/agents/fallback.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,54 @@
from langchain_core.language_models import BaseChatModel
from langchain_core.messages import HumanMessage
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from loguru import logger

from openagent.conf.llm_provider import get_current_llm


def fallback(state):
logger.info("Running fallback agent")

chat_template = ChatPromptTemplate.from_messages(
[
(
"system",
"""
You are the OpenAgent created by RSS3.

Your role:
1. Handle general queries and conversations that don't fall under the expertise of other specialized agents.
2. Clarify unclear requests and provide versatile assistance.
3. Maintain conversation continuity and guide users to appropriate specialists when necessary.

Your communication style:
- Be friendly, approachable, and enthusiastic in your responses.
- Use a mix of professional knowledge and casual charm.
- Include relevant puns, jokes, or word plays to keep the conversation lively.
- Sprinkle in emojis occasionally to add personality to your messages.
- Provide detailed answers, but keep them concise and easy to understand.

Remember:
- If a query seems more suitable for a specialized agent (Market Analyst, Asset Manager,
Block Explorer, or Research Analyst), suggest redirecting the user while still providing a helpful general response.
- Always aim to add value, even if the query is outside your primary expertise.
- When in doubt, ask for clarification to ensure you're addressing the user's needs accurately.

Let's make every interaction informative, fun, and memorable! 🚀✨
""".strip(),
),
*state["messages"][0:-1],
("human", "{input}"),
]
)
chain = chat_template | get_current_llm() | StrOutputParser()
return {
"messages": [
HumanMessage(
content=chain.invoke({"input": state["messages"][-1].content}),
name="fallback",
)
]
}

def build_fallback_agent(llm: BaseChatModel):
def fallback(state):
logger.info("Running fallback agent")

chat_template = ChatPromptTemplate.from_messages(
[
(
"system",
"""
You are the OpenAgent created by RSS3.

Your role:
1. Handle general queries and conversations that don't fall under the expertise of other specialized agents.
2. Clarify unclear requests and provide versatile assistance.
3. Maintain conversation continuity and guide users to appropriate specialists when necessary.

Your communication style:
- Be friendly, approachable, and enthusiastic in your responses.
- Use a mix of professional knowledge and casual charm.
- Include relevant puns, jokes, or word plays to keep the conversation lively.
- Sprinkle in emojis occasionally to add personality to your messages.
- Provide detailed answers, but keep them concise and easy to understand.

Remember:
- If a query seems more suitable for a specialized agent (Market Analyst, Asset Manager,
Block Explorer, or Research Analyst), suggest redirecting the user while still providing a helpful general response.
- Always aim to add value, even if the query is outside your primary expertise.
- When in doubt, ask for clarification to ensure you're addressing the user's needs accurately.

Let's make every interaction informative, fun, and memorable! 🚀✨
""".strip(),
),
*state["messages"][0:-1],
("human", "{input}"),
]
)
chain = chat_template | llm | StrOutputParser()
return {
"messages": [
HumanMessage(
content=chain.invoke({"input": state["messages"][-1].content}),
name="fallback",
)
]
}

return fallback
37 changes: 20 additions & 17 deletions openagent/agents/feed_explore.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
from dotenv import load_dotenv
from langchain_core.language_models import BaseChatModel

from openagent.agents.agent_factory import create_agent
from openagent.conf.llm_provider import get_current_llm
from openagent.executors.defi_executor import DeFiExecutor
from openagent.executors.feed_executor import FeedExecutor
from openagent.executors.feed_source_executor import FeedSourceExecutor

load_dotenv()

feed_explorer_agent = create_agent(
get_current_llm(),
[FeedExecutor(), FeedSourceExecutor(), DeFiExecutor()],
"""
You are FeedExplorer, dedicated to exploring and presenting blockchain-related
activities and feeds.
Help users query various feeds, retrieve activities from different sources, and provide
insights on DeFi activities.

Leverage the FeedExecutor to provide insights on various feeds, the FeedSourceExecutor
to retrieve activities based on different sources, and the DeFiExecutor to give detailed
information on DeFi activities.
def build_feed_explorer_agent(llm: BaseChatModel):
feed_explorer_agent = create_agent(
llm,
[FeedExecutor(), FeedSourceExecutor(), DeFiExecutor()],
"""
You are FeedExplorer, dedicated to exploring and presenting blockchain-related
activities and feeds.
Help users query various feeds, retrieve activities from different sources, and provide
insights on DeFi activities.

Use the available tools to gather and display accurate feed and activity data.
Leverage the FeedExecutor to provide insights on various feeds, the FeedSourceExecutor
to retrieve activities based on different sources, and the DeFiExecutor to give detailed
information on DeFi activities.

Your answer should be detailed and include puns or jokes where possible \
And keep a lively, enthusiastic, and energetic tone, maybe include some emojis.
""".strip(),
)
Use the available tools to gather and display accurate feed and activity data.

Your answer should be detailed and include puns or jokes where possible \
And keep a lively, enthusiastic, and energetic tone, maybe include some emojis.
""".strip(),
)
return feed_explorer_agent
34 changes: 17 additions & 17 deletions openagent/agents/market_analysis.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
from dotenv import load_dotenv
from langchain_core.language_models import BaseChatModel

from openagent.agents.agent_factory import create_agent
from openagent.conf.env import settings
from openagent.conf.llm_provider import get_current_llm
from openagent.executors.coin_market_executor import CoinMarketExecutor
from openagent.executors.funding_rate_executor import FundingRateExecutor
from openagent.executors.nft_rank_executor import NFTRankingExecutor
from openagent.executors.nft_search_executor import NFTSearchExecutor
from openagent.executors.price_executor import PriceExecutor
from openagent.executors.search_executor import search_executor

load_dotenv()

executors = [FundingRateExecutor(), search_executor]
if settings.COINGECKO_API_KEY:
executors.extend([PriceExecutor(), CoinMarketExecutor()])
if settings.NFTSCAN_API_KEY:
executors.extend([NFTSearchExecutor(), NFTRankingExecutor()])

market_analysis_agent = create_agent(
get_current_llm(),
executors,
"""
You are MarketAnalyst, responsible for providing market data analysis.
Help users understand market dynamics and trends by retrieving real-time price information of tokens.
def build_market_analysis_agent(llm: BaseChatModel):
executors = [FundingRateExecutor(), search_executor]
if settings.COINGECKO_API_KEY:
executors.extend([PriceExecutor(), CoinMarketExecutor()])
if settings.MORALIS_API_KEY:
executors.extend([NFTRankingExecutor()])
return create_agent(
llm,
executors,
"""
You are MarketAnalyst, responsible for providing market data analysis.
Help users understand market dynamics and trends by retrieving real-time price information of tokens.

Your answer should be detailed and include puns or jokes where possible \
And keep a lively, enthusiastic, and energetic tone, maybe include some emojis.
""".strip(),
)
Your answer should be detailed and include puns or jokes where possible \
And keep a lively, enthusiastic, and energetic tone, maybe include some emojis.
""".strip(),
)
26 changes: 0 additions & 26 deletions openagent/agents/project_management.py

This file was deleted.

29 changes: 29 additions & 0 deletions openagent/agents/research_analyst.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from dotenv import load_dotenv
from langchain_core.language_models import BaseChatModel

from openagent.agents.agent_factory import create_agent
from openagent.conf.env import settings
from openagent.executors.project_executor import ProjectExecutor
from openagent.executors.search_executor import search_executor

load_dotenv()


def build_research_analyst_agent(llm: BaseChatModel):
executors = [search_executor]
if settings.ROOTDATA_API_KEY:
executors.append(ProjectExecutor())

research_analyst_agent = create_agent(
llm,
executors,
"""
You are ResearchAnalyst, responsible for assisting users in conducting research and analysis related to web3 projects.
Provide accurate and detailed information about project progress, team members, market trends, investors,
and other relevant data to support investment decisions.

Your answer should be detailed and include puns or jokes where possible \
And keep a lively, enthusiastic, and energetic tone, maybe include some emojis.
""".strip(),
)
return research_analyst_agent
Loading
Loading