Skip to content

Learning: LLM Fundamentals for Agents

How to Use This Page

  • Work lesson-by-lesson and keep prompts versioned.
  • Measure both quality and token cost.
  • Iterate only one variable at a time.

Lesson 1: Fundamentals

Learn how prompt structure and instruction clarity shape model behavior.

What You Learn

  • How to write task, constraints, and output format explicitly
  • Why instruction ordering changes model compliance
  • How token budgets influence response quality

Walkthrough

  1. Create a baseline prompt for one fixed task.
  2. Add explicit format constraints.
  3. Compare output consistency across 5 repeated runs.

Try It Yourself

  • Move key instructions from bottom to top and compare outcomes.
  • Remove one constraint at a time and note failure modes.
  • Rewrite the prompt in half the tokens and compare quality.

Lesson 2: Intermediate Patterns

Learn template families, routing strategies, and context budgeting.

What You Learn

  • How to route simple tasks to lower-cost models
  • Why prompt templates should be task-specific
  • How to track token usage by task class

Walkthrough

  1. Define low, medium, and high-complexity prompt templates.
  2. Route inputs by complexity.
  3. Log token input/output and quality score per run.

Try It Yourself

  • Add a misroute case and analyze quality impact.
  • Tune one template for lower cost without quality loss.
  • Create a fallback template when the first response fails format checks.

Lesson 3: Production Patterns

Learn context trimming, relevance control, and prompt release management.

What You Learn

  • How to keep only relevant context chunks
  • Why noisy context causes lost-in-the-middle errors
  • How to version prompts and roll back safely

Walkthrough

  1. Add a context filtering step before model invocation.
  2. Evaluate output quality with full vs filtered context.
  3. Store prompt versions with simple change notes.

Try It Yourself

  • Build a tiny eval set with 10 representative queries.
  • Compare two prompt versions on cost and accuracy.
  • Pick a release candidate and document rollback criteria.

Code Examples

  • Starter script: docs/starter/stage02_llm_fundamentals.py
  • Stage architecture notes: docs/roadmap/stage-02-prompt-design-context-control/architecture.md