Skip to content

Commit d59ba87

Browse files
committed
style: fix linting and formatting
1 parent 25335d8 commit d59ba87

7 files changed

+425
-331
lines changed

tools/code_implementation_server.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,13 @@ async def read_code_mem(file_paths: List[str]) -> str:
430430
"""
431431
try:
432432
if not file_paths or not isinstance(file_paths, list):
433-
result = {"status": "error", "message": "file_paths parameter is required and must be a list"}
434-
log_operation("read_code_mem_error", {"error": "missing_or_invalid_file_paths"})
433+
result = {
434+
"status": "error",
435+
"message": "file_paths parameter is required and must be a list",
436+
}
437+
log_operation(
438+
"read_code_mem_error", {"error": "missing_or_invalid_file_paths"}
439+
)
435440
return json.dumps(result, ensure_ascii=False, indent=2)
436441

437442
# Remove duplicates while preserving order
@@ -449,10 +454,11 @@ async def read_code_mem(file_paths: List[str]) -> str:
449454
"status": "no_summary",
450455
"file_paths": unique_file_paths,
451456
"message": "No summary file found.",
452-
"results": []
457+
"results": [],
453458
}
454459
log_operation(
455-
"read_code_mem", {"file_paths": unique_file_paths, "status": "no_summary_file"}
460+
"read_code_mem",
461+
{"file_paths": unique_file_paths, "status": "no_summary_file"},
456462
)
457463
return json.dumps(result, ensure_ascii=False, indent=2)
458464

@@ -465,37 +471,40 @@ async def read_code_mem(file_paths: List[str]) -> str:
465471
"status": "no_summary",
466472
"file_paths": unique_file_paths,
467473
"message": "Summary file is empty.",
468-
"results": []
474+
"results": [],
469475
}
470476
log_operation(
471-
"read_code_mem", {"file_paths": unique_file_paths, "status": "empty_summary"}
477+
"read_code_mem",
478+
{"file_paths": unique_file_paths, "status": "empty_summary"},
472479
)
473480
return json.dumps(result, ensure_ascii=False, indent=2)
474481

475482
# Process each file path and collect results
476483
results = []
477484
summaries_found = 0
478-
485+
479486
for file_path in unique_file_paths:
480487
# Extract file-specific section from summary
481-
file_section = _extract_file_section_from_summary(summary_content, file_path)
482-
488+
file_section = _extract_file_section_from_summary(
489+
summary_content, file_path
490+
)
491+
483492
if file_section:
484493
file_result = {
485494
"file_path": file_path,
486495
"status": "summary_found",
487496
"summary_content": file_section,
488-
"message": f"Summary information found for {file_path}"
497+
"message": f"Summary information found for {file_path}",
489498
}
490499
summaries_found += 1
491500
else:
492501
file_result = {
493502
"file_path": file_path,
494503
"status": "no_summary",
495504
"summary_content": None,
496-
"message": f"No summary found for {file_path}"
505+
"message": f"No summary found for {file_path}",
497506
}
498-
507+
499508
results.append(file_result)
500509

501510
# Determine overall status
@@ -512,7 +521,7 @@ async def read_code_mem(file_paths: List[str]) -> str:
512521
"total_requested": len(unique_file_paths),
513522
"summaries_found": summaries_found,
514523
"message": f"Found summaries for {summaries_found}/{len(unique_file_paths)} files",
515-
"results": results
524+
"results": results,
516525
}
517526

518527
log_operation(
@@ -531,10 +540,14 @@ async def read_code_mem(file_paths: List[str]) -> str:
531540
result = {
532541
"status": "error",
533542
"message": f"Failed to check code memory: {str(e)}",
534-
"file_paths": file_paths if isinstance(file_paths, list) else [str(file_paths)],
535-
"results": []
543+
"file_paths": file_paths
544+
if isinstance(file_paths, list)
545+
else [str(file_paths)],
546+
"results": [],
536547
}
537-
log_operation("read_code_mem_error", {"file_paths": file_paths, "error": str(e)})
548+
log_operation(
549+
"read_code_mem_error", {"file_paths": file_paths, "error": str(e)}
550+
)
538551
return json.dumps(result, ensure_ascii=False, indent=2)
539552

540553

utils/llm_utils.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,38 +53,37 @@ def get_preferred_llm_class(config_path: str = "mcp_agent.secrets.yaml") -> Type
5353
return OpenAIAugmentedLLM
5454

5555

56-
def get_default_models(config_path: str = "mcp_agent.config.yaml") -> dict:
56+
def get_default_models(config_path: str = "mcp_agent.config.yaml"):
5757
"""
58-
Get default models configuration from config file.
58+
Get default models from configuration file.
5959
6060
Args:
61-
config_path: Path to the main configuration file
61+
config_path: Path to the configuration file
6262
6363
Returns:
64-
dict: Default models configuration
64+
dict: Dictionary with 'anthropic' and 'openai' default models
6565
"""
6666
try:
6767
if os.path.exists(config_path):
6868
with open(config_path, "r", encoding="utf-8") as f:
6969
config = yaml.safe_load(f)
7070

71-
# Extract model configurations
72-
openai_config = config.get("openai", {})
73-
anthropic_config = config.get("anthropic", {})
71+
# Handle null values in config sections
72+
anthropic_config = config.get("anthropic") or {}
73+
openai_config = config.get("openai") or {}
7474

75-
return {
76-
"anthropic": anthropic_config.get(
77-
"default_model", "claude-sonnet-4-20250514"
78-
),
79-
"openai": openai_config.get("default_model", "o3-mini"),
80-
}
75+
anthropic_model = anthropic_config.get(
76+
"default_model", "claude-sonnet-4-20250514"
77+
)
78+
openai_model = openai_config.get("default_model", "o3-mini")
79+
80+
return {"anthropic": anthropic_model, "openai": openai_model}
8181
else:
82-
print(f"🤖 Config file {config_path} not found, using default models")
82+
print(f"Config file {config_path} not found, using default models")
8383
return {"anthropic": "claude-sonnet-4-20250514", "openai": "o3-mini"}
8484

8585
except Exception as e:
86-
print(f"🤖 Error reading config file {config_path}: {e}")
87-
print("🤖 Falling back to default models")
86+
print(f"❌Error reading config file {config_path}: {e}")
8887
return {"anthropic": "claude-sonnet-4-20250514", "openai": "o3-mini"}
8988

9089

workflows/agents/code_implementation_agent.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ async def _handle_read_file_with_memory_optimization(self, tool_call: Dict) -> D
310310
result_data = json.loads(read_code_mem_result)
311311
# Check if any summaries were found in the results
312312
should_use_summary = (
313-
result_data.get("status") in ["all_summaries_found", "partial_summaries_found"]
313+
result_data.get("status")
314+
in ["all_summaries_found", "partial_summaries_found"]
314315
and result_data.get("summaries_found", 0) > 0
315316
)
316317
except json.JSONDecodeError:
@@ -339,17 +340,25 @@ async def _handle_read_file_with_memory_optimization(self, tool_call: Dict) -> D
339340
# Extract the specific file result for the single file we requested
340341
file_results = result_data.get("results", [])
341342
if file_results and len(file_results) > 0:
342-
specific_result = file_results[0] # Get the first (and only) result
343+
specific_result = file_results[
344+
0
345+
] # Get the first (and only) result
343346
# Transform to match the old single-file format for backward compatibility
344347
transformed_result = {
345348
"status": specific_result.get("status", "no_summary"),
346-
"file_path": specific_result.get("file_path", file_path),
347-
"summary_content": specific_result.get("summary_content"),
349+
"file_path": specific_result.get(
350+
"file_path", file_path
351+
),
352+
"summary_content": specific_result.get(
353+
"summary_content"
354+
),
348355
"message": specific_result.get("message", ""),
349356
"original_tool": "read_file",
350-
"optimization": "redirected_to_read_code_mem"
357+
"optimization": "redirected_to_read_code_mem",
351358
}
352-
final_result = json.dumps(transformed_result, ensure_ascii=False)
359+
final_result = json.dumps(
360+
transformed_result, ensure_ascii=False
361+
)
353362
else:
354363
# Fallback if no results
355364
result_data["original_tool"] = "read_file"
@@ -942,7 +951,11 @@ async def test_summary_functionality(self, test_file_path: str = None):
942951
json.loads(result) if isinstance(result, str) else result
943952
)
944953

945-
if result_data.get("status") in ["all_summaries_found", "partial_summaries_found"] and result_data.get("summaries_found", 0) > 0:
954+
if (
955+
result_data.get("status")
956+
in ["all_summaries_found", "partial_summaries_found"]
957+
and result_data.get("summaries_found", 0) > 0
958+
):
946959
summary_files_found += 1
947960
except Exception as e:
948961
self.logger.warning(
@@ -1042,7 +1055,11 @@ async def test_summary_optimization(self, test_file_path: str = "config.py"):
10421055

10431056
result_data = json.loads(result) if isinstance(result, str) else result
10441057

1045-
return result_data.get("status") in ["all_summaries_found", "partial_summaries_found"] and result_data.get("summaries_found", 0) > 0
1058+
return (
1059+
result_data.get("status")
1060+
in ["all_summaries_found", "partial_summaries_found"]
1061+
and result_data.get("summaries_found", 0) > 0
1062+
)
10461063
except Exception as e:
10471064
self.logger.warning(f"Failed to test read_code_mem optimization: {e}")
10481065
return False

0 commit comments

Comments
 (0)