|
@@ -0,0 +1,43 @@
|
|
|
+import re
|
|
|
+
|
|
|
+def extract_agent_run_steps(log_path):
|
|
|
+ pattern = re.compile(
|
|
|
+ r'^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3} - agent run\[\d+\] - DEBUG - current step content:'
|
|
|
+ )
|
|
|
+ timestamp_pattern = re.compile(r'^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3} - ')
|
|
|
+ results = []
|
|
|
+ current = []
|
|
|
+ collecting = False
|
|
|
+
|
|
|
+ with open(log_path, 'r', encoding='utf-8') as f:
|
|
|
+ for line in f:
|
|
|
+ if pattern.match(line):
|
|
|
+ if collecting and current:
|
|
|
+ results.append(''.join(current).rstrip())
|
|
|
+ current = []
|
|
|
+ collecting = True
|
|
|
+ current.append(line)
|
|
|
+ elif collecting:
|
|
|
+ if timestamp_pattern.match(line):
|
|
|
+ results.append(''.join(current).rstrip())
|
|
|
+ current = []
|
|
|
+ collecting = False
|
|
|
+ else:
|
|
|
+ current.append(line)
|
|
|
+ # 文件结尾处理
|
|
|
+ if collecting and current:
|
|
|
+ results.append(''.join(current).rstrip())
|
|
|
+ return results
|
|
|
+
|
|
|
+if __name__ == "__main__":
|
|
|
+ import sys
|
|
|
+ if len(sys.argv) != 2:
|
|
|
+ print("Usage: python extract_agent_run_step.py <logfile>")
|
|
|
+ sys.exit(1)
|
|
|
+ log_file = sys.argv[1]
|
|
|
+ steps = extract_agent_run_steps(log_file)
|
|
|
+ for i, step in enumerate(steps, 1):
|
|
|
+ print(f"--- Step {i} ---")
|
|
|
+ print(step)
|
|
|
+ print()
|
|
|
+
|