Python
Simple Python from zero: names, lists, functions, files, JSON, errors, tests, and the loop every agent uses.
- 0118 min
Why Python for Agents
What Python is, why agents are built in it, how print and comments work, and how to run code on this site from zero.
- 0218 min
Variables and Names
Assignment gives a value a name. Learn naming rules, snake_case, rebinding, and the names every agent loop uses.
- 0318 min
Types: Numbers, Text, True/False, and None
Every value has a type. Learn int, float, str, bool, and None, how to convert, and why bool('False') is True.
- 0418 min
Compare and Combine Values
Use ==, !=, <, in, is, and, or, not. Know same value versus same object, short-circuit, and beginner traps.
- 0520 min
Strings (Text)
Make, slice, and clean text with concat, split, join, strip, and replace — the work of prompts and tool names.
- 0618 min
Numbers and Math
Integers, floats, division, rounding, remainders, and how agents count steps, tokens, and cost without lying.
- 0718 min
True, False, and None
Truth tests, empty values, None vs 0 vs empty text, and why if result can lie when result is 0 or a blank string.
- 0818 min
Lists
A list is a row of values you can change. Index, slice, append, pop, and keep an agent's step memory without losing order.
- 0918 min
Index and Slice
Count from 0. A slice is a piece of a list or a string. Off-by-one errors break chunks of text and log windows.
- 1017 min
Tuples and Sets
A tuple is a pair you should not change. A set holds unique names, like allowed tools. Empty set is set(), not {}.
- 1120 min
Dictionaries
A dict maps a key to a value. Learn [], .get, in, items, nested args, and why this is how JSON and tool calls look.
- 1221 min
Nested Data (Traces)
Walk traces as dicts of lists of dicts. Change one field. Chain .get so missing keys do not crash an agent loop.
- 1320 min
If, Elif, and Else
Branch with if, elif, and else. Return early. Guard unknown tools, empty text, and errors before the happy path.
- 1420 min
Match and Case
match picks the first shape that fits. Route a tool dict with case. Keep if for simple yes/no tests.
- 1520 min
Loops and Budgets
for and while repeat work. enumerate, zip, break, continue, any/all, and a hard step budget so the loop cannot run forever.
- 1620 min
Functions
Define a function with def, return a value, write a docstring, pass keyword arguments, and store tools in a dict.
- 1719 min
Scope, Defaults, and Extra Arguments
Local vs global names, default arguments, *args and **kwargs, and why a list default leaks agent memory.
- 1820 min
Unpacking
Split a pair into names, peel the rest of a list, merge dicts with **, and unpack a tool result without losing defaults.
- 1918 min
Modules
Import a file of code, rename it with as, pull one name with from, and only run a main block when this file is the program.
- 2021 min
JSON and Text
Round-trip Python data with dumps and loads. Know what JSON allows, fake a file with a string, and split a CSV line.
- 2119 min
with, Files, and Paths
with always closes. pathlib Path names a file. utf-8 turns text into bytes. This is how read and write tools work.
- 2221 min
Errors and try/except
Catch specific errors, clean up with finally, and turn tool failures into dicts the agent loop can read.
- 2320 min
Copy vs Change in Place
Lists and dicts change in place. Copy when you must not share. Never give two agents one transcript list.
- 2420 min
Comprehensions
Build lists, dicts, and sets in one expression. Filter a trace of dicts. Use a for-loop when the body is more than one step.
- 2521 min
Classes
Make a class with __init__, self, and methods. Build a tiny Agent with goal, step, and run. Know when a function is enough.
- 2620 min
Dataclasses
Use dataclass to hold data. Freeze a ToolCall snapshot. Set list defaults with field(default_factory=list). Compare with a plain dict.
- 2720 min
Type Hints
Write list[str], dict[str, int], and X | None. Hints help you and your editor. They do not stop bad JSON at runtime.
- 2820 min
Useful Standard Library
Use datetime, Counter, defaultdict, islice, sha256, uuid, and copy. Know that time.sleep blocks the whole program.
- 2919 min
Regular Expressions
Use re.search, findall, and groups. Pull a URL or a small blob from messy model text. Prefer json.loads when you already have JSON.
- 3018 min
Logging and Secrets
Log with a list of dicts and levels. Read env vars with os.environ.get. Never print API keys. Redact them with ***.
- 3117 min
Virtual Envs and pip
A virtual env is a private folder of packages. Learn pip, pinned requirements.txt, and why Joeven’s browser has no pip.
- 3220 min
HTTP and APIs
You ask a server, it answers. Learn methods, status codes, JSON bodies, headers, and timeouts — with fake functions, no network.
- 3320 min
Parse JSON from a Model
Models wrap JSON in markdown fences and chat. Strip the fence, parse with json.loads, return an error dict, and never eval().
- 3419 min
Retries and Timeouts
Retry timeouts and 429. Do not retry 400 or 401. Cap tries, print backoff waits, and open a circuit after too many fails.
- 3518 min
Async in Simple Words
Async means wait for many tools at once. Simulate concurrent jobs with a queue and an in-flight limit. Skip event-loop internals.
- 3619 min
Tests
Use assert to test a tool, goal_satisfied, and parse_action. lambda is a tiny check. A runner counts pass and fail.
- 3722 min
A Mini Agent in Python
Put it together: a TOOLS dict, JSON parse, a budgeted loop, a transcript, a finish tool, a fake model, and a printed trace.