MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / execute_pattern_chain

Function execute_pattern_chain

scripts/python_ui/streamlit.py:1142–1226  ·  view source on GitHub ↗

Execute a sequence of patterns in a chain, passing output from each to the next. Args: patterns_sequence: List of pattern names to execute in sequence initial_input: Initial input text to start the chain Returns: Dict containing results from each stage of the chain

(patterns_sequence: List[str], initial_input: str)

Source from the content-addressed store, hash-verified

1140
1141
1142def execute_pattern_chain(patterns_sequence: List[str], initial_input: str) -> Dict:
1143 """Execute a sequence of patterns in a chain, passing output from each to the next.
1144
1145 Args:
1146 patterns_sequence: List of pattern names to execute in sequence
1147 initial_input: Initial input text to start the chain
1148
1149 Returns:
1150 Dict containing results from each stage of the chain
1151 """
1152 logger.info(
1153 f"Starting pattern chain execution with {len(patterns_sequence)} patterns"
1154 )
1155 chain_results = {
1156 "sequence": patterns_sequence,
1157 "stages": [],
1158 "final_output": None,
1159 "metadata": {
1160 "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
1161 "success": False,
1162 },
1163 }
1164
1165 current_input = initial_input
1166
1167 try:
1168 for i, pattern in enumerate(patterns_sequence, 1):
1169 logger.info(f"Chain Stage {i}: Executing pattern '{pattern}'")
1170 stage_result = {
1171 "pattern": pattern,
1172 "input": current_input,
1173 "output": None,
1174 "success": False,
1175 "error": None,
1176 }
1177
1178 try:
1179 cmd = ["fabric", "--pattern", pattern]
1180 result = run(
1181 cmd, input=current_input, capture_output=True, text=True, check=True
1182 )
1183 output = result.stdout.strip()
1184
1185 if output:
1186 stage_result["output"] = output
1187 stage_result["success"] = True
1188 current_input = output # Use this output as input for next pattern
1189 logger.debug(f"Stage {i} completed successfully")
1190 else:
1191 stage_result["error"] = "Pattern generated no output"
1192 logger.warning(f"Pattern {pattern} generated no output")
1193
1194 except CalledProcessError as e:
1195 error_msg = f"Error executing pattern: {e.stderr.strip()}"
1196 stage_result["error"] = error_msg
1197 logger.error(error_msg)
1198 break
1199

Callers 1

mainFunction · 0.85

Calls 2

runFunction · 0.85
save_output_logFunction · 0.85

Tested by

no test coverage detected