Spaces:
Sleeping
Sleeping
Chris
commited on
Commit
·
ec90d0f
1
Parent(s):
f753656
Final 7.11.3
Browse files
src/agents/__pycache__/router.cpython-310.pyc
CHANGED
|
Binary files a/src/agents/__pycache__/router.cpython-310.pyc and b/src/agents/__pycache__/router.cpython-310.pyc differ
|
|
|
src/agents/router.py
CHANGED
|
@@ -80,7 +80,7 @@ class RouterAgent:
|
|
| 80 |
llm_classification = self._get_llm_classification(state.question)
|
| 81 |
|
| 82 |
# Combine pattern-based and LLM-based classification
|
| 83 |
-
final_types, final_primary = self.
|
| 84 |
question_types, primary_type, llm_classification
|
| 85 |
)
|
| 86 |
|
|
@@ -565,8 +565,8 @@ REASONING: [brief explanation]
|
|
| 565 |
|
| 566 |
return parsed
|
| 567 |
|
| 568 |
-
def
|
| 569 |
-
|
| 570 |
"""Combine pattern-based and LLM-based classifications"""
|
| 571 |
|
| 572 |
# Map LLM classification to our enum types
|
|
@@ -597,35 +597,36 @@ REASONING: [brief explanation]
|
|
| 597 |
|
| 598 |
return combined_types, final_primary
|
| 599 |
|
| 600 |
-
def
|
| 601 |
-
"""Select agents based on
|
| 602 |
-
|
| 603 |
-
agents = []
|
| 604 |
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
QuestionType.MATHEMATICAL: AgentRole.REASONING_AGENT,
|
| 608 |
-
QuestionType.TEXT_MANIPULATION: AgentRole.REASONING_AGENT,
|
| 609 |
-
QuestionType.WEB_RESEARCH: AgentRole.WEB_RESEARCHER,
|
| 610 |
-
QuestionType.FILE_PROCESSING: AgentRole.FILE_PROCESSOR,
|
| 611 |
-
QuestionType.REASONING: AgentRole.REASONING_AGENT,
|
| 612 |
-
QuestionType.CODE_EXECUTION: AgentRole.CODE_EXECUTOR
|
| 613 |
-
}
|
| 614 |
|
| 615 |
-
|
| 616 |
-
if
|
| 617 |
-
agents.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 618 |
|
| 619 |
-
#
|
| 620 |
-
|
| 621 |
-
if qtype != primary_type: # Don't duplicate primary
|
| 622 |
-
secondary_agent = primary_agent_map.get(qtype)
|
| 623 |
-
if secondary_agent and secondary_agent not in agents:
|
| 624 |
-
agents.append(secondary_agent)
|
| 625 |
|
| 626 |
-
#
|
| 627 |
-
if
|
| 628 |
-
|
|
|
|
| 629 |
|
| 630 |
return agents
|
| 631 |
|
|
@@ -1035,6 +1036,38 @@ REASONING: [brief explanation]
|
|
| 1035 |
'reasoning': 'LLM classification error'
|
| 1036 |
}
|
| 1037 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1038 |
def _combine_classifications(self, pattern_result: Dict[str, Any], llm_result: Dict[str, Any], question: str) -> Dict[str, Any]:
|
| 1039 |
"""Combine pattern and LLM classifications for final decision"""
|
| 1040 |
|
|
@@ -1085,37 +1118,4 @@ REASONING: [brief explanation]
|
|
| 1085 |
'reasoning': reasoning,
|
| 1086 |
'pattern_result': pattern_result,
|
| 1087 |
'llm_result': llm_result
|
| 1088 |
-
}
|
| 1089 |
-
|
| 1090 |
-
def _select_agents_for_type(self, classification_result: Dict[str, Any]) -> List[AgentRole]:
|
| 1091 |
-
"""Select appropriate agents based on enhanced classification"""
|
| 1092 |
-
|
| 1093 |
-
question_type = classification_result['type']
|
| 1094 |
-
confidence = classification_result['confidence']
|
| 1095 |
-
|
| 1096 |
-
# Agent selection based on question type
|
| 1097 |
-
if question_type == 'mathematical':
|
| 1098 |
-
agents = [AgentRole.WEB_RESEARCHER, AgentRole.REASONING_AGENT]
|
| 1099 |
-
elif question_type == 'text_manipulation':
|
| 1100 |
-
agents = [AgentRole.REASONING_AGENT]
|
| 1101 |
-
elif question_type == 'file_processing':
|
| 1102 |
-
agents = [AgentRole.FILE_PROCESSOR, AgentRole.REASONING_AGENT]
|
| 1103 |
-
elif question_type == 'web_research':
|
| 1104 |
-
agents = [AgentRole.WEB_RESEARCHER]
|
| 1105 |
-
elif question_type == 'reasoning':
|
| 1106 |
-
agents = [AgentRole.REASONING_AGENT, AgentRole.WEB_RESEARCHER]
|
| 1107 |
-
elif question_type == 'factual_lookup':
|
| 1108 |
-
agents = [AgentRole.WEB_RESEARCHER]
|
| 1109 |
-
else:
|
| 1110 |
-
# General questions - try multiple approaches
|
| 1111 |
-
agents = [AgentRole.WEB_RESEARCHER, AgentRole.REASONING_AGENT]
|
| 1112 |
-
|
| 1113 |
-
# Always add synthesizer
|
| 1114 |
-
agents.append(AgentRole.SYNTHESIZER)
|
| 1115 |
-
|
| 1116 |
-
# If confidence is low, add more agents for better coverage
|
| 1117 |
-
if confidence < 0.6:
|
| 1118 |
-
if AgentRole.WEB_RESEARCHER not in agents:
|
| 1119 |
-
agents.insert(-1, AgentRole.WEB_RESEARCHER) # Insert before synthesizer
|
| 1120 |
-
|
| 1121 |
-
return agents
|
|
|
|
| 80 |
llm_classification = self._get_llm_classification(state.question)
|
| 81 |
|
| 82 |
# Combine pattern-based and LLM-based classification
|
| 83 |
+
final_types, final_primary = self._combine_classifications_legacy(
|
| 84 |
question_types, primary_type, llm_classification
|
| 85 |
)
|
| 86 |
|
|
|
|
| 565 |
|
| 566 |
return parsed
|
| 567 |
|
| 568 |
+
def _combine_classifications_legacy(self, pattern_types: List[QuestionType], pattern_primary: QuestionType,
|
| 569 |
+
llm_classification: Dict[str, Any]) -> Tuple[List[QuestionType], QuestionType]:
|
| 570 |
"""Combine pattern-based and LLM-based classifications"""
|
| 571 |
|
| 572 |
# Map LLM classification to our enum types
|
|
|
|
| 597 |
|
| 598 |
return combined_types, final_primary
|
| 599 |
|
| 600 |
+
def _select_agents_for_type(self, classification_result: Dict[str, Any]) -> List[AgentRole]:
|
| 601 |
+
"""Select appropriate agents based on enhanced classification"""
|
|
|
|
|
|
|
| 602 |
|
| 603 |
+
question_type = classification_result['type']
|
| 604 |
+
confidence = classification_result['confidence']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 605 |
|
| 606 |
+
# Agent selection based on question type
|
| 607 |
+
if question_type == 'mathematical':
|
| 608 |
+
agents = [AgentRole.WEB_RESEARCHER, AgentRole.REASONING_AGENT]
|
| 609 |
+
elif question_type == 'text_manipulation':
|
| 610 |
+
agents = [AgentRole.REASONING_AGENT]
|
| 611 |
+
elif question_type == 'file_processing':
|
| 612 |
+
agents = [AgentRole.FILE_PROCESSOR, AgentRole.REASONING_AGENT]
|
| 613 |
+
elif question_type == 'web_research':
|
| 614 |
+
agents = [AgentRole.WEB_RESEARCHER]
|
| 615 |
+
elif question_type == 'reasoning':
|
| 616 |
+
agents = [AgentRole.REASONING_AGENT, AgentRole.WEB_RESEARCHER]
|
| 617 |
+
elif question_type == 'factual_lookup':
|
| 618 |
+
agents = [AgentRole.WEB_RESEARCHER]
|
| 619 |
+
else:
|
| 620 |
+
# General questions - try multiple approaches
|
| 621 |
+
agents = [AgentRole.WEB_RESEARCHER, AgentRole.REASONING_AGENT]
|
| 622 |
|
| 623 |
+
# Always add synthesizer
|
| 624 |
+
agents.append(AgentRole.SYNTHESIZER)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 625 |
|
| 626 |
+
# If confidence is low, add more agents for better coverage
|
| 627 |
+
if confidence < 0.6:
|
| 628 |
+
if AgentRole.WEB_RESEARCHER not in agents:
|
| 629 |
+
agents.insert(-1, AgentRole.WEB_RESEARCHER) # Insert before synthesizer
|
| 630 |
|
| 631 |
return agents
|
| 632 |
|
|
|
|
| 1036 |
'reasoning': 'LLM classification error'
|
| 1037 |
}
|
| 1038 |
|
| 1039 |
+
def _select_agents(self, question_types: List[QuestionType], primary_type: QuestionType, question: str) -> List[AgentRole]:
|
| 1040 |
+
"""Select agents based on combined classification"""
|
| 1041 |
+
|
| 1042 |
+
agents = []
|
| 1043 |
+
|
| 1044 |
+
# Primary agent based on primary type
|
| 1045 |
+
primary_agent_map = {
|
| 1046 |
+
QuestionType.MATHEMATICAL: AgentRole.REASONING_AGENT,
|
| 1047 |
+
QuestionType.TEXT_MANIPULATION: AgentRole.REASONING_AGENT,
|
| 1048 |
+
QuestionType.WEB_RESEARCH: AgentRole.WEB_RESEARCHER,
|
| 1049 |
+
QuestionType.FILE_PROCESSING: AgentRole.FILE_PROCESSOR,
|
| 1050 |
+
QuestionType.REASONING: AgentRole.REASONING_AGENT,
|
| 1051 |
+
QuestionType.CODE_EXECUTION: AgentRole.CODE_EXECUTOR
|
| 1052 |
+
}
|
| 1053 |
+
|
| 1054 |
+
primary_agent = primary_agent_map.get(primary_type, AgentRole.WEB_RESEARCHER)
|
| 1055 |
+
if primary_agent not in agents:
|
| 1056 |
+
agents.append(primary_agent)
|
| 1057 |
+
|
| 1058 |
+
# Add secondary agents based on all detected types
|
| 1059 |
+
for qtype in question_types:
|
| 1060 |
+
if qtype != primary_type: # Don't duplicate primary
|
| 1061 |
+
secondary_agent = primary_agent_map.get(qtype)
|
| 1062 |
+
if secondary_agent and secondary_agent not in agents:
|
| 1063 |
+
agents.append(secondary_agent)
|
| 1064 |
+
|
| 1065 |
+
# Always add synthesizer at the end
|
| 1066 |
+
if AgentRole.SYNTHESIZER not in agents:
|
| 1067 |
+
agents.append(AgentRole.SYNTHESIZER)
|
| 1068 |
+
|
| 1069 |
+
return agents
|
| 1070 |
+
|
| 1071 |
def _combine_classifications(self, pattern_result: Dict[str, Any], llm_result: Dict[str, Any], question: str) -> Dict[str, Any]:
|
| 1072 |
"""Combine pattern and LLM classifications for final decision"""
|
| 1073 |
|
|
|
|
| 1118 |
'reasoning': reasoning,
|
| 1119 |
'pattern_result': pattern_result,
|
| 1120 |
'llm_result': llm_result
|
| 1121 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|