def execute_python(code: str) -> str: img_code = f""" import matplotlib matplotlib.use('Agg') {code} # ← エージェントが生成したコード import matplotlib.pyplot as plt, base64, io, json as _json _imgs = [] for _i in plt.get_fignums(): # ← 開いている figure を全部拾う _b = io.BytesIO() plt.figure(_i).savefig(_b, format='png', bbox_inches='tight', dpi=100) _imgs.append({{'i': _i, 'd': base64.b64encode(_b.getvalue()).decode()}}) print('_IMG_' + _json.dumps(_imgs) + '_END_') """ with code_session(CODE_INTERPRETER_REGION) as client: resp = client.invoke("executeCode", {"code": img_code, ...}) # stdout の _IMG_..._END_ から画像を抽出 → S3 へ 07 — execute_python auto-inject capture