style(memory): apply ruff formatting and linting fixes

Auto-fixed linting errors and formatting issues:
- Removed unused imports (F401): pytest, Any, AnalysisType, MemoryType, OutcomeType
- Removed unused variable (F841): hooks variable in test
- Applied consistent formatting across memory service and test files

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-05 14:07:48 +01:00
parent e3fe0439fd
commit cf6291ac8e
17 changed files with 236 additions and 185 deletions

View File

@@ -414,12 +414,14 @@ class MemoryToolService:
if args.query.lower() in key.lower():
value = await working.get(key)
if value is not None:
results.append({
"type": "working",
"key": key,
"content": str(value),
"relevance": 1.0,
})
results.append(
{
"type": "working",
"key": key,
"content": str(value),
"relevance": 1.0,
}
)
elif memory_type == MemoryType.EPISODIC:
episodic = await self._get_episodic()
@@ -430,14 +432,18 @@ class MemoryToolService:
agent_instance_id=context.agent_instance_id,
)
for episode in episodes:
results.append({
"type": "episodic",
"id": str(episode.id),
"summary": episode.task_description,
"outcome": episode.outcome.value if episode.outcome else None,
"occurred_at": episode.occurred_at.isoformat(),
"relevance": episode.importance_score,
})
results.append(
{
"type": "episodic",
"id": str(episode.id),
"summary": episode.task_description,
"outcome": episode.outcome.value
if episode.outcome
else None,
"occurred_at": episode.occurred_at.isoformat(),
"relevance": episode.importance_score,
}
)
elif memory_type == MemoryType.SEMANTIC:
semantic = await self._get_semantic()
@@ -448,15 +454,17 @@ class MemoryToolService:
min_confidence=args.min_relevance,
)
for fact in facts:
results.append({
"type": "semantic",
"id": str(fact.id),
"subject": fact.subject,
"predicate": fact.predicate,
"object": fact.object,
"confidence": fact.confidence,
"relevance": fact.confidence,
})
results.append(
{
"type": "semantic",
"id": str(fact.id),
"subject": fact.subject,
"predicate": fact.predicate,
"object": fact.object,
"confidence": fact.confidence,
"relevance": fact.confidence,
}
)
elif memory_type == MemoryType.PROCEDURAL:
procedural = await self._get_procedural()
@@ -467,15 +475,17 @@ class MemoryToolService:
limit=args.limit,
)
for proc in procedures:
results.append({
"type": "procedural",
"id": str(proc.id),
"name": proc.name,
"trigger": proc.trigger_pattern,
"success_rate": proc.success_rate,
"steps_count": len(proc.steps) if proc.steps else 0,
"relevance": proc.success_rate,
})
results.append(
{
"type": "procedural",
"id": str(proc.id),
"name": proc.name,
"trigger": proc.trigger_pattern,
"success_rate": proc.success_rate,
"steps_count": len(proc.steps) if proc.steps else 0,
"relevance": proc.success_rate,
}
)
# Sort by relevance and limit
results.sort(key=lambda x: x.get("relevance", 0), reverse=True)
@@ -601,7 +611,11 @@ class MemoryToolService:
if ep.task_type:
task_types[ep.task_type] = task_types.get(ep.task_type, 0) + 1
if ep.outcome:
outcome_val = ep.outcome.value if hasattr(ep.outcome, "value") else str(ep.outcome)
outcome_val = (
ep.outcome.value
if hasattr(ep.outcome, "value")
else str(ep.outcome)
)
outcomes[outcome_val] = outcomes.get(outcome_val, 0) + 1
# Sort by frequency
@@ -613,11 +627,13 @@ class MemoryToolService:
examples = []
if args.include_examples:
for ep in episodes[: min(3, args.max_items)]:
examples.append({
"summary": ep.task_description,
"task_type": ep.task_type,
"outcome": ep.outcome.value if ep.outcome else None,
})
examples.append(
{
"summary": ep.task_description,
"task_type": ep.task_type,
"outcome": ep.outcome.value if ep.outcome else None,
}
)
return {
"analysis_type": "recent_patterns",
@@ -661,11 +677,13 @@ class MemoryToolService:
examples = []
if args.include_examples:
for ep in successful[: min(3, args.max_items)]:
examples.append({
"summary": ep.task_description,
"task_type": ep.task_type,
"lessons": ep.lessons_learned,
})
examples.append(
{
"summary": ep.task_description,
"task_type": ep.task_type,
"lessons": ep.lessons_learned,
}
)
return {
"analysis_type": "success_factors",
@@ -694,9 +712,7 @@ class MemoryToolService:
failure_by_task[task].append(ep)
# Most common failure types
failure_counts = {
task: len(eps) for task, eps in failure_by_task.items()
}
failure_counts = {task: len(eps) for task, eps in failure_by_task.items()}
top_failures = sorted(failure_counts.items(), key=lambda x: x[1], reverse=True)[
: args.max_items
]
@@ -704,12 +720,14 @@ class MemoryToolService:
examples = []
if args.include_examples:
for ep in failed[: min(3, args.max_items)]:
examples.append({
"summary": ep.task_description,
"task_type": ep.task_type,
"lessons": ep.lessons_learned,
"error": ep.outcome_details,
})
examples.append(
{
"summary": ep.task_description,
"task_type": ep.task_type,
"lessons": ep.lessons_learned,
"error": ep.outcome_details,
}
)
return {
"analysis_type": "failure_patterns",
@@ -794,15 +812,21 @@ class MemoryToolService:
insights = []
if top_tasks:
insights.append(f"Most common task type: {top_tasks[0][0]} ({top_tasks[0][1]} occurrences)")
insights.append(
f"Most common task type: {top_tasks[0][0]} ({top_tasks[0][1]} occurrences)"
)
total = sum(outcome_dist.values())
if total > 0:
success_rate = outcome_dist.get("success", 0) / total
if success_rate > 0.8:
insights.append("High success rate observed - current approach is working well")
insights.append(
"High success rate observed - current approach is working well"
)
elif success_rate < 0.5:
insights.append("Success rate below 50% - consider reviewing procedures")
insights.append(
"Success rate below 50% - consider reviewing procedures"
)
return insights
@@ -839,9 +863,13 @@ class MemoryToolService:
if top_failures:
worst_task, count = top_failures[0]
tips.append(f"'{worst_task}' has most failures ({count}) - needs procedure review")
tips.append(
f"'{worst_task}' has most failures ({count}) - needs procedure review"
)
tips.append("Review lessons_learned from past failures before attempting similar tasks")
tips.append(
"Review lessons_learned from past failures before attempting similar tasks"
)
return tips
@@ -912,7 +940,11 @@ class MemoryToolService:
outcomes = {"success": 0, "failure": 0, "partial": 0, "abandoned": 0}
for ep in recent_episodes:
if ep.outcome:
key = ep.outcome.value if hasattr(ep.outcome, "value") else str(ep.outcome)
key = (
ep.outcome.value
if hasattr(ep.outcome, "value")
else str(ep.outcome)
)
if key in outcomes:
outcomes[key] += 1
@@ -942,7 +974,8 @@ class MemoryToolService:
# Filter by minimum success rate if specified
procedures = [
p for p in all_procedures
p
for p in all_procedures
if args.min_success_rate is None or p.success_rate >= args.min_success_rate
][: args.limit]