How this course works
Read · 1 of 3
Real shapes, instant runs
Real models need the internet and an API key, and they answer a little differently every time. That's bad for learning: you want to run your code a hundred times and see exactly what changed.
So in the browser you'll use a stand-in model: a small Python class with exactly the shapes of the real Claude API. client.messages.create(...) returns a response with .content blocks and a .stop_reason, just like the real SDK.
In module 12 you swap in the real client on your computer. Because the shapes are the same, your agent keeps working.
The stand-in's code runs first in every program, folded away under Runs first so you see only what matters. Open it any time: it's 30 short lines.
Read this lesson as text
A stand-in model with the real API's shapes, so everything runs here and works with Claude later.
Real shapes, instant runs
Real models need the internet and an API key, and they answer a little differently every time. That's bad for learning: you want to run your code a hundred times and see exactly what changed.
So in the browser you'll use a stand-in model: a small Python class with exactly the shapes of the real Claude API. client.messages.create(...) returns a response with .content blocks and a .stop_reason, just like the real SDK.
In module 12 you swap in the real client on your computer. Because the shapes are the same, your agent keeps working.
The stand-in's code runs first in every program, folded away under Runs first so you see only what matters. Open it any time: it's 30 short lines.
One call to the stand-in
def brain(messages):
return Response(text("Hello! You said: " + messages[-1]["content"]))
client = Client(brain)
reply = client.messages.create(model="stand-in", max_tokens=200, messages=[{"role": "user", "content": "hi"}])
print(reply.stop_reason)
print(reply.content[0].text)- Line 1: A brain decides what the model says. This one just repeats your message back.
- Line 4: The client wraps the brain, like `anthropic.Anthropic()` wraps the real model.
- Line 5: One call: a list of messages in, a response out.
- Line 6: No tool was used, so the model is done: `end_turn`.
- Line 7: The reply's text lives in its first content block.
Done, or not done?
def brain(messages):
return Response(text("Let me check."), tool_use("call_1", "search", query="weather Pune"))
reply = Client(brain).messages.create(model="stand-in", max_tokens=200, messages=[{"role": "user", "content": "Rain today?"}])
print(reply.stop_reason, len(reply.content), reply.content[1].name)What does this print?
- tool_use 2 search
- end_turn 2 search
- tool_use 1 search
Show the answer
tool_use 2 search The reply has two blocks: some text, then a tool_use. Because it asked for a tool, stop_reason is tool_use: the model isn't done, it's waiting for your code to run the search.