-
Notifications
You must be signed in to change notification settings - Fork 0
feat(phase1): tool reranking, rejection, reflection, context repository, extended metrics, agent recommender #10
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
Open
cherninkiy
wants to merge
1
commit into
main
Choose a base branch
from
dev
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,67 +1,35 @@ | ||
| # Logs and temporary files | ||
| *.log | ||
| *.tmp | ||
| *.swp | ||
|
|
||
| # Environment files | ||
| .env | ||
| .env.local | ||
| *.env.* | ||
|
|
||
| # Coverage reports | ||
| coverage/ | ||
| htmlcov/ | ||
| .coverage | ||
|
|
||
| # Python specific | ||
| __pycache__/ | ||
| *.pyc | ||
| *.pyo | ||
| *.pyd | ||
| .Python | ||
| *.so | ||
| .coverage | ||
| coverage/ | ||
| htmlcov/ | ||
| .pytest_cache/ | ||
| *.egg-info/ | ||
| .eggs/ | ||
| .mypy_cache/ | ||
| .pytest_cache/ | ||
| .tox/ | ||
|
|
||
| # Build and distribution artifacts | ||
| # Build artifacts | ||
| dist/ | ||
| build/ | ||
| *.egg-info/ | ||
| .eggs/ | ||
|
|
||
| # Dependencies | ||
| .venv/ | ||
| venv/ | ||
| .env/ | ||
| node_modules/ | ||
|
|
||
| # Editors and IDEs | ||
| .vscode/ | ||
| .idea/ | ||
| *.swp | ||
| *.swo | ||
|
|
||
| # OS generated files | ||
| .DS_Store | ||
| Thumbs.db | ||
| *.egg | ||
|
|
||
| # Compression and archives | ||
| *.zip | ||
| *.gz | ||
| *.tar | ||
| *.tgz | ||
| *.bz2 | ||
| *.xz | ||
| *.7z | ||
| *.rar | ||
| *.zst | ||
| *.lz4 | ||
| *.lzh | ||
| *.cab | ||
| *.arj | ||
| *.rpm | ||
| *.deb | ||
| *.Z | ||
| *.lz | ||
| *.lzo | ||
| *.tar.gz | ||
| *.tar.bz2 | ||
| *.tar.xz | ||
| *.tar.zst | ||
| # Original rule preserved | ||
| *.log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Specialized agent modules.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,193 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Lightweight agent recommendation based on trajectory history. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| This module intentionally starts with a compact heuristic model that mimics the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| planned RecVAE API surface while remaining dependency-free. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from __future__ import annotations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from dataclasses import dataclass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing import Any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def _tokenize(text: str) -> set[str]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return {part.strip(".,!?;:()[]{}\"'").lower() for part in text.split() if part.strip()} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @dataclass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class AgentPerformance: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Aggregated performance for an agent and task category.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| agent_id: str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| task_type: str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| success_rate: float | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| avg_success_score: float | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| avg_latency_ms: float | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sample_count: int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class TrajectoryEncoder: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Simple trajectory encoder/decoder. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Produces a compact latent vector: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [avg_success_score, avg_latency_norm, average_step_depth, event_count_norm]. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def encode_trajectory(self, events_list: list[dict[str, Any]]) -> list[float]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not events_list: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [0.0, 0.0, 0.0, 0.0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| count = len(events_list) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| avg_success = sum(float(e.get("success_score", 0.0)) for e in events_list) / count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| avg_latency = sum(float(e.get("execution_time_ms", 0.0)) for e in events_list) / count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| avg_step = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sum(float(e.get("step_number", 0.0) or 0.0) for e in events_list) / count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| max(0.0, min(1.0, avg_success)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| max(0.0, min(1.0, avg_latency / 10000.0)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| max(0.0, min(1.0, avg_step / 20.0)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| max(0.0, min(1.0, count / 20.0)), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def decode_vector(self, latent_vector: list[float]) -> dict[str, float]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| padded = (latent_vector + [0.0, 0.0, 0.0, 0.0])[:4] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "expected_success_score": max(0.0, min(1.0, float(padded[0]))), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "expected_latency_ms": max(0.0, float(padded[1])) * 10000.0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "expected_step_depth": max(0.0, float(padded[2])) * 20.0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "trajectory_density": max(0.0, min(1.0, float(padded[3]))), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class AgentRecommender: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Recommend agents using historical success and task similarity.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def __init__(self) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self._stats: dict[tuple[str, str], AgentPerformance] = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self._trained = False | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def train_on_history(self, metrics_events: list[dict[str, Any]]) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| grouped: dict[tuple[str, str], dict[str, float]] = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for event in metrics_events: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| agent_id = str(event.get("agent_id", "unknown")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| task_type = str(event.get("task_type", "general")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| key = (agent_id, task_type) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| grouped.setdefault( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| key, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "count": 0.0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "success_sum": 0.0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "success_bool_sum": 0.0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "latency_sum": 0.0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| g = grouped[key] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| score = float(event.get("success_score", 1.0 if event.get("success") else 0.0)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| g["count"] += 1.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| g["success_sum"] += score | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| g["success_bool_sum"] += 1.0 if score >= 0.5 else 0.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| g["latency_sum"] += float(event.get("execution_time_ms", 0.0)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self._stats = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (agent_id, task_type), g in grouped.items(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| count = max(1, int(g["count"])) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self._stats[(agent_id, task_type)] = AgentPerformance( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| agent_id=agent_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| task_type=task_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| success_rate=g["success_bool_sum"] / count, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| avg_success_score=g["success_sum"] / count, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| avg_latency_ms=g["latency_sum"] / count, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sample_count=count, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self._trained = True | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def recommend_agents( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| task_description: str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| context: dict[str, Any] | None = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| top_k: int = 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> list[dict[str, Any]]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not self._trained or not self._stats: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| context = context or {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target_task_type = str(context.get("task_type", "general")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target_tokens = _tokenize(f"{target_task_type} {task_description}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scored: list[tuple[float, AgentPerformance]] = [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for perf in self._stats.values(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type_tokens = _tokenize(perf.task_type) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| overlap = len(target_tokens & type_tokens) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| similarity = overlap / max(1, len(target_tokens)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Higher success and lower latency are preferred; sample_count adds confidence. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| confidence = min(1.0, perf.sample_count / 10.0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| latency_bonus = 1.0 / (1.0 + perf.avg_latency_ms / 1000.0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| final_score = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| perf.avg_success_score * 0.6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| + perf.success_rate * 0.2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| + similarity * 0.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| + latency_bonus * 0.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) * (0.7 + 0.3 * confidence) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scored.append((final_score, perf)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scored.sort(key=lambda item: item[0], reverse=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "agent_id": perf.agent_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "task_type": perf.task_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "score": round(score, 4), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "success_rate": round(perf.success_rate, 4), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "avg_success_score": round(perf.avg_success_score, 4), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "avg_latency_ms": round(perf.avg_latency_ms, 2), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "sample_count": perf.sample_count, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for score, perf in scored[: max(0, top_k)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_agent_success_rate(self, agent_id: str, task_type: str = "general") -> float: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| perf = self._stats.get((agent_id, task_type)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if perf: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return perf.success_rate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Fallback to overall rate for the agent across all task types. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| matches = [p for p in self._stats.values() if p.agent_id == agent_id] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not matches: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 0.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return sum(p.success_rate for p in matches) / len(matches) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class CommitteeBuilder: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Build and optimize an execution committee from recommendations.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def build_committee( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| recommendations: list[dict[str, Any]], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constraints: dict[str, Any] | None = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> list[dict[str, Any]]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constraints = constraints or {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| max_members = int(constraints.get("max_members", 3)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| min_score = float(constraints.get("min_score", 0.0)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| filtered = [item for item in recommendations if float(item.get("score", 0.0)) >= min_score] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return filtered[: max(0, max_members)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def optimize_committee_composition( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| candidate_agents: list[dict[str, Any]], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> list[dict[str, Any]]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Encourage task-type diversity while keeping high-ranked agents first. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chosen: list[dict[str, Any]] = [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| seen_task_types: set[str] = set() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for agent in candidate_agents: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| task_type = str(agent.get("task_type", "general")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if task_type not in seen_task_types: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chosen.append(agent) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| seen_task_types.add(task_type) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Add remaining candidates to fill committee capacity. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for agent in candidate_agents: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if agent not in chosen: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chosen.append(agent) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return chosen | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+181
to
+193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation uses
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The trajectory metrics are calculated using multiple generator expressions, which results in iterating over
events_listthree times. This can be optimized into a single loop for better performance, especially as the number of events grows.