Welcome back! In the previous chapter, Agent Protocol Adapters, we learned how AionUi acts as a "Universal Translator" to speak to different AI models.
At this point, we have an AI that can talk. But an AI that can only talk is just a fancy chatbot. We want an AI that can work. We want it to edit code, create spreadsheets, and read PDFs.
Think of the Large Language Model (LLM) as a brilliant brain in a jar.
The Tools & Skills Framework gives the AI "hands."
fs.writeFile).Let's imagine the user says: "Make an Excel file with a budget for 2024."
If we just send this to raw ChatGPT, it will spit out a text table. But with the Tools & Skills Framework:
create_xlsx..xlsx file.
Before the AI tries to do a job, it needs to read the manual. In AionUi, these are Markdown files (like SKILL.md).
This isn't code; it's Prompt Engineering stored as a file. It tells the AI best practices, common pitfalls, and formatting rules.
Here is a simplified look at skills/xlsx/SKILL.md (from the provided context):
# XLSX creation, editing, and analysis
## CRITICAL: Use Formulas, Not Hardcoded Values
Always use Excel formulas instead of calculating values in Python.
### โ WRONG
sheet['B10'] = 5000 # Hardcoded
### โ
CORRECT
sheet['B10'] = '=SUM(B2:B9)' # Dynamic formula
2 + 2 in its head and write 4 into the cell. If the user later changes the input to 3, the result stays 4. This manual forces the AI to write =2+2 so the spreadsheet actually works!
Once the AI knows how to behave, it needs a way to act. We build tools using the DeclarativeTool class found in src/agent/gemini/cli/tools/tools.ts.
A tool has two main parts:
We extend BaseDeclarativeTool. This handles all the messy validation logic for us.
// Example: A simplified Create File tool
import { BaseDeclarativeTool } from './tools';
export class CreateFileTool extends BaseDeclarativeTool {
constructor() {
super(
'create_file', // Tool Name (for AI)
'Create File', // Display Name (for UI)
'Writes text to a file', // Description
Kind.Edit, // Category
{ // JSON Schema for inputs
type: 'object',
properties: {
path: { type: 'string' },
content: { type: 'string' }
}
}
);
}
// ... implementation continues below
We implement a createInvocation method. This returns the actual "Action" the tool performs.
protected createInvocation(params: any) {
return {
// 1. Tell the UI what we are about to do (for confirmation dialogs)
getDescription: () => `Creating file at ${params.path}`,
// 2. The actual work happens here
execute: async (signal) => {
await fs.writeFile(params.path, params.content);
return {
returnDisplay: "File created successfully!",
llmContent: "File created."
};
}
};
}
}
{ path: "budget.txt", content: "..." }.execute function runs fs.writeFile.Giving an AI "hands" is dangerous. You don't want it to delete your operating system.
The framework includes a Confirmation System. Before execute() runs, the framework asks: "Do we need user permission?"
This is defined in the ToolInvocation interface:
// Inside a ToolInvocation
shouldConfirmExecute(abortSignal): Promise<ToolCallConfirmationDetails | false>;
If this returns data, the Agent Task Orchestration layer (Chapter 1) pauses everything and shows a pop-up to the user: "The AI wants to edit 'budget.xlsx'. Allow?"
How does a text request become a file on your disk?
validateBuildAndExecute
In src/agent/gemini/cli/tools/tools.ts, there is a critical method called validateBuildAndExecute. This is the safe-guard wrapper around every tool.
// src/agent/gemini/cli/tools/tools.ts
async validateBuildAndExecute(params, abortSignal) {
// 1. Try to build the tool (Checks JSON Schema)
const invocationOrError = this.silentBuild(params);
// 2. If validation fails, tell the AI nicely
if (invocationOrError instanceof Error) {
return {
llmContent: `Error: Invalid parameters. ${invocationOrError.message}`,
error: { type: ToolErrorType.INVALID_TOOL_PARAMS }
};
}
// 3. If valid, try to Execute
try {
return await invocationOrError.execute(abortSignal);
} catch (error) {
// Handle crashes gracefully
return {
llmContent: `Error: Execution failed. ${error.message}`
};
}
}
In this chapter, we learned:
DeclarativeTool) that perform the actual work.Now the AI can manage tasks, talk to us, and use tools to edit files. But how do we get the AI to write better responses? How do we structure the prompts that are sent to the brain?
Next, we will look at Prompt Engineering Protocols to see how we construct the perfect query.
Next Chapter: Prompt Engineering Protocols
Generated by Code IQ