Welcome to the final chapter of our BriefTool tutorial series!
In the previous chapter, Bridge Upload Protocol, we built a sophisticated system to move files securely from a local computer to the cloud. We have now built a "Waiter" that can speak, present menus beautifully, check the food quality, and even deliver takeout to remote locations.
But there is one final, critical question: Who is actually allowed to sit at this table?
Not every user should see every feature. Some features are experimental (beta), some are for paid "Pro" users only, and some might be broken and need to be turned off remotely.
This chapter covers Feature Entitlement & Gating: the complex decision logic that determines if BriefTool should be active or hidden.
Imagine you get into a high-tech car. You want to start the engine. In a simple world, you just turn a key. But in a complex system, three things must happen:
If the engine is missing, the key is wrong, or you don't push the button, the car stays silent.
Our software works the same way. We don't want to show BriefTool if the code was compiled without it, if the user isn't in the beta group, or if the user explicitly turned it off.
User Intent: The user types claude --brief in their terminal. They want to force the tool to turn on.
The System's Logic:
KAIROS code included?--brief).Result: Only if all three are true does the tool appear.
We separate the logic into two main functions: isBriefEntitled (Am I allowed?) and isBriefEnabled (Is it on?).
feature)This is the "Factory Setting." When we compile the code, we can choose to include or exclude entire chunks of logic.
feature('KAIROS')GrowthBook)This is the "License." Even if the code exists, we might want to gate it behind a remote toggle. This allows us to rollout features slowly (e.g., to 10% of users) or kill a feature instantly if it breaks, without users needing to update their app.
getFeatureValue_CACHED_WITH_REFRESH(...)This is the "Switch." Even if a user is allowed to use a feature, they might prefer the old way of working. We respect their choice.
getUserMsgOptIn()
When the application starts, it runs a specific sequence to decide if BriefTool should be added to the AI's toolbox.
Let's look at BriefTool.ts. This file contains the logic that acts as the gatekeeper.
isBriefEntitled)This function checks permissions. It doesn't care if you want to use the tool, only if you can.
// From BriefTool.ts (Simplified)
export function isBriefEntitled(): boolean {
// 1. Build-time check: Is the code here?
const hasBuildFlag = feature('KAIROS') || feature('KAIROS_BRIEF')
// If the code isn't even compiled, stop immediately.
if (!hasBuildFlag) return false
// 2. Runtime check: Check remote flags (GrowthBook)
// Or check if the user is a developer (CLAUDE_CODE_BRIEF)
return (
getKairosActive() ||
isEnvTruthy(process.env.CLAUDE_CODE_BRIEF) ||
getFeatureValue_CACHED_WITH_REFRESH('tengu_kairos_brief', false)
)
}
Explanation:
feature(...): If this returns false, the compiler might actually delete the code inside this block to save space (Dead Code Elimination).isEnvTruthy(...): A "Master Key" for developers. If I set CLAUDE_CODE_BRIEF=true on my laptop, I bypass the remote checks so I can test my work.getFeatureValue...: Checks the remote server.isBriefEnabled)This function combines the permission check (above) with the user's intent.
// From BriefTool.ts (Simplified)
export function isBriefEnabled(): boolean {
// 1. Re-check the build flag (Crucial for code removal)
if (!feature('KAIROS') && !feature('KAIROS_BRIEF')) {
return false
}
// 2. Check User Intent (OptIn) AND Permission (Entitled)
const userWantsIt = getKairosActive() || getUserMsgOptIn()
const userIsAllowed = isBriefEntitled()
return userWantsIt && userIsAllowed
}
Explanation:
&&). Both must be true.Finally, we apply this logic to the tool definition itself.
// From BriefTool.ts
export const BriefTool = buildTool({
name: BRIEF_TOOL_NAME,
// This function is called every time the AI is about to run
isEnabled() {
return isBriefEnabled()
},
// ... rest of tool definition
})
Explanation: isEnabled() is the final barrier. If this returns false, the AI model doesn't even know this tool exists. It won't see it in the list of available actions.
Congratulations! You have completed the BriefTool tutorial series.
We have traced the journey of a single feature from a raw string of text to a secure, gated, production-ready system.
You now understand the architecture of a modern AI tool: it is not just a function call; it is a pipeline of Validation, UX, Security, and Access Control.
Thank you for reading!
Generated by Code IQ