fix: address remaining review comments — broken import, race condition, duplicate logic

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
alex-clawd
2026-05-13 00:12:18 -07:00
parent 2ddc348ad2
commit 089656195d
3 changed files with 37 additions and 63 deletions

View File

@@ -1035,6 +1035,34 @@ class AgentTUI(App[None]):
return self._get_or_create_agent(self._agent_names[0])
return None
def _format_memory_record(self, i: int, mem: object) -> list[str]:
"""Format a single memory record into Rich markup lines."""
record = getattr(mem, "record", mem)
content = getattr(record, "content", "") or str(mem)
if len(content) > 150:
content = content[:150] + "..."
meta = getattr(record, "metadata", {}) or {}
mem_type = meta.get("type", "raw")
importance = getattr(record, "importance", "") or meta.get("importance", "")
scope = getattr(record, "scope", "") or meta.get("scope", "")
timestamp = getattr(record, "created_at", "")
type_tag = (
f"[bold cyan]{mem_type}[/]"
if mem_type == "canonical"
else f"[dim]{mem_type}[/]"
)
importance_tag = f" [yellow]★{importance}[/]" if importance else ""
scope_tag = f" [{_DIM}]scope:{scope}[/]" if scope else ""
time_tag = f" [{_DIM}]{timestamp}[/]" if timestamp else ""
return [
f" {i}. {type_tag}{importance_tag}{scope_tag}{time_tag}",
f" {content}",
"",
]
def _show_memory_panel(self) -> None:
"""Show recent memories for the focused agent (GAP-92: rich formatting)."""
agent = self._get_focused_agent()
@@ -1055,31 +1083,7 @@ class AgentTUI(App[None]):
lines = [f"[bold]Memory Inspector — {agent_name}[/]\n"]
for i, mem in enumerate(memories, 1):
record = getattr(mem, "record", mem)
content = getattr(record, "content", "") or str(mem)
if len(content) > 150:
content = content[:150] + "..."
meta = getattr(record, "metadata", {}) or {}
mem_type = meta.get("type", "raw")
importance = getattr(record, "importance", "") or meta.get("importance", "")
scope = getattr(record, "scope", "") or meta.get("scope", "")
timestamp = getattr(record, "created_at", "")
type_tag = (
f"[bold cyan]{mem_type}[/]"
if mem_type == "canonical"
else f"[dim]{mem_type}[/]"
)
importance_tag = f" [yellow]★{importance}[/]" if importance else ""
scope_tag = f" [{_DIM}]scope:{scope}[/]" if scope else ""
time_tag = f" [{_DIM}]{timestamp}[/]" if timestamp else ""
lines.append(
f" {i}. {type_tag}{importance_tag}{scope_tag}{time_tag}"
)
lines.append(f" {content}")
lines.append("")
lines.extend(self._format_memory_record(i, mem))
lines.append(f"[{_DIM}]Use /memory search <query> to filter[/]")
self._mount_sys("\n".join(lines))
@@ -1106,31 +1110,7 @@ class AgentTUI(App[None]):
lines = [f"[bold]Memories matching '{query}'{agent_name}[/]\n"]
for i, mem in enumerate(results, 1):
record = getattr(mem, "record", mem)
content = getattr(record, "content", "") or str(mem)
if len(content) > 150:
content = content[:150] + "..."
meta = getattr(record, "metadata", {}) or {}
mem_type = meta.get("type", "raw")
importance = getattr(record, "importance", "") or meta.get("importance", "")
scope = getattr(record, "scope", "") or meta.get("scope", "")
timestamp = getattr(record, "created_at", "")
type_tag = (
f"[bold cyan]{mem_type}[/]"
if mem_type == "canonical"
else f"[dim]{mem_type}[/]"
)
importance_tag = f" [yellow]★{importance}[/]" if importance else ""
scope_tag = f" [{_DIM}]scope:{scope}[/]" if scope else ""
time_tag = f" [{_DIM}]{timestamp}[/]" if timestamp else ""
lines.append(
f" {i}. {type_tag}{importance_tag}{scope_tag}{time_tag}"
)
lines.append(f" {content}")
lines.append("")
lines.extend(self._format_memory_record(i, mem))
lines.append(f"[{_DIM}]Use /memory search <query> to refine[/]")
self._mount_sys("\n".join(lines))

View File

@@ -197,10 +197,8 @@ async def _run_model_benchmark(
emit({"type": "model_start", "model": model, "total_cases": total})
sem = asyncio.Semaphore(_MAX_CASES_PARALLEL)
done_count = 0
async def _run_case(i: int, case: BenchmarkCase) -> BenchmarkResult:
nonlocal done_count
async with sem:
emit({"type": "case_start", "model": model, "case_index": i, "total_cases": total, "input": case.input})
@@ -220,8 +218,7 @@ async def _run_model_benchmark(
try:
agent = _load_agent(bench_defn, agents_dir=agents_dir)
except Exception as e:
done_count += 1
emit({"type": "case_done", "model": model, "case_index": done_count, "total_cases": total, "passed": False, "score": 0.0, "time_ms": 0, "error": str(e)})
emit({"type": "case_done", "model": model, "case_index": i, "total_cases": total, "passed": False, "score": 0.0, "time_ms": 0, "error": str(e)})
return BenchmarkResult(
case_index=i, input=case.input, expected=case.expected,
actual=f"[Agent creation error: {e}]", model=model, passed=False, score=0.0,
@@ -240,8 +237,7 @@ async def _run_model_benchmark(
cost = response.cost
except asyncio.TimeoutError:
elapsed_ms = _current_time_ms() - start_ms
done_count += 1
emit({"type": "case_done", "model": model, "case_index": done_count, "total_cases": total, "passed": False, "score": 0.0, "time_ms": elapsed_ms, "error": "timeout"})
emit({"type": "case_done", "model": model, "case_index": i, "total_cases": total, "passed": False, "score": 0.0, "time_ms": elapsed_ms, "error": "timeout"})
return BenchmarkResult(
case_index=i, input=case.input, expected=case.expected,
actual=f"[Timeout after {_CASE_TIMEOUT_SECONDS}s]", model=model, passed=False, score=0.0,
@@ -249,8 +245,7 @@ async def _run_model_benchmark(
)
except Exception as e:
elapsed_ms = _current_time_ms() - start_ms
done_count += 1
emit({"type": "case_done", "model": model, "case_index": done_count, "total_cases": total, "passed": False, "score": 0.0, "time_ms": elapsed_ms, "error": str(e)})
emit({"type": "case_done", "model": model, "case_index": i, "total_cases": total, "passed": False, "score": 0.0, "time_ms": elapsed_ms, "error": str(e)})
return BenchmarkResult(
case_index=i, input=case.input, expected=case.expected,
actual=f"[Error: {e}]", model=model, passed=False, score=0.0,
@@ -261,7 +256,7 @@ async def _run_model_benchmark(
if case.expected is not None:
passed, score = _check_expected(case.expected, actual)
if case.criteria is not None:
emit({"type": "judging", "model": model, "case_index": done_count + 1, "total_cases": total})
emit({"type": "judging", "model": model, "case_index": i, "total_cases": total})
try:
criteria_passed, criteria_score = await asyncio.wait_for(
_judge_with_llm(case.criteria, case.input, actual, judge_model),
@@ -275,8 +270,7 @@ async def _run_model_benchmark(
else:
passed, score = criteria_passed, criteria_score
done_count += 1
emit({"type": "case_done", "model": model, "case_index": done_count, "total_cases": total, "passed": passed, "score": score, "time_ms": elapsed_ms})
emit({"type": "case_done", "model": model, "case_index": i, "total_cases": total, "passed": passed, "score": score, "time_ms": elapsed_ms})
return BenchmarkResult(
case_index=i, input=case.input, expected=case.expected, actual=actual,
model=model, passed=passed, score=score,

View File

@@ -229,8 +229,8 @@ def _train_new_agents(agent_files: list, n_iterations: int) -> None:
click.secho(f"Training {agent_name} ({len(cases)} cases, {n_iterations} iterations)", fg="cyan", bold=True)
try:
from crewai.new_agent.definition_parser import load_agent_definition
agent = load_agent_definition(str(agent_path))
from crewai.new_agent.definition_parser import load_agent_from_definition
agent = load_agent_from_definition(str(agent_path))
except Exception as e:
click.secho(f" Error loading agent {agent_name}: {e}", fg="red")
continue