Module 4 - VLM, multimodal RAG, and agentic AI revision

Revision guide · ~50 min · dense bullets, not full lessons

Chapter 4.1 follows this path: Foundations → CLIP → LLaVA → Qwen-VL → SAM → Synthesis.

Foundations

CLIP

LLaVA

Qwen-VL

SAM

Synthesis

Need Start with
Tag / retrieve CLIP
Chat about image LLaVA
OCR + boxes + multi-image Qwen-VL
Pixel mask SAM
Grasp / rotoscope pipeline VLM + SAM

4.2 VLM applications

Application failure Planned control
Caption hallucination Visible-only prompt + negative examples
VQA false assumption Verify object exists
Guessed document field null + validation + human review
Compounding reasoning error Independent verifier
Tiny/thin segmentation miss Domain testing and prompt refinement

4.3 Multimodal RAG

Data Good starting point
Plain text Text or hybrid RAG
Products/photos CLIP-style image search
Reports/charts/forms Multimodal document RAG
High-stakes answers Retrieval + claim citations + validation

4.4 RAG to assistants and agents

Capability ladder

Stage What is added Travel example
LLM Language generation Writes a plausible itinerary
RAG External knowledge Retrieves company policy
Assistant Conversation context Remembers dates and budget
Tool-using assistant External capabilities Calls flight and hotel APIs
Agent Runtime decisions Replans after a failed policy check
Multi-agent Delegation Splits flights, hotels, meetings, expenses

Workflow vs agent

Agent loop

think → act → observe → remember → repeat

Agent patterns

Pattern Shape Good fit
ReAct Think, act, observe, repeat Short tasks driven by latest result
Plan-and-execute Plan first, execute, replan failures Long tasks and parallel substeps
Reflection Draft, critique, revise Reports, code, and final write-ups

Context cost grows because each model call often resends the goal, tools, and earlier history. Truncate observations, summarise old decisions, and keep structured task state outside the transcript.

Retrieval, state, and multiple agents

Framework rule

Choose by your technology stack and operational needs, not hype. Keep goals, tool policies, state, traces, approvals, and evaluation portable outside any one SDK.

4.5 Multi-agent systems

A team is not a bigger model. It is specialists plus a coordinator that owns the goal.

When to split

Several tools can still belong to one agent. Start with one loop.

Roles, contracts, handoffs

An agent = role + model + tools + state + contract.

If you cannot say "this agent owns X and returns Y," do not delegate yet.

Handoffs stay small: goal, constraints, expected format. Not the whole chat.

Coordination cycle

decompose → execute → attribute → reconcile (repeat)

Bound it with a round limit, a token budget, and a deadlock check. Escalate a repeated conflict instead of looping forever.

Search flights and hotels together when they do not need each other. Run budget and policy after a pair is chosen.

Supervisor, state, validation

Permissions, trust, logs

Work Rule
Search / policy / budget Automatic, read-only
Book / send Human confirms first

Treat another agent's text as untrusted data. Wrap it, check it, reject "ignore the budget," and still require approval for writes.

Log delegation, tool call, raw result, validation, latency/retries, and who approved the write.

Cost, eval, standards

One round of 4 specialists ≈ 8 model-facing messages plus their tool calls.

Score selection, arguments, task completion, groundedness, conflicts caught, rounds/cost. A fluent itinerary is not a pass.

Standard Connects
A2A Agent ↔ agent
MCP Agent ↔ tools and data
ANP Agents on the open web (proposed)
AGNTCY Directory, identity, messaging

Neither A2A nor MCP makes a booking safe.

Five rules

  1. Specialise only when it helps.
  2. Contract every agent.
  3. Coordinate in a bounded loop.
  4. Keep handoffs small and checked.
  5. Treat every extra agent as extra risk.

4.6 LangChain and LangGraph

The split

Core graph

state → nodes → edges, with a checkpointer saving every super-step.

Persistence and people

Multi-agent graphs

Production reliability

Problem Response
Temporary timeout / 503 Limited retry with backoff
No fare under cap Semantic result: replan or answer honestly
Expired credential Repair or escalate
Repeated booking Idempotency key + human approval
Hanging dependency Tool 5 s → node 30 s → run 90 s
Live source unavailable Label stale cache, ask user, or fail clearly
Endless replanning Attempt, deadline, and recursion limits

Trace the parent run and child nodes: latency, cost, retries, policy verdict, replanning, and approval. Middleware can add summarisation, approval, and call limits without rewriting the main loop.

Six rules

  1. LangChain standardises; LangGraph orchestrates.
  2. A graph is typed state, small nodes, and explicit edges.
  3. Chaining, routing, fan-out, and loops are edge patterns.
  4. Checkpoints give memory, resumption, approval, and time travel.
  5. Middleware adds reusable behaviour.
  6. Reliability determines whether the agent is deployable.

20-minute drill

  1. Walk through ViT patch count for 224×224 and 16×16 patches.
  2. Explain why LLaVA needs a projector even when dimensions match.
  3. Convert one normalized <box> to pixel coordinates for a given image size.
  4. Sketch a two-step pipeline: Qwen-VL finds box → SAM segments.
  5. Write a caption prompt with scope and length constraints.
  6. Write an invoice JSON schema that uses null for missing values.
  7. Compare BM25, dense, and hybrid search for an exact policy number.
  8. Sketch text query → page retrieval → VLM answer → page citation.
  9. Explain late interaction without using the formula.
  10. Diagnose separately: the right page was retrieved, but the answer invented a number.
  11. Explain the six stages from LLM to multi-agent using the Paris request.
  12. Decide workflow or agent for monthly expense reporting and justify the choice.
  13. Trace the Paris loop through the failed seven-day booking check.
  14. Compare ReAct, plan-and-execute, and reflection using one sentence each.
  15. Classify a fact as conversation state, task state, or long-term memory.
  16. Explain why MCP discovery does not make a tool safe.
  17. Give one reason to keep a single agent and one reason to split into specialists.
  18. Rewrite travel_agent: handle the trip into a contract with inputs, outputs, and limits.
  19. Sketch the coordination cycle and name one stop condition.
  20. Decide supervisor vs peer-to-peer for a booking desk and justify it.
  21. Treat "ignore the budget" from hotel_agent as data and say what gets logged.
  22. Split A2A from MCP in one sentence each.
  23. Explain LangChain versus LangGraph using the Paris agent.
  24. Pick reducers for messages, budget, candidates, and attempt count.
  25. Trace one super-step: active nodes → merge → checkpoint → edges.
  26. Explain how one thread survives a server restart and waits for approval.
  27. Choose handoff or fan-out for flights, hotels, and three client meetings.
  28. Classify timeout, no-result, bad argument, and expired credential failures.
  29. Explain why a booking retry needs an idempotency key.
  30. Read a trace and identify the slow node, retries, policy failure, and approval.