Lesson 51.1 · 1 of 6 · 4 min read · Reviewed 24 Nov 2026
What a framework gives you, and what it hides
By the end, you can
- Explain what agent frameworks provide.
- Spot what they hide from you.
What you get
| Feature | Saves you from writing |
|---|---|
| Agent loop | Call, check stop reason, run tools, repeat |
| Tool plumbing | Schemas, dispatch, error wrapping |
| State and checkpoints | Saving and resuming runs |
| Memory helpers | Summaries, vector stores |
| Multi-agent patterns | Supervisors, handoffs, group chats |
| Tracing integrations | Hooking into observability tools |
What can be hidden
- The actual prompt after the framework adds its own instructions.
- Extra model calls for planning, summarising or routingRouting: A workflow pattern that classifies an input and sends it to a specialised prompt, model or handler..
- History handling, such as how much is re-sent each step.
- Retries that multiply cost on errors.
Anthropic’s agentAgent: A system where a model decides its own next steps, calling tools in a loop until the task is done. guidance suggests starting with the API directly, and if you use a framework, making sure you understand the code underneath.
Questions to ask of any framework
- Can I see every request and response?
- Can I control the system promptSystem prompt: Instructions passed in the top-level system field that set the model’s role, rules and context for the whole conversation. fully?
- How does it manage history and context size?
- Does it support the model features I need (caching, thinking, structured outputsStructured outputs: Making a model return data that matches a defined schema, such as JSON with required fields and types.)?
- How hard is it to leave if it stops fitting?
Key points
- Frameworks give you a loop, tool plumbing, state, memory helpers, tracing and multi-agent patterns.
- They save time but can hide the prompts, the message history and the exact calls being made.
- Hidden behaviour makes debugging and cost control harder.
- Whatever you use, make sure you can see the final prompt and every model call.
Expose what a framework hides
Wrap a model client with a tracer and find the extra instructions, calls and retries a framework adds.
You will have: A tracing client and a printed list of every call the framework made, with token counts.
Steps
- Run the starter: the run finishes but you see nothing about its calls.
- Make TracingClient record each call's purpose and input tokens.
- Record failed calls too, then re-raise so the framework behaves as before.
- Read the trace: count the planning call, the retry and the memory summary you never asked for.
- Remove FRAMEWORK_RULES and see how much of the cost was hidden instructions.
Done when
- The trace shows 4 calls for a task you expected to take 1.
- The failed attempt appears as an error, followed by the silent retry.
- Total input tokens are many times the direct call.
Open in the Playground No API key needed.
Starter code (Python)
# A toy framework hides extra calls. Wrap the client with a tracer to see every call it makes.
class FakeClient:
"""Simulated model client. The second call fails once, like a brief network error."""
def __init__(self):
self.n = 0
def create(self, system, messages, purpose):
self.n += 1
if self.n == 2:
raise TimeoutError("simulated timeout")
tokens = len((system + " ".join(messages)).split())
return {"text": f"reply {self.n}", "input_tokens": tokens}
FRAMEWORK_RULES = "You are a helpful agent. Think in steps. Always plan before acting. " * 20
class TinyFramework:
def __init__(self, client):
self.client = client
def run(self, system, task):
sys_full = FRAMEWORK_RULES + system # its own instructions, added silently
plan = self.client.create(sys_full, [task], "plan")
for attempt in range(3): # silent retries
try:
ans = self.client.create(sys_full, [task, plan["text"]], "answer")
break
except TimeoutError:
continue
self.client.create(sys_full, [task, ans["text"]], "summarise memory")
return ans["text"]
class TracingClient:
def __init__(self, inner):
self.inner, self.calls = inner, []
def create(self, system, messages, purpose):
# TODO: call the inner client; record (purpose, input_tokens or "error"); re-raise errors after recording
return self.inner.create(system, messages, purpose)
SYSTEM, TASK = "Answer billing questions.", "Why was I charged twice this month?"
direct = len((SYSTEM + " " + TASK).split())
tracer = TracingClient(FakeClient())
TinyFramework(tracer).run(SYSTEM, TASK)
total = sum(t for _, t in tracer.calls if isinstance(t, int))
print(f"calls made: {len(tracer.calls)}")
for purpose, t in tracer.calls:
print(f" {purpose}: {t}")
print(f"input tokens: {total}, about {total // max(direct, 1)}x the direct call ({direct})")
Show a solution
# A toy framework hides extra calls. Wrap the client with a tracer to see every call it makes.
class FakeClient:
"""Simulated model client. The second call fails once, like a brief network error."""
def __init__(self):
self.n = 0
def create(self, system, messages, purpose):
self.n += 1
if self.n == 2:
raise TimeoutError("simulated timeout")
tokens = len((system + " ".join(messages)).split())
return {"text": f"reply {self.n}", "input_tokens": tokens}
FRAMEWORK_RULES = "You are a helpful agent. Think in steps. Always plan before acting. " * 20
class TinyFramework:
def __init__(self, client):
self.client = client
def run(self, system, task):
sys_full = FRAMEWORK_RULES + system # its own instructions, added silently
plan = self.client.create(sys_full, [task], "plan")
for attempt in range(3): # silent retries
try:
ans = self.client.create(sys_full, [task, plan["text"]], "answer")
break
except TimeoutError:
continue
self.client.create(sys_full, [task, ans["text"]], "summarise memory")
return ans["text"]
class TracingClient:
def __init__(self, inner):
self.inner, self.calls = inner, []
def create(self, system, messages, purpose):
try:
r = self.inner.create(system, messages, purpose)
except Exception as err:
self.calls.append((purpose, f"error: {err}"))
raise
self.calls.append((purpose, r["input_tokens"]))
return r
SYSTEM, TASK = "Answer billing questions.", "Why was I charged twice this month?"
direct = len((SYSTEM + " " + TASK).split())
tracer = TracingClient(FakeClient())
TinyFramework(tracer).run(SYSTEM, TASK)
total = sum(t for _, t in tracer.calls if isinstance(t, int))
print(f"calls made: {len(tracer.calls)}")
for purpose, t in tracer.calls:
print(f" {purpose}: {t}")
print(f"input tokens: {total}, about {total // max(direct, 1)}x the direct call ({direct})")