You have ten facts the agent should know. How do you hand them to the model so it can reference fact three without confusion?
Just comma-separate them? Or send them all as a blob paragraph? Neither feels stable.
Neither is. A numbered list with one fact per line gives each fact a stable index and makes the format trivial to parse on the way back. enumerate(start=1) does the numbering in one line:
facts = ["Sky is blue", "Grass is green"]
lines = [f"{i}. {f}" for i, f in enumerate(facts, start=1)]
print(chr(10).join(lines))So this is pure Python — no agent call, no await, just shaping a string that other memory functions will read?
Exactly. Context formatting is the scaffolding the rest of the week builds on. The whole function is three statements — enumerate, format, join:
def build_context_string(facts: list) -> str:
lines = [f"{i}. {f}" for i, f in enumerate(facts, start=1)]
return chr(10).join(lines)Why chr(10) instead of the newline escape? Is that a style thing?
Either works in Python. chr(10) is the integer 10 converted to its character — the newline — and it sidesteps any quirks when the string travels through tooling that double-escapes backslashes. The semantics are identical.
And the output is the exact format the model expects — one numbered fact per line, ready to drop into a system prompt or a user message?
Ready to inject. Numbered lists are a shape the model has seen millions of times in training — it reads them cleanly every call. That is the memory shape the rest of the week relies on.
TL;DR: enumerate(facts, start=1) plus newline join gives the agent a stable fact index.
enumerate(facts, start=1) — 1-based index alongside each itemf"{i}. {f}" — one line per fact with a visible numberchr(10).join(lines) — newline separator, any tooling-safe form| Shape | Pros |
|---|---|
| Bullets | readable, no index |
| Numbered | stable reference by number |
| Paragraph | unstructured, hard to parse |
Every memory function downstream reads this numbered shape.
You have ten facts the agent should know. How do you hand them to the model so it can reference fact three without confusion?
Just comma-separate them? Or send them all as a blob paragraph? Neither feels stable.
Neither is. A numbered list with one fact per line gives each fact a stable index and makes the format trivial to parse on the way back. enumerate(start=1) does the numbering in one line:
facts = ["Sky is blue", "Grass is green"]
lines = [f"{i}. {f}" for i, f in enumerate(facts, start=1)]
print(chr(10).join(lines))So this is pure Python — no agent call, no await, just shaping a string that other memory functions will read?
Exactly. Context formatting is the scaffolding the rest of the week builds on. The whole function is three statements — enumerate, format, join:
def build_context_string(facts: list) -> str:
lines = [f"{i}. {f}" for i, f in enumerate(facts, start=1)]
return chr(10).join(lines)Why chr(10) instead of the newline escape? Is that a style thing?
Either works in Python. chr(10) is the integer 10 converted to its character — the newline — and it sidesteps any quirks when the string travels through tooling that double-escapes backslashes. The semantics are identical.
And the output is the exact format the model expects — one numbered fact per line, ready to drop into a system prompt or a user message?
Ready to inject. Numbered lists are a shape the model has seen millions of times in training — it reads them cleanly every call. That is the memory shape the rest of the week relies on.
TL;DR: enumerate(facts, start=1) plus newline join gives the agent a stable fact index.
enumerate(facts, start=1) — 1-based index alongside each itemf"{i}. {f}" — one line per fact with a visible numberchr(10).join(lines) — newline separator, any tooling-safe form| Shape | Pros |
|---|---|
| Bullets | readable, no index |
| Numbered | stable reference by number |
| Paragraph | unstructured, hard to parse |
Every memory function downstream reads this numbered shape.
Create a free account to get started. Paid plans unlock all tracks.