0Pricing
Claude Architect · บทเรียน

ต้องใช้ประวัติทั้งหมด

ทุกคำขอจะส่งบทสนทนาทั้งหมดไปด้วย

ต้องใช้ประวัติทั้งหมด เป็นบทเรียน Claude Architect ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Claude Architect และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Claude Architect มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

The Model Keeps No State

The most important fact about the Claude API: the model is stateless. It remembers nothing between requests. There is no hidden session on Anthropic's side holding your earlier turns.

Every time you call the API, you send the entire conversation history in the messages array. If a fact isn't in that array, the model simply doesn't know it — even if it told you the same fact thirty seconds ago.

For a Claude Certified Architect, internalizing this changes how you design every multi-turn system, agentic loop, and multi-agent handoff.

Anatomy of a Request

A Claude API request carries a fixed set of fields. The ones you'll touch on every turn:

  • model — which Claude model to call
  • max_tokens — output budget
  • system — the system prompt (instructions, persona, rules)
  • messages — the full conversation history as an array of role/content objects
  • tools and tool_choice — optional tool definitions and selection control

Notice what is NOT here: any kind of conversation ID or session token. State lives entirely in what you resend.

import anthropic

client = anthropic.Anthropic()

response = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=1024,
    system="You are a concise travel assistant.",
    messages=[
        {"role": "user", "content": "I want to visit Japan in spring."}
    ],
)

Building the History Array

To continue a conversation, you don't 'reply' to a session — you append the model's previous answer and the new user turn to the same messages list, then resend the whole thing.

The pattern: take last turn's messages, push the assistant's response, push the new user message, and call again. The array grows with every exchange.

messages = [
    {"role": "user", "content": "I want to visit Japan in spring."},
    {"role": "assistant", "content": "Great — cherry blossom season peaks in early April."},
    {"role": "user", "content": "What about the weather then?"},
]

response = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=1024,
    messages=messages,  # full history, every turn
)

What Happens If You Forget

Suppose you send only the latest user message — "What about the weather then?" — and drop the earlier turns. The model has no idea what 'then' refers to or that Japan was ever mentioned.

It will either ask for clarification or hallucinate a context. This is the single most common cause of 'the bot forgot what we were talking about' bugs. The fix is never a prompt trick — it's resending the full history.

Tool Results Are Part of History Too

History isn't just user and assistant text. When the model calls a tool, the conversation continues with structured turns:

  • an assistant turn containing a tool_use block
  • a user turn containing the matching tool_result

You must append the tool result back into messages and resend everything. The model only 'sees' the tool's output because it's now part of the history you carry forward.

messages.append({"role": "assistant", "content": response.content})  # has tool_use
messages.append({
    "role": "user",
    "content": [{
        "type": "tool_result",
        "tool_use_id": tool_use_id,
        "content": "Tokyo, April: ~15C, mild, occasional rain.",
    }],
})

response = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=1024,
    tools=tools,
    messages=messages,  # history now includes the tool_result
)

The Agentic Loop Carries History

This is why the agentic loop works the way it does. Each iteration: send the request, inspect stop_reason, and if it's tool_use, run the tools, append the results to history, and loop again — until stop_reason is end_turn.

The loop is fundamentally a history-accumulation loop. Terminate on the stop_reason, NEVER by scanning the text for words like 'done'. An iteration cap is a safety net, not the primary stop mechanism.

while True:
    response = client.messages.create(
        model="claude-sonnet-4-5", max_tokens=1024,
        tools=tools, messages=messages,
    )
    if response.stop_reason == "tool_use":
        messages.append({"role": "assistant", "content": response.content})
        messages.append({"role": "user", "content": run_tools(response)})
        continue  # resend the FULL grown history
    break  # end_turn -> done

Subagents Do NOT Inherit History

Here's the multi-agent trap. In a hub-and-spoke system, a coordinator delegates work to subagents via Task calls. But a subagent gets a fresh conversation — it does NOT inherit the coordinator's message history.

If the subagent needs the customer's ID, the order number, or any earlier finding, the coordinator must pass it explicitly inside the subagent's prompt. Assuming inheritance is a guaranteed failure: the subagent runs blind.

Passing Context Explicitly

Because state isn't shared, the coordinator's job includes packaging the right context into each delegation. Give the subagent exactly what it needs to act — no more (least privilege also applies to context).

Multiple Task calls in one response run in parallel, and each one is a self-contained brief. Treat every subagent prompt as a complete, standalone request.

subagent_prompt = f"""
You are researching flight options.
Context (you have no other history):
- Destination: Tokyo, Japan
- Travel window: early April 2026
- Origin: Istanbul (IST)
Return the 3 cheapest round-trip options with dates and prices.
"""
# Coordinator allowedTools must include "Task".
# Subagent starts with a blank message history -> context must be inline.

History Grows — and So Does Cost

Resending everything has a consequence: each turn re-tokenizes the entire history. Long conversations mean larger, slower, costlier requests, and eventually the context window fills up.

Architect-level reliability work is about managing that growth without losing fidelity:

  • Trim verbose tool output to only the relevant fields before appending.
  • Progressive summarization compresses old turns — but beware: it makes numbers, percentages, and dates vague.

Keep Transactional Facts Verbatim

The fix for vague summaries: pull hard facts — order IDs, amounts, dates, verified identities — into a separate 'case facts' block kept verbatim, outside the summary. Summarize the chatter, never the numbers.

Also mind lost-in-the-middle: models attend most to the start and end of the context. Put the most critical facts and the current instruction where they'll be seen, not buried in the middle of a long history.

messages = [
    {"role": "user", "content":
        "CASE FACTS (verbatim):\n"
        "- Order #A-4471, total $129.00, placed 2026-03-02\n"
        "- Customer verified: ID CUST-8830\n\n"
        "CONVERSATION SUMMARY:\n"
        "Customer reported a late delivery and requested options."
    },
    {"role": "user", "content": "Now: can you process a partial refund?"},
]

Sessions Resume — Tool Results May Be Stale

Claude Code persists history across sessions: --resume <name> continues a named session, and fork_session branches from a shared point. Convenient — but a caution worth remembering for the exam.

Resumed tool results can be stale if the codebase changed since they were captured. Carrying forward old history isn't always right; sometimes a fresh session seeded with a clean, structured summary beats replaying outdated context.

# Continue a prior named session (history reloaded)
claude --resume refactor-auth

# Branch from a shared point without polluting the original
# fork_session -> new line of exploration from the same base

Quick Check: The Forgetful Subagent

A scenario testing the core decision of this lesson.

Recap: Full History Is Required

Lock these in for the exam and for real systems:

  • The model is stateless; every request must carry the entire messages history.
  • Tool calls extend history — append each tool_result and resend everything.
  • The agentic loop is a history-accumulation loop; stop on stop_reason, not on parsed text.
  • Subagents do not inherit the coordinator's history — pass all context explicitly in each prompt.
  • History grows: trim verbose tool output, summarize old turns, but keep transactional facts verbatim and mind lost-in-the-middle.
  • Resumed sessions can carry stale tool results — sometimes a fresh session with a clean summary is better.

คำถามที่พบบ่อย

บทเรียน “ต้องใช้ประวัติทั้งหมด” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “ต้องใช้ประวัติทั้งหมด” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Claude Architect ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Claude Architect มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “ต้องใช้ประวัติทั้งหมด”

ทุกคำขอจะส่งบทสนทนาทั้งหมดไปด้วย คุณปฏิบัติ Claude Architect ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Claude Architect หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Claude Architect บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

บทเรียน “ต้องใช้ประวัติทั้งหมด” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Claude Architect นี้ได้ไหม

ได้ บทเรียน Claude Architect ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. ต้องใช้ประวัติทั้งหมด
  2. ความเสี่ยงของการสรุปแบบค่อยเป็นค่อยไป
  3. ผลกระทบจากข้อมูลที่หายไปตรงกลาง
  4. บล็อกข้อเท็จจริงของกรณีและการตัดผลลัพธ์
← กลับไปที่ Claude Architect