Welcome to Chapter 3 of the TaskGetTool tutorial!
In the previous Chapter 2: Data Contract Schemas, we built strict "Border Guards" (Schemas) to ensure the AI speaks to our code correctly (using the right data types).
Now, we face a different challenge. The AI knows how to call the tool (syntax), but it doesn't necessarily know why or when to call it (semantics).
In this chapter, we will write the Prompt Configuration. This is effectively the "User Manual" that we hand to the AI.
Imagine you hand a new employee a specialized wrench.
Without this manual, the AI is just guessing. It might try to "Get a Task" when it should be "Creating a Task." Or worse, it might start working on a task without checking if it is blocked by another task first.
The Central Use Case: We want the AI to read our documentation and autonomously think: "I see that I should check the 'blockedBy' field before I tell the user I'm starting work."
We define these instructions in a file called prompt.ts. There are two distinct parts to this configuration:
This is a short, one-sentence summary. When the AI has 50 different tools available, it scans these descriptions to quickly decide which tool is relevant to the user's request.
This is a detailed block of text (often written in Markdown). It provides:
Let's look at the prompt.ts file in our project.
We keep this simple. It helps the AI's "router" pick the right tool.
// Inside prompt.ts
export const DESCRIPTION = 'Get a task by ID from the task list'
Explanation: If a user says "Find task 123," the AI matches that intent against this string.
This is where we add intelligence. We aren't writing code here; we are writing English instructions that the AI will "read."
// Inside prompt.ts
export const PROMPT = `Use this tool to retrieve a task by its ID.
## When to Use This Tool
- To understand task dependencies (what blocks it)
- After being assigned a task, to get complete requirements
## Tips
- After fetching, verify its 'blockedBy' list is empty.
`
Explanation:
##) and bullet points because AI models are trained on internet text and understand this structure very well.How does the AI actually see this? It's not magic. When the application starts, our system bundles these strings and sends them to the AI in a "System Message."
DESCRIPTION and PROMPT.
We need to attach these strings to our main Tool Definition so the system can find them. We do this in TaskGetTool.ts.
// Inside TaskGetTool.ts
import { DESCRIPTION, PROMPT } from './prompt.js'
export const TaskGetTool = buildTool({
name: TASK_GET_TOOL_NAME,
// 1. Attach the short description
async description() {
return DESCRIPTION
},
// 2. Attach the detailed manual
async prompt() {
return PROMPT
},
// ... rest of the tool definition (schemas, call function)
})
Beginner Explanation:
prompt.ts.description() and prompt() functions in the tool builder.buildTool framework runs, it knows exactly what documentation to send to the AI.
You might wonder, "Why put text in a separate file (prompt.ts) instead of right inside the code?"
In this chapter, we created the Prompt Configuration.
We learned that:
At this point, the AI knows how to call the tool (Chapter 2) and why to call it (Chapter 3). When it finally calls the tool, our code runs and gets a result from the database.
However, the database gives us raw data. If we just dump a giant JSON object back to the AI, it might get confused or waste "tokens" (processing power). We need to present the result nicely.
Next Chapter: Result Formatting Strategy
Generated by Code IQ