MCPcopy Create free account
hub / github.com/InternScience/InternAgent / execute

Method execute

internagent/mas/agents/ranking_agent.py:98–314  ·  view source on GitHub ↗

Rank hypotheses using weighted multi-criteria scoring. Evaluates each hypothesis across configured criteria (novelty, plausibility, testability, alignment), computes weighted overall scores, and selects top candidates. Processes hypotheses in batches for efficiency.

(self, context: Dict[str, Any], params: Dict[str, Any])

Source from the content-addressed store, hash-verified

96 return descriptions.get(criterion, f"Evaluation of {criterion}")
97
98 async def execute(self, context: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
99 """
100 Rank hypotheses using weighted multi-criteria scoring.
101
102 Evaluates each hypothesis across configured criteria (novelty, plausibility,
103 testability, alignment), computes weighted overall scores, and selects top
104 candidates. Processes hypotheses in batches for efficiency. Supports distinct
105 selection strategy to ensure diversity across hypothesis families.
106
107 Args:
108 context (Dict[str, Any]): Execution context with keys:
109 - goal (Dict): Research goal and constraints
110 - hypotheses (List[Dict]): Hypotheses to rank with id/text/rationale
111 - iteration (int): Current iteration number
112 - feedback (List[Dict]): Scientist feedback (optional)
113 params (Dict[str, Any]): Runtime parameters (currently unused)
114
115 Returns:
116 Dict[str, Any]: Ranking results containing:
117 - ranked_hypotheses (List[Dict]): Scored hypotheses sorted by score
118 - scoring_explanation (str): Overall scoring rationale
119 - top_hypotheses (List[str]): Top N hypothesis IDs
120 - metadata (Dict): Ranking context
121
122 Raises:
123 AgentExecutionError: If goal/hypotheses missing or ranking fails
124 """
125 # Extract parameters
126 goal = context.get("goal", {})
127 hypotheses = context.get("hypotheses", [])
128
129 if not goal or not hypotheses:
130 raise AgentExecutionError("Research goal and hypotheses are required for ranking")
131
132 if len(hypotheses) == 0:
133 raise AgentExecutionError("At least one hypothesis is required for ranking")
134
135 # Extract optional parameters
136 iteration = context.get("iteration", 0)
137 feedback = context.get("feedback", [])
138
139 # Create a JSON schema for the expected output
140 output_schema = {
141 "type": "object",
142 "properties": {
143 "scored_hypotheses": {
144 "type": "array",
145 "items": {
146 "type": "object",
147 "properties": {
148 "id": {
149 "type": "string",
150 "description": "ID of the hypothesis"
151 },
152 "overall_score": {
153 "type": "number",
154 "description": "Overall score (0.0-10.0)"
155 },

Callers

nothing calls this directly

Calls 6

_build_system_promptMethod · 0.95
_build_ranking_promptMethod · 0.95
AgentExecutionErrorClass · 0.85
_call_modelMethod · 0.80
getMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected