Inspecting Prompt Templates and Context Windows
What you'll learn: How to examine the exact prompts your agent sends to the LLM to verify they contain the right context, tools, and conversation history.
Why Inspection Matters
When your agent behaves unexpectedly—choosing wrong tools, forgetting context, or repeating actions—the culprit is often the actual prompt being sent to the LLM. What you think you're sending may differ from what's actually assembled at runtime.
Think of it like debugging a recipe: if your cake doesn't rise, you need to check the exact ingredients that went into the bowl, not just assume they matched the recipe card.
What to Inspect
Prompt template structure: Verify your system message, instruction format, and tool definitions are correctly formatted and complete.
Context window contents: Check what conversation history, observations, and prior reasoning steps are included. Are older messages being truncated? Is critical context missing?
Tool definitions: Ensure function schemas, parameter descriptions, and examples are present and accurate in the prompt.
Token count: Confirm your assembled prompt fits within the model's context window limits—you may be silently truncating important information.
How to Inspect
Add logging before each LLM call to dump the complete prompt object. Review the exact string or message array being sent. Compare against your expectations. Look for missing sections, malformed JSON, or unexpected truncation.
This inspection step transforms debugging from guesswork into systematic verification. You'll quickly spot whether the agent's mistakes stem from bad prompts or model behavior.
Key Takeaway: Always log and inspect the complete prompt sent to your LLM—what you think you're sending isn't always what arrives, and visibility into the actual context window is essential for debugging agent behavior.