Skip to content

Commit 9c7141b

Browse files
HQideastainless-app[bot]
authored andcommitted
fix(examples/memory): properly add assistant_content to messages (#1049)
1 parent b61fd87 commit 9c7141b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

examples/memory/basic.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ def conversation_loop():
335335
raise
336336

337337
# Process all messages from the runner
338-
assistant_content: list[BetaContentBlockParam] = []
339338
for message in runner:
340339
spinner.stop()
341340

@@ -351,6 +350,7 @@ def conversation_loop():
351350
print(f"\n🧹 [Context Management: {edit.type} applied]")
352351

353352
# Process content blocks
353+
assistant_content: list[BetaContentBlockParam] = []
354354
for content in message.content:
355355
if content.type == "text":
356356
print(content.text, end="", flush=True)
@@ -371,6 +371,10 @@ def conversation_loop():
371371
}
372372
)
373373

374+
# Store assistant message
375+
if assistant_content:
376+
messages.append({"role": "assistant", "content": assistant_content})
377+
374378
# Generate tool response automatically
375379
tool_response = runner.generate_tool_call_response()
376380
if tool_response and tool_response["content"]:
@@ -381,10 +385,6 @@ def conversation_loop():
381385
if isinstance(result, dict) and result.get("type") == "tool_result":
382386
print(f"[Tool result processed]")
383387

384-
# Store assistant message
385-
if assistant_content:
386-
messages.append({"role": "assistant", "content": assistant_content})
387-
388388
print()
389389

390390

0 commit comments

Comments
 (0)