2025-11-04 05:17:27 +01:00
|
|
|
from dataclasses import dataclass
|
2025-11-04 08:09:12 +01:00
|
|
|
from typing import Dict, List, Set
|
|
|
|
|
|
2025-11-04 05:17:27 +01:00
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
|
class AgentRole:
|
|
|
|
|
name: str
|
|
|
|
|
description: str
|
|
|
|
|
system_prompt: str
|
|
|
|
|
allowed_tools: Set[str]
|
|
|
|
|
specialization_areas: List[str]
|
|
|
|
|
temperature: float = 0.7
|
|
|
|
|
max_tokens: int = 4096
|
|
|
|
|
|
2025-11-04 08:09:12 +01:00
|
|
|
|
2025-11-04 05:17:27 +01:00
|
|
|
AGENT_ROLES = {
|
2025-11-04 08:09:12 +01:00
|
|
|
"coding": AgentRole(
|
|
|
|
|
name="coding",
|
|
|
|
|
description="Specialized in writing, reviewing, and debugging code",
|
|
|
|
|
system_prompt="""You are a coding specialist AI assistant. Your primary responsibilities:
|
2025-11-04 05:17:27 +01:00
|
|
|
- Write clean, efficient, well-structured code
|
|
|
|
|
- Review code for bugs, security issues, and best practices
|
|
|
|
|
- Refactor and optimize existing code
|
|
|
|
|
- Implement features based on specifications
|
|
|
|
|
- Follow language-specific conventions and patterns
|
2025-11-04 08:09:12 +01:00
|
|
|
Focus on code quality, maintainability, and performance.""",
|
2025-11-04 05:17:27 +01:00
|
|
|
allowed_tools={
|
2025-11-04 08:09:12 +01:00
|
|
|
"read_file",
|
|
|
|
|
"write_file",
|
|
|
|
|
"list_directory",
|
|
|
|
|
"create_directory",
|
|
|
|
|
"change_directory",
|
|
|
|
|
"get_current_directory",
|
|
|
|
|
"python_exec",
|
|
|
|
|
"run_command",
|
|
|
|
|
"index_directory",
|
2025-11-04 05:17:27 +01:00
|
|
|
},
|
2025-11-04 08:09:12 +01:00
|
|
|
specialization_areas=[
|
|
|
|
|
"code_writing",
|
|
|
|
|
"code_review",
|
|
|
|
|
"debugging",
|
|
|
|
|
"refactoring",
|
|
|
|
|
],
|
|
|
|
|
temperature=0.3,
|
2025-11-04 05:17:27 +01:00
|
|
|
),
|
2025-11-04 08:09:12 +01:00
|
|
|
"research": AgentRole(
|
|
|
|
|
name="research",
|
|
|
|
|
description="Specialized in information gathering and analysis",
|
|
|
|
|
system_prompt="""You are a research specialist AI assistant. Your primary responsibilities:
|
2025-11-04 05:17:27 +01:00
|
|
|
- Search for and gather relevant information
|
|
|
|
|
- Analyze data and documentation
|
|
|
|
|
- Synthesize findings into clear summaries
|
|
|
|
|
- Verify facts and cross-reference sources
|
|
|
|
|
- Identify trends and patterns in information
|
2025-11-04 08:09:12 +01:00
|
|
|
Focus on accuracy, thoroughness, and clear communication of findings.""",
|
2025-11-04 05:17:27 +01:00
|
|
|
allowed_tools={
|
2025-11-04 08:09:12 +01:00
|
|
|
"read_file",
|
|
|
|
|
"list_directory",
|
|
|
|
|
"index_directory",
|
|
|
|
|
"http_fetch",
|
|
|
|
|
"web_search",
|
|
|
|
|
"web_search_news",
|
|
|
|
|
"db_query",
|
|
|
|
|
"db_get",
|
2025-11-04 05:17:27 +01:00
|
|
|
},
|
2025-11-04 08:09:12 +01:00
|
|
|
specialization_areas=[
|
|
|
|
|
"information_gathering",
|
|
|
|
|
"analysis",
|
|
|
|
|
"documentation",
|
|
|
|
|
"fact_checking",
|
|
|
|
|
],
|
|
|
|
|
temperature=0.5,
|
2025-11-04 05:17:27 +01:00
|
|
|
),
|
2025-11-04 08:09:12 +01:00
|
|
|
"data_analysis": AgentRole(
|
|
|
|
|
name="data_analysis",
|
|
|
|
|
description="Specialized in data processing and analysis",
|
|
|
|
|
system_prompt="""You are a data analysis specialist AI assistant. Your primary responsibilities:
|
2025-11-04 05:17:27 +01:00
|
|
|
- Process and analyze structured and unstructured data
|
|
|
|
|
- Perform statistical analysis and pattern recognition
|
|
|
|
|
- Query databases and extract insights
|
|
|
|
|
- Create data summaries and reports
|
|
|
|
|
- Identify anomalies and trends
|
2025-11-04 08:09:12 +01:00
|
|
|
Focus on accuracy, data integrity, and actionable insights.""",
|
2025-11-04 05:17:27 +01:00
|
|
|
allowed_tools={
|
2025-11-04 08:09:12 +01:00
|
|
|
"db_query",
|
|
|
|
|
"db_get",
|
|
|
|
|
"db_set",
|
|
|
|
|
"read_file",
|
|
|
|
|
"write_file",
|
|
|
|
|
"python_exec",
|
|
|
|
|
"run_command",
|
|
|
|
|
"list_directory",
|
2025-11-04 05:17:27 +01:00
|
|
|
},
|
2025-11-04 08:09:12 +01:00
|
|
|
specialization_areas=[
|
|
|
|
|
"data_processing",
|
|
|
|
|
"statistical_analysis",
|
|
|
|
|
"database_operations",
|
|
|
|
|
],
|
|
|
|
|
temperature=0.3,
|
2025-11-04 05:17:27 +01:00
|
|
|
),
|
2025-11-04 08:09:12 +01:00
|
|
|
"planning": AgentRole(
|
|
|
|
|
name="planning",
|
|
|
|
|
description="Specialized in task planning and coordination",
|
|
|
|
|
system_prompt="""You are a planning specialist AI assistant. Your primary responsibilities:
|
2025-11-04 05:17:27 +01:00
|
|
|
- Break down complex tasks into manageable steps
|
|
|
|
|
- Create execution plans and workflows
|
|
|
|
|
- Identify dependencies and prerequisites
|
|
|
|
|
- Estimate effort and resource requirements
|
|
|
|
|
- Coordinate between different components
|
2025-11-04 08:09:12 +01:00
|
|
|
Focus on logical organization, completeness, and feasibility.""",
|
2025-11-04 05:17:27 +01:00
|
|
|
allowed_tools={
|
2025-11-04 08:09:12 +01:00
|
|
|
"read_file",
|
|
|
|
|
"write_file",
|
|
|
|
|
"list_directory",
|
|
|
|
|
"index_directory",
|
|
|
|
|
"db_set",
|
|
|
|
|
"db_get",
|
2025-11-04 05:17:27 +01:00
|
|
|
},
|
2025-11-04 08:09:12 +01:00
|
|
|
specialization_areas=["task_decomposition", "workflow_design", "coordination"],
|
|
|
|
|
temperature=0.6,
|
2025-11-04 05:17:27 +01:00
|
|
|
),
|
2025-11-04 08:09:12 +01:00
|
|
|
"testing": AgentRole(
|
|
|
|
|
name="testing",
|
|
|
|
|
description="Specialized in testing and quality assurance",
|
|
|
|
|
system_prompt="""You are a testing specialist AI assistant. Your primary responsibilities:
|
2025-11-04 05:17:27 +01:00
|
|
|
- Design and execute test cases
|
|
|
|
|
- Identify edge cases and potential failures
|
|
|
|
|
- Verify functionality and correctness
|
|
|
|
|
- Test error handling and edge conditions
|
|
|
|
|
- Ensure code meets quality standards
|
2025-11-04 08:09:12 +01:00
|
|
|
Focus on thoroughness, coverage, and issue identification.""",
|
2025-11-04 05:17:27 +01:00
|
|
|
allowed_tools={
|
2025-11-04 08:09:12 +01:00
|
|
|
"read_file",
|
|
|
|
|
"write_file",
|
|
|
|
|
"python_exec",
|
|
|
|
|
"run_command",
|
|
|
|
|
"list_directory",
|
|
|
|
|
"db_query",
|
2025-11-04 05:17:27 +01:00
|
|
|
},
|
2025-11-04 08:09:12 +01:00
|
|
|
specialization_areas=["test_design", "quality_assurance", "validation"],
|
|
|
|
|
temperature=0.4,
|
2025-11-04 05:17:27 +01:00
|
|
|
),
|
2025-11-04 08:09:12 +01:00
|
|
|
"documentation": AgentRole(
|
|
|
|
|
name="documentation",
|
|
|
|
|
description="Specialized in creating and maintaining documentation",
|
|
|
|
|
system_prompt="""You are a documentation specialist AI assistant. Your primary responsibilities:
|
2025-11-04 05:17:27 +01:00
|
|
|
- Write clear, comprehensive documentation
|
|
|
|
|
- Create API references and user guides
|
|
|
|
|
- Document code with comments and docstrings
|
|
|
|
|
- Organize and structure information logically
|
|
|
|
|
- Ensure documentation is up-to-date and accurate
|
2025-11-04 08:09:12 +01:00
|
|
|
Focus on clarity, completeness, and user-friendliness.""",
|
2025-11-04 05:17:27 +01:00
|
|
|
allowed_tools={
|
2025-11-04 08:09:12 +01:00
|
|
|
"read_file",
|
|
|
|
|
"write_file",
|
|
|
|
|
"list_directory",
|
|
|
|
|
"index_directory",
|
|
|
|
|
"http_fetch",
|
|
|
|
|
"web_search",
|
2025-11-04 05:17:27 +01:00
|
|
|
},
|
2025-11-04 08:09:12 +01:00
|
|
|
specialization_areas=[
|
|
|
|
|
"technical_writing",
|
|
|
|
|
"documentation_organization",
|
|
|
|
|
"user_guides",
|
|
|
|
|
],
|
|
|
|
|
temperature=0.6,
|
2025-11-04 05:17:27 +01:00
|
|
|
),
|
2025-11-04 08:09:12 +01:00
|
|
|
"orchestrator": AgentRole(
|
|
|
|
|
name="orchestrator",
|
|
|
|
|
description="Coordinates multiple agents and manages overall execution",
|
|
|
|
|
system_prompt="""You are an orchestrator AI assistant. Your primary responsibilities:
|
2025-11-04 05:17:27 +01:00
|
|
|
- Coordinate multiple specialized agents
|
|
|
|
|
- Delegate tasks to appropriate agents
|
|
|
|
|
- Integrate results from different agents
|
|
|
|
|
- Manage overall workflow execution
|
|
|
|
|
- Ensure task completion and quality
|
2025-11-04 08:09:12 +01:00
|
|
|
Focus on effective delegation, integration, and overall success.""",
|
2025-11-04 05:17:27 +01:00
|
|
|
allowed_tools={
|
2025-11-04 08:09:12 +01:00
|
|
|
"read_file",
|
|
|
|
|
"write_file",
|
|
|
|
|
"list_directory",
|
|
|
|
|
"db_set",
|
|
|
|
|
"db_get",
|
|
|
|
|
"db_query",
|
2025-11-04 05:17:27 +01:00
|
|
|
},
|
2025-11-04 08:09:12 +01:00
|
|
|
specialization_areas=[
|
|
|
|
|
"agent_coordination",
|
|
|
|
|
"task_delegation",
|
|
|
|
|
"result_integration",
|
|
|
|
|
],
|
|
|
|
|
temperature=0.5,
|
2025-11-04 05:17:27 +01:00
|
|
|
),
|
2025-11-04 08:09:12 +01:00
|
|
|
"general": AgentRole(
|
|
|
|
|
name="general",
|
|
|
|
|
description="General purpose agent for miscellaneous tasks",
|
|
|
|
|
system_prompt="""You are a general purpose AI assistant. Your responsibilities:
|
2025-11-04 05:17:27 +01:00
|
|
|
- Handle diverse tasks across multiple domains
|
|
|
|
|
- Provide balanced assistance for various needs
|
|
|
|
|
- Adapt to different types of requests
|
|
|
|
|
- Collaborate with specialized agents when needed
|
2025-11-04 08:09:12 +01:00
|
|
|
Focus on versatility, helpfulness, and task completion.""",
|
2025-11-04 05:17:27 +01:00
|
|
|
allowed_tools={
|
2025-11-04 08:09:12 +01:00
|
|
|
"read_file",
|
|
|
|
|
"write_file",
|
|
|
|
|
"list_directory",
|
|
|
|
|
"create_directory",
|
|
|
|
|
"change_directory",
|
|
|
|
|
"get_current_directory",
|
|
|
|
|
"python_exec",
|
|
|
|
|
"run_command",
|
|
|
|
|
"run_command_interactive",
|
|
|
|
|
"http_fetch",
|
|
|
|
|
"web_search",
|
|
|
|
|
"web_search_news",
|
|
|
|
|
"db_set",
|
|
|
|
|
"db_get",
|
|
|
|
|
"db_query",
|
|
|
|
|
"index_directory",
|
2025-11-04 05:17:27 +01:00
|
|
|
},
|
2025-11-04 08:09:12 +01:00
|
|
|
specialization_areas=["general_assistance"],
|
|
|
|
|
temperature=0.7,
|
|
|
|
|
),
|
2025-11-04 05:17:27 +01:00
|
|
|
}
|
|
|
|
|
|
2025-11-04 08:09:12 +01:00
|
|
|
|
2025-11-04 05:17:27 +01:00
|
|
|
def get_agent_role(role_name: str) -> AgentRole:
|
2025-11-04 08:09:12 +01:00
|
|
|
return AGENT_ROLES.get(role_name, AGENT_ROLES["general"])
|
|
|
|
|
|
2025-11-04 05:17:27 +01:00
|
|
|
|
|
|
|
|
def list_agent_roles() -> Dict[str, AgentRole]:
|
|
|
|
|
return AGENT_ROLES.copy()
|
|
|
|
|
|
2025-11-04 08:09:12 +01:00
|
|
|
|
2025-11-04 05:17:27 +01:00
|
|
|
def get_recommended_agent(task_description: str) -> str:
|
|
|
|
|
task_lower = task_description.lower()
|
|
|
|
|
|
2025-11-04 08:09:12 +01:00
|
|
|
code_keywords = [
|
|
|
|
|
"code",
|
|
|
|
|
"implement",
|
|
|
|
|
"function",
|
|
|
|
|
"class",
|
|
|
|
|
"bug",
|
|
|
|
|
"debug",
|
|
|
|
|
"refactor",
|
|
|
|
|
"optimize",
|
|
|
|
|
]
|
|
|
|
|
research_keywords = [
|
|
|
|
|
"search",
|
|
|
|
|
"find",
|
|
|
|
|
"research",
|
|
|
|
|
"information",
|
|
|
|
|
"analyze",
|
|
|
|
|
"investigate",
|
|
|
|
|
]
|
|
|
|
|
data_keywords = ["data", "database", "query", "statistics", "analyze", "process"]
|
|
|
|
|
planning_keywords = ["plan", "organize", "workflow", "steps", "coordinate"]
|
|
|
|
|
testing_keywords = ["test", "verify", "validate", "check", "quality"]
|
|
|
|
|
doc_keywords = ["document", "documentation", "explain", "guide", "manual"]
|
2025-11-04 05:17:27 +01:00
|
|
|
|
|
|
|
|
if any(keyword in task_lower for keyword in code_keywords):
|
2025-11-04 08:09:12 +01:00
|
|
|
return "coding"
|
2025-11-04 05:17:27 +01:00
|
|
|
elif any(keyword in task_lower for keyword in research_keywords):
|
2025-11-04 08:09:12 +01:00
|
|
|
return "research"
|
2025-11-04 05:17:27 +01:00
|
|
|
elif any(keyword in task_lower for keyword in data_keywords):
|
2025-11-04 08:09:12 +01:00
|
|
|
return "data_analysis"
|
2025-11-04 05:17:27 +01:00
|
|
|
elif any(keyword in task_lower for keyword in planning_keywords):
|
2025-11-04 08:09:12 +01:00
|
|
|
return "planning"
|
2025-11-04 05:17:27 +01:00
|
|
|
elif any(keyword in task_lower for keyword in testing_keywords):
|
2025-11-04 08:09:12 +01:00
|
|
|
return "testing"
|
2025-11-04 05:17:27 +01:00
|
|
|
elif any(keyword in task_lower for keyword in doc_keywords):
|
2025-11-04 08:09:12 +01:00
|
|
|
return "documentation"
|
2025-11-04 05:17:27 +01:00
|
|
|
else:
|
2025-11-04 08:09:12 +01:00
|
|
|
return "general"
|