</>

Advanced Programming for Data Scientists

Vibe Coding &
Agents Building

Coding with AI, and building AI that acts.

Nir Naim · Tel Aviv University · 3-hour session

Roadmap

Where we're going today

Before we start · the basics

First, the big picture

What this “AI” actually is — and what “vibe coding” even means.

The tool under the hood

What is a large language model?

Think “autocomplete that read the whole library,” not “a mind that knows facts.”

Why it works for us

Why it's so good at code

📐 Code is the most patterned text there is

  • Strict syntax
  • Repeated idioms
  • Millions of public examples

✨ So it can go from plain English → working code

  • “Sort this list” → real Python
  • Fills in the boilerplate
  • Astonishingly often — on the first try

Read this twice

The catch: confident ≠ correct

Your job: stay the engineer who decides what's actually correct.

The name for it

So what is “vibe coding”?

You describe what you want in plain language → the AI writes the code → you run, review & steer. You focus on the intent and the outcome, not on typing every character.

Term coined by Andrej Karpathy, early 2025 — now how a lot of real software gets built.

What changes for you

The shift in your job

⌨️ Old way

  • Type every line yourself
  • Memorize syntax & APIs
  • Speed = how fast you type

🧭 Vibe coding

  • Describe the intent
  • Review & verify the output
  • Speed = how well you steer

You're still the engineer — now the pilot, not the typist.

Before class

You already set up your machine ✅

GitHub Student Pack (with your @mail.tau.ac.il email) → Copilot Pro → VS Code → the Copilot extension. If not — do it now, it's on the course site.

02

Vibe Coding

Ask → visualize → test → fix → iterate.

Warm-up ispow2(n)

Give the AI the constraints, not just the goal

sol1.py
# no bin / len / logs / strings — bit ops only. 0 is NOT a power of two.
def ispow2(n):
    return n > 0 and (n & (n - 1)) == 0

Tell it the forbidden built-ins up front — or it reaches for bin().

The mental model

The vibe-coding loop

Ask Visualize Test Refactor safely Iterate

You stay the engineer. The AI is a very fast, very literal pair-programmer.

Demo longest_run(n)

Watch the loop on a real question

longest_run(n) → length of the longest run of consecutive 1 bits.

▶ Live now longest_run

🎬 Switch to VS Code

Full walkthrough, live — ask, visualize, test, fix, iterate.

The takeaway

Passing tests ≠ acceptable solution

🎯 Constraints first

The AI happily breaks the rules unless you state them. bin() worked — but was forbidden.

🧪 Tests = freedom

Once you have tests, you can let the AI rewrite the code and know instantly if it broke.

Before your turn

How to talk to the AI

Your turn

reverse_bits(x, num_bits) — 30 min

Reverse the low num_bits bits of x. Same loop: ask (with constraints) → visualize → test → fix → improve.

Timer + visualizer are on the course site → In Class.

03

Building AI Agents

with PydanticAI

The core idea

A single answer vs. an agent that acts

🗨️ One LLM request

  • Only its training data
  • No live info, no your data
  • Can't verify itself
  • One shot
vs

🤖 Agent + tools

  • Fetches real info via tools
  • Grounds in your sources
  • Retries, loops, checks
  • Structured output

What makes it an agent

Reason → act → observe → repeat

Prompt
LLMdecide
Call toolsearch, run…
Read result
Answerstructured

Remove the loop and the tools → you're back to one chat message.

What is a tool?

A normal typed function the model can call

tool
@agent.tool_plain
def word_count(text: str) -> int:
    """Return the number of words in the given text."""
    return len(text.split())

The docstring is the tool's instruction manual for the model.

Why bother

Tools + a loop beat better prompting

An LLM alone is a brilliant intern with no phone, no internet, no notebook. Tools give it the phone and the notebook.

SWE-benchGAIAτ-bench

On "doing" tasks, tool-using agents complete far more than single prompts.

Your stack = 3 choices

Framework · Model · Harness

🧱 Framework

PydanticAI, LangGraph, LlamaIndex…
We use PydanticAI.

🧠 Model

Gemini, Claude, GPT, Llama…
Swappable in one line. Gateway = API / OpenRouter / Ollama.

🛠️ Harness

Tools · observability · tests · guardrails.
Where the real work is.

Model & framework are easy swaps. The harness is what makes an agent good.

The point

The harness is the agent

Tools Observability Tests & evals Guardrails Memory

Same model, same framework — a strong harness is the difference between a demo and something you'd ship.

Architectures · first cut

Workflow vs. agent

🧭 Workflow

  • You wire the steps in code
  • Path is predefined
  • Predictable, cheap, debuggable
vs

🤖 Agent

  • The model decides next step
  • Path emerges at runtime
  • Flexible — but slower & pricier

Same brick underneath: the augmented LLM (model + tools + memory).

Architectures · the ladder simple → complex

Six patterns you compose

Scaling up · & the one rule

Topologies — and start simple

Hierarchical

Supervisors of workers. High control, big tasks.

Swarm

Peers, no boss. Exploration at scale.

Mesh

3–8 peers, tight loops on one artifact.

Rule: every layer adds cost, latency & failure points. Use the fewest pieces that solve it.

Tools at scale

MCP — “USB-C for AI tools”

One open standard. Plug your agent into ready-made servers — GitHub, Slack, databases, filesystem, browser — and it gains all their tools at once.

Write onceReuse across modelsClient & server

No credit card needed

Free tokens — and a cap so the loop can't run away

Because agents loop, always cap the number of requests.

▶ Live first_agent.py

One tool · free model · structured output · capped

first_agent.py
class Answer(BaseModel):
    result: int

agent = Agent("google-gla:gemini-2.0-flash", output_type=Answer)

@agent.tool_plain
def add(a: int, b: int) -> int:
    """Add two integers."""
    return a + b

out = agent.run_sync("What is 21 + 21? Use the add tool.",
                     usage_limits=UsageLimits(request_limit=5))
print(out.output.result)   # -> 42

Assume it misbehaves

Failure modes → guardrails

At home · workshop

Build a research assistant agent

Skeleton Simple tool Real tool Parallel + merge Observe Eval

Fan out with asyncio.gather, fan in with a synthesizer — then trace it and eval it. Full guide on the site.

Recap

Ask · Visualize · Test
Fix · Iterate

The same loop — from a bit trick to a parallel agent pipeline.

Nir Naim · Course site has everything: prep · demo · challenge · workshop

Bonus · optional

Under the hood: the Transformer

A quick, high-level peek at the architecture behind every modern LLM.

The architecture

One design powers the whole field

Remember the opener: a next-word predictor. This is the engine that does the predicting.

Step 1 text → numbers

First, words become numbers

🧩 Tokens

  • Text is chopped into small chunks
  • A “token” ≈ a word or a piece of one
  • vibe coding["vibe", " cod", "ing"]

🔢 Embeddings

  • Each token → a vector (a list of numbers)
  • The vector captures its meaning
  • Similar meanings land near each other

Step 2 · the key idea

Attention — every word reads the others

Each token looks at every other token and decides which ones matter for what comes next.

“river bank

bank pays attention to river → water's edge.

“savings bank

bank pays attention to savings → money.

Same word — context resolves the meaning. That's the breakthrough.

Step 3 stack it up · predict

Stack the layers, predict the next token

Tokens
Embed
Attention× dozens of layers
Next-tokenprobabilities
Pick one
Append & repeat

Trained on trillions of words. At runtime it predicts one token, adds it, and predicts again — “autoregressive.”

Why it mattered

Why the Transformer changed everything

⚡ Parallel

  • Reads all tokens at once
  • Older models plodded word-by-word
  • So it trains on huge GPU clusters

📈 It scales

  • More data + more compute →
  • predictably better models
  • This “scaling” gave us today's LLMs

You don't need the math to use it well — but now you've seen what's inside the box.

← → to navigate · F fullscreen · press any key
1 / 1