Welcome back! In the previous chapter, Tool Summary Generator, we built the engine that sends data to an AI model to get a summary.
However, having an engine isn't enough. If you simply ask an AI to "summarize what happened," it might reply with:
"I have reviewed the logs and it appears that a file was read successfully. After that, the system..."
This is too long. We are building a mobile app notification or a single-line status bar. We have limited space. We need the AI to be concise, robotic, and specific.
In this chapter, we will learn about Prompt Configuration. We will define the "persona" or "style guide" for our AI to ensure the output fits perfectly into our user interface (UI).
Imagine you hire a copywriter to write a headline for a billboard.
In our code, the System Prompt is that set of strict instructions. It tells the AI how to speak before it even knows what to speak about.
We want to transform a complex tool action like deleteFile('/src/temp/unused.log') into a summary.
The System Prompt is like a Creative Brief given to an employee. For this project, our brief has three strict rules:
Let's look at the actual text we send to the AI. This is defined as a constant string in our code.
// From file: toolUseSummaryGenerator.ts
const TOOL_USE_SUMMARY_SYSTEM_PROMPT = `
Write a short summary label describing what these tool calls accomplished.
It appears as a single-line row in a mobile app and truncates around 30 characters,
so think git-commit-subject, not sentence.
Keep the verb in past tense and the most distinctive noun.
Drop articles, connectors, and long location context first.
Examples:
- Searched in auth/
- Fixed NPE in UserService
- Created signup endpoint
- Read config.json
- Ran failing tests
`
Explanation:
How does this text get used?
When we communicate with an AI (like Claude or ChatGPT), we send two types of messages:
Let's see where we actually inject this configuration into the generator function we looked at in the last chapter.
// From file: toolUseSummaryGenerator.ts
// 1. We prepare the prompt configuration
const systemPrompt = asSystemPrompt([TOOL_USE_SUMMARY_SYSTEM_PROMPT])
// 2. We send it to the AI alongside the data
const response = await queryHaiku({
systemPrompt: systemPrompt,
userPrompt: `Tools completed:\n\n${toolSummaries}\n\nLabel:`,
signal,
// ... options
})
Explanation:
asSystemPrompt: This is a helper that formats our string into the specific object structure the API requires.queryHaiku: This function takes the systemPrompt as a separate argument from the userPrompt. This ensures the rules are kept separate from the data, preventing the data from confusing the AI about its instructions.You might wonder why we specifically asked for "Git commit subject" style.
In software development, a "Git commit" is a saved change to the code. Developers are trained to write the subject line of these saves in a very specific way:
By telling the AI to use this specific style, we leverage a concept the AI already knows very well from its training data (which includes millions of lines of code). It creates a mental shortcut for the model to produce high-quality technical summaries.
In this chapter, we learned about Prompt Configuration.
Now our AI knows how to write. But what if the data we send it is too big? Even the best AI will crash or cost too much money if we try to paste a 10-megabyte file into the chat window.
In the next chapter, we will learn how to trim the data before it ever reaches the prompt.
Next Chapter: Payload Optimization
Generated by Code IQ