tonko22 commited on
Commit
775ea0b
·
1 Parent(s): 3726684

Simplify all a bit

Browse files
agents/analysis_agent.py CHANGED
@@ -8,7 +8,7 @@ in a user-friendly way, showing lyrics with comments underneath them.
8
  from smolagents import CodeAgent, VisitWebpageTool
9
  from loguru import logger
10
 
11
- from config import AGENT_CONFIG, load_prompt_templates
12
  from tools.search_tools import ThrottledDuckDuckGoSearchTool
13
  from tools.analysis_tools import analyze_lyrics_tool
14
 
@@ -23,11 +23,10 @@ def create_analysis_agent(model):
23
  Returns:
24
  A configured CodeAgent for lyrics analysis
25
  """
26
- # Get configuration values
27
- config = AGENT_CONFIG['analysis_agent']
28
  prompt_templates = load_prompt_templates()
29
 
30
- # Create the throttled search tool
31
  throttled_search_tool = ThrottledDuckDuckGoSearchTool(
32
  min_delay=3.0,
33
  max_delay=7.0
@@ -47,8 +46,8 @@ def create_analysis_agent(model):
47
  name="lyrics_analysis_agent",
48
  description="Specialized agent for analyzing song lyrics and providing detailed commentary",
49
  additional_authorized_imports=["numpy", "bs4", "json", "re"],
50
- max_steps=config['max_steps'],
51
- verbosity_level=config['verbosity_level'],
52
  prompt_templates=prompt_templates
53
  )
54
 
 
8
  from smolagents import CodeAgent, VisitWebpageTool
9
  from loguru import logger
10
 
11
+ from config import load_prompt_templates
12
  from tools.search_tools import ThrottledDuckDuckGoSearchTool
13
  from tools.analysis_tools import analyze_lyrics_tool
14
 
 
23
  Returns:
24
  A configured CodeAgent for lyrics analysis
25
  """
26
+ # Load prompt templates
 
27
  prompt_templates = load_prompt_templates()
28
 
29
+ # Create the throttled search tool with hardcoded values
30
  throttled_search_tool = ThrottledDuckDuckGoSearchTool(
31
  min_delay=3.0,
32
  max_delay=7.0
 
46
  name="lyrics_analysis_agent",
47
  description="Specialized agent for analyzing song lyrics and providing detailed commentary",
48
  additional_authorized_imports=["numpy", "bs4", "json", "re"],
49
+ max_steps=5, # Hardcoded from config
50
+ verbosity_level=2, # Hardcoded from config
51
  prompt_templates=prompt_templates
52
  )
53
 
agents/manager_agent.py CHANGED
@@ -5,7 +5,7 @@ Manager agent for coordinating the lyrics search and analysis process.
5
  from smolagents import CodeAgent, FinalAnswerTool
6
  from loguru import logger
7
 
8
- from config import AGENT_CONFIG, load_prompt_templates
9
  from agents.web_agent import create_web_agent
10
  from agents.analysis_agent import create_analysis_agent
11
 
@@ -20,8 +20,7 @@ def create_manager_agent(model):
20
  Returns:
21
  A configured CodeAgent manager for coordinating other agents
22
  """
23
- # Get configuration values
24
- config = AGENT_CONFIG['manager_agent']
25
  prompt_templates = load_prompt_templates()
26
 
27
  # Create sub-agents
@@ -43,9 +42,9 @@ def create_manager_agent(model):
43
  description="Specialized agent for coordinating lyrics search and analysis",
44
  managed_agents=[web_agent, analysis_agent],
45
  additional_authorized_imports=["json", "re"],
46
- planning_interval=config['planning_interval'],
47
- verbosity_level=config['verbosity_level'],
48
- max_steps=config['max_steps'],
49
  prompt_templates=prompt_templates
50
  )
51
 
 
5
  from smolagents import CodeAgent, FinalAnswerTool
6
  from loguru import logger
7
 
8
+ from config import load_prompt_templates
9
  from agents.web_agent import create_web_agent
10
  from agents.analysis_agent import create_analysis_agent
11
 
 
20
  Returns:
21
  A configured CodeAgent manager for coordinating other agents
22
  """
23
+ # Load prompt templates
 
24
  prompt_templates = load_prompt_templates()
25
 
26
  # Create sub-agents
 
42
  description="Specialized agent for coordinating lyrics search and analysis",
43
  managed_agents=[web_agent, analysis_agent],
44
  additional_authorized_imports=["json", "re"],
45
+ planning_interval=3, # Hardcoded from config
46
+ verbosity_level=3, # Hardcoded from config
47
+ max_steps=30, # Hardcoded from config
48
  prompt_templates=prompt_templates
49
  )
50
 
agents/single_agent.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Web agent for finding and extracting song lyrics from online sources.
3
+ """
4
+
5
+ from loguru import logger
6
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, VisitWebpageTool, FinalAnswerTool
7
+
8
+ from config import load_prompt_templates
9
+ from tools.analysis_tools import analyze_lyrics_tool
10
+ from tools.search_tools import ThrottledDuckDuckGoSearchTool
11
+
12
+
13
+ def create_single_agent(model):
14
+ """
15
+ Create an agent specialized in web browsing and lyrics extraction.
16
+
17
+ Args:
18
+ model: The LLM model to use with this agent
19
+
20
+ Returns:
21
+ A configured CodeAgent for web searches
22
+ """
23
+ # Load prompt templates
24
+ prompt_templates = load_prompt_templates()
25
+
26
+ # Define agent parameters directly in the code instead of using config
27
+ # Example usage within the agent
28
+ agent = CodeAgent(
29
+ tools=[
30
+ FinalAnswerTool(),
31
+ DuckDuckGoSearchTool(),
32
+ VisitWebpageTool(),
33
+ analyze_lyrics_tool
34
+ ],
35
+ model=model,
36
+ additional_authorized_imports=['numpy', 'bs4'],
37
+ max_steps=22,
38
+ verbosity_level=1,
39
+ description="Specialized agent for finding and extracting song, specified by the user. Performs lyrics search and analysys using given tools. Provides detailed commentary using FinalAnswerTool meaning.",
40
+ )
41
+
42
+ logger.info("Web agent (lyrics search) created successfully")
43
+ return agent
agents/web_agent.py CHANGED
@@ -5,7 +5,7 @@ Web agent for finding and extracting song lyrics from online sources.
5
  from smolagents import CodeAgent, VisitWebpageTool
6
  from loguru import logger
7
 
8
- from config import AGENT_CONFIG, load_prompt_templates
9
  from tools.search_tools import ThrottledDuckDuckGoSearchTool
10
 
11
 
@@ -19,8 +19,7 @@ def create_web_agent(model):
19
  Returns:
20
  A configured CodeAgent for web searches
21
  """
22
- # Get configuration values
23
- config = AGENT_CONFIG['web_agent']
24
  prompt_templates = load_prompt_templates()
25
 
26
  # Create the throttled search tool
@@ -43,8 +42,8 @@ def create_web_agent(model):
43
  name="lyrics_search_agent",
44
  description="Specialized agent for finding and extracting complete song lyrics",
45
  additional_authorized_imports=["numpy", "bs4", "json", "re"],
46
- max_steps=config['max_steps'],
47
- verbosity_level=config['verbosity_level'],
48
  prompt_templates=prompt_templates
49
  )
50
 
 
5
  from smolagents import CodeAgent, VisitWebpageTool
6
  from loguru import logger
7
 
8
+ from config import load_prompt_templates
9
  from tools.search_tools import ThrottledDuckDuckGoSearchTool
10
 
11
 
 
19
  Returns:
20
  A configured CodeAgent for web searches
21
  """
22
+ # Load prompt templates
 
23
  prompt_templates = load_prompt_templates()
24
 
25
  # Create the throttled search tool
 
42
  name="lyrics_search_agent",
43
  description="Specialized agent for finding and extracting complete song lyrics",
44
  additional_authorized_imports=["numpy", "bs4", "json", "re"],
45
+ max_steps=10, # Hardcoded from config
46
+ verbosity_level=2, # Hardcoded from config
47
  prompt_templates=prompt_templates
48
  )
49
 
app.py CHANGED
@@ -5,13 +5,14 @@ Lyrics Analyzer Agent - Main Entry Point
5
  This module serves as the entry point for the Lyrics Analyzer application, which
6
  uses a system of specialized agents to search for and analyze song lyrics.
7
  """
8
-
9
  from loguru import logger
10
  from Gradio_UI import GradioUI
11
  from smolagents import LiteLLMModel
12
 
13
  from config import setup_logger, load_api_keys, get_model_id, get_gradio_config
14
  from agents.manager_agent import create_manager_agent
 
15
 
16
 
17
  def main():
@@ -31,14 +32,14 @@ def main():
31
  model = LiteLLMModel(model_id=model_id)
32
 
33
  # Create the manager agent which will create and manage the other agents
34
- manager_agent = create_manager_agent(model)
35
 
36
  # Start the Gradio UI server
37
  logger.info("Initializing Gradio UI and launching server")
38
 
39
  # Determine if we're in test mode (local) or production (HuggingFace)
40
  # HuggingFace environment has SPACE_ID environment variable
41
- import os
42
  is_test = os.environ.get('SPACE_ID') is None
43
  gradio_config = get_gradio_config(is_test)
44
 
@@ -55,7 +56,7 @@ def main():
55
  "server_port": gradio_config["server_port"]
56
  })
57
 
58
- GradioUI(manager_agent).launch(**launch_kwargs)
59
  logger.success("Server started successfully")
60
 
61
 
 
5
  This module serves as the entry point for the Lyrics Analyzer application, which
6
  uses a system of specialized agents to search for and analyze song lyrics.
7
  """
8
+ import os
9
  from loguru import logger
10
  from Gradio_UI import GradioUI
11
  from smolagents import LiteLLMModel
12
 
13
  from config import setup_logger, load_api_keys, get_model_id, get_gradio_config
14
  from agents.manager_agent import create_manager_agent
15
+ from agents.single_agent import create_single_agent
16
 
17
 
18
  def main():
 
32
  model = LiteLLMModel(model_id=model_id)
33
 
34
  # Create the manager agent which will create and manage the other agents
35
+ single_agent = create_single_agent(model)
36
 
37
  # Start the Gradio UI server
38
  logger.info("Initializing Gradio UI and launching server")
39
 
40
  # Determine if we're in test mode (local) or production (HuggingFace)
41
  # HuggingFace environment has SPACE_ID environment variable
42
+
43
  is_test = os.environ.get('SPACE_ID') is None
44
  gradio_config = get_gradio_config(is_test)
45
 
 
56
  "server_port": gradio_config["server_port"]
57
  })
58
 
59
+ GradioUI(single_agent).launch(**launch_kwargs)
60
  logger.success("Server started successfully")
61
 
62
 
config.py CHANGED
@@ -57,25 +57,6 @@ SEARCH_TOOL_CONFIG = {
57
  "max_delay": 7.0
58
  }
59
 
60
- # Agent configuration
61
- AGENT_CONFIG = {
62
- "web_agent": {
63
- "max_steps": 50,
64
- "verbosity_level": 2,
65
- "description": "Browses the web to find original full lyrics and scrape them. Excels at building effective search queries"
66
- },
67
- "analysis_agent": {
68
- "max_steps": 5,
69
- "verbosity_level": 2,
70
- "description": "You are a Song Analysis Expert with deep knowledge of music theory, lyrical interpretation, cultural contexts, and music history. Your role is to analyze song lyrics to uncover their deeper meaning, artistic significance, and historical context."
71
- },
72
- "manager_agent": {
73
- "max_steps": 30,
74
- "verbosity_level": 3,
75
- "planning_interval": 3,
76
- "description": "Manages the search process and coordinates the search and analysis of song lyrics. Summarizes the results in a user-friendly format."
77
- }
78
- }
79
 
80
  # Gradio UI configuration
81
  def get_gradio_config(is_test=True):
 
57
  "max_delay": 7.0
58
  }
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  # Gradio UI configuration
62
  def get_gradio_config(is_test=True):