College AI Track

Module 6 of 12

Module 06: Introduction to AI Agents — Concepts, Architectures & Simple Agents with Tools

4 min read671 words
What you'll learn
Define an agent as a policy mapping state + perception → actions over time, often via tools.Contrast marketing “autonomy” with tool-using agents where your code enforces permissions.Explain ReAct-style traces vs function calling as two faces of one pattern.Implement a minimal loop with mock or live APIs and stop conditions.Identify runaway loops, injection via tool output, cost, unsafe side effects, integrity issues.Sketch guardrails: allowlists, human approval, logging, budgets, sandboxes.

"The model proposes; the runtime disposes." — Separation of LLM text from tool execution

At a Glance

Duration8–10 hours
DifficultyIntermediate (Python; JSON; optional APIs)
PrerequisitesPrompt design; basic function arguments

Learning Objectives

By the end of this module, you will be able to:

  1. Define an agent as a policy mapping state + perception → actions over time, often via tools.
  2. Contrast marketing “autonomy” with tool-using agents where your code enforces permissions.
  3. Explain ReAct-style traces vs function calling as two faces of one pattern.
  4. Implement a minimal loop with mock or live APIs and stop conditions.
  5. Identify runaway loops, injection via tool output, cost, unsafe side effects, integrity issues.
  6. Sketch guardrails: allowlists, human approval, logging, budgets, sandboxes.

Concept Section 1 — From Chatbot to Agent

Loop: Observe (user + tool results) → Decide (reply or tool call) → Act (your code runs tool) → Observe → Stop on answer, max steps, or budget.

Single-shot vs agentic

Single-shotAgent loop
StepsOne callMany
FailureIncompleteLoops, misuse, cost
DebugEasierNeeds traces

Concept Section 2 — Autonomous vs tool-using

NarrativeEngineering default
“AI browses freely”Allowlisted domains or local files
“AI sends email”Draft-only until human sends
“AI runs shell”No (except isolated honors labs)

Concept Section 3 — ReAct, function calling, planners

PatternModel emitsYour code does
ReAct (text)Thought / Action linesParse (fragile)
Function callingJSON tool callDispatch + validate schema
PlannerPlan then subcallsMore checks

Course stance: Draw the loop on a whiteboard before adopting LangChain-sized abstractions.

Concept Section 4 — Safety, cost, integrity

ControlPurpose
max_iterationsStop ping-pong
Token budgetCap cost
Tool allowlistNo arbitrary URLs
Human approvalWrites / sends / money
Structured logsDebug + review

Agents that complete graded work from hidden sources usually violate syllabi—design for tutor / quiz / cite, not substitution.

Agent loop vs scripted pipeline

PipelineAgent
FlowFixedModel branches
CostPredictableVariable
DebugStack tracesPrompt + tool traces

Hands-On Example — Pedagogical Python Loop (Stub Model)

Key Example: Replace fake_model_plan with a real chat.completions call that returns tool_calls; feed tool results back per provider docs.

python
[object Object], json
,[object Object], typing ,[object Object], ,[object Object],

,[object Object], ,[object Object],(,[object Object],) -> ,[object Object],[,[object Object],, ,[object Object],]:
    hours = {
        ,[object Object],: {,[object Object],: ,[object Object],, ,[object Object],: ,[object Object],},
        ,[object Object],: {,[object Object],: ,[object Object],, ,[object Object],: ,[object Object],},
    }
    ,[object Object], hours.get(building.lower(), {,[object Object],: ,[object Object],})

,[object Object], ,[object Object],(,[object Object],) -> ,[object Object],:
    ,[object Object], name == ,[object Object],:
        ,[object Object], get_campus_building_hours(**arguments)
    ,[object Object], ValueError(,[object Object],)

,[object Object], ,[object Object],(,[object Object],) -> ,[object Object],[,[object Object],, ,[object Object],]:
    ,[object Object], ,[object Object], ,[object Object], user_text.lower():
        ,[object Object], {
            ,[object Object],: ,[object Object],,
            ,[object Object],: ,[object Object],,
            ,[object Object],: {,[object Object],: ,[object Object],},
        }
    ,[object Object], {,[object Object],: ,[object Object],, ,[object Object],: ,[object Object],}

,[object Object], ,[object Object],(,[object Object],) -> ,[object Object],:
    plan = fake_model_plan(user_text)
    ,[object Object], plan[,[object Object],] == ,[object Object],:
        ,[object Object], plan[,[object Object],]
    result = run_tool(plan[,[object Object],], plan[,[object Object],])
    ,[object Object], ,[object Object],

,[object Object],(demo_loop(,[object Object],))

Narrative extensions: Wrap with MAX_STEPS and an explicit timeout string; treat tool output as untrusted (never promote to system content blindly); estimate token cost as steps × average tokens × price for back-of-envelope budgets.

Try This! Feed a tool result containing “ignore previous instructions…” and verify your app isolates or blocks it.

Fun Fact: LangChain/LangGraph speed prototypes but add API surface—pin versions and print traces in class.

Try This Now

  1. State diagram for a sandboxed research agent with human gates.
  2. List 10 allowlisted vs 10 denied tools with one-line risks.
  3. 250 words: LangChain vs raw SDK for your capstone—pick one.

Practice Exercises

State-machine diagram; allow/deny tool list with safe substitutes; injection policy paragraph; token cost estimate; ReAct abstract bullets (empirical vs aspirational).

Mini-Project

Bounded campus info agent: Local JSON/YAML ground truth; ≥3 tools; no general web browse; tests for routing and errors; README threat model. Stub loop OK if APIs disallowed.

Key Takeaways

  • Agents = policies around models; governance lives in tools.
  • Prefer structured calls over free-form shell from the model.
  • Start narrow, logged, human-in-the-loop for real side effects.

Key Takeaway

  • Structured tool calls beat parsing fragile “Thought:” text for student projects.
  • Cap iterations, cost, and tool surface before you cap “intelligence.”
  • Tool output is untrusted—mind prompt-injection from retrieved or external text.
  • Frameworks accelerate prototypes; threat modeling is still your job.
  • Academic integrity constraints are features of good agent design, not annoyances.

Resources

  • Yao et al., ReAct · Vendor function-calling guides (version-aware)
  • OWASP LLM Top 10 — injection, insecure output handling
  • Russell & Norvig — agent vocabulary (PEAS)

Align live API labs with campus key policy; prefer mocks for exams.