Level 1.5 · Agents · Session 2 of 3

Powering the agent

Tools it can call · prompts that steer it · memory that lasts — then wire it up.

Covers: Stations 4–6  ·  You'll need: the Session 2 Colab notebook + your Gemini key from Session 1

The shape of today

Three upgrades → build

Three ideas, one build
  • Tools & actions — what a tool really is and how to define a good one
  • Prompting your agent — the system prompt is its job description
  • Memory — short-term vs long-term, then you wire both in Colab
4
Idea 1

Tools & actions

Concept · What a tool is

A function the model can call

  • A tool is just a function you write — code the agent is allowed to run.
  • The model decides WHEN to call it; your code decides WHAT it does.
  • The LLM never runs your code itself — it asks, you run it, you hand back the result.
🔧 Analogy

The model is a smart manager who can't touch the machines. It says "run the calculator with 12 × 9" — you flip the switch and report back what came out.

Concept · Anatomy of a good tool

Name it, describe it, guard it

The 4 parts

What makes it usable

Clear name · a plain-English description · typed inputs/outputs · sane error handling.

Why it matters

The model reads this

The description IS the instruction manual. Vague docs → wrong calls. Good docs → the model picks the right tool.

def get_weather(city: str) -> dict:
    """Get today's weather for a city.
    Args: city — full city name, e.g. "Austin".
    Returns: {temp_f, summary}. Raises if city unknown."""
    if not city:
        raise ValueError("city is required")   # guard the input
    return weather_api.lookup(city)
Concept · The toolbox

Tools agents actually use

Reach out

🔎 Web search

Fetch today's facts the model was never trained on.

Compute

🧮 Run code

Do exact math or data work instead of guessing.

Remember

🗄️ Database

Read and write real records — users, orders, notes.

Connect

🔌 APIs

Send email, book calendars, hit any web service.

🔑 The pattern

Give an agent the right files, search, code, and APIs and almost any task becomes "pick a tool, call it, check the result."

5
Idea 2

Prompting your agent

Concept · The system prompt

The agent's job description

  • Who it is — its role and tone ("You are a helpful research assistant").
  • What tools it has — and when to reach for each one.
  • Its rules — what to always do, what to never do, how to handle 'I don't know'.
Where it lives

Set once as the system_instruction — it rides along on every loop, steering each decision the agent makes.

Concept · Prompting habits

Vague in → vague out

Vague

"Help the user"

No role, no rules, no examples. The model fills the gaps — and it fills them differently every time.

Specific

"You are a calendar agent. Use book() only after confirming the time. If unsure, ask."

Role, tool, rule. Predictable behavior.

🔑 Three habits

Be specific (say exactly what you want) · give examples (show one good answer) · iterate (test, watch it fail, tighten the words).

⚡ Energizer · 10–12 min · on your feet

The Exact Instructions Challenge

  • One student writes step-by-step instructions for a simple task (draw a face, make a sandwich).
  • A partner does only what's written — literally, no guessing, no common sense.
Printable card in Coach HQ → Session 2 energizer
6
Idea 3

Agent memory

Concept · Two kinds of memory

Short-term vs. long-term

Short-term

The context window

Everything in the current chat — the running history. Fast, but limited and it resets.

Long-term

A vector database

Notes saved outside the chat. The agent searches it and pulls back only what's relevant.

⚠️ Why it matters

The context window fills up — and when the chat resets, short-term memory is gone. Long-term memory is how an agent remembers you across sessions.

Build it

Power it up in Colab

Build · function calling + memory

Declare a tool, recall a memory

# 1 — give the agent a role AND a tool
config = types.GenerateContentConfig(
    system_instruction="You are a study buddy. "
        "Use remember() to look things up before answering.",
    tools=[remember],                 # function calling
)

# 2 — long-term memory: search, don't dump
def remember(query: str) -> str:
    hits = memory_db.search(query, top_k=3)
    return "\n".join(hits)      # only the 3 most relevant notes

resp = client.models.generate_content(
    model="gemini-2.5-flash", config=config, contents=history)
Goal in the notebook

Tell it a fact ("my quiz is Friday"), start a fresh chat, then ask "when's my quiz?" — watch it call remember instead of shrugging.

Session 2 · Wrap

Your agent leveled up 🎉

  • Tools = functions the model calls — it decides when, your code decides what.
  • The system prompt is the job description; be specific, show examples, iterate.
  • Memory: short-term (context window) vs long-term (searchable vector DB).

Next session → Agents in the real world: architectures, building your own, and keeping them safe.

LearnAI · Level 1.5 · Session 2 — Powering the Agent · press S for coach notes