AI Decorators
Define AI completion, embeddings, RAG pipelines, safety policies, model capabilities, and token budgets with AxilJS semantic decorators.
AI Decorators
AxilJS AI decorators describe AI-powered behavior without coupling application code to a specific model provider.
They declare the capability or constraint an operation requires. An AI consumer can then interpret that metadata and select the appropriate model, provider, safety policy, retrieval pipeline, or resource limits.
This keeps AI semantics in the application contract while allowing the underlying AI infrastructure to evolve independently.
@tAIComplete
Declares that a method produces its result through LLM completion.
Tasks
| Task | Description |
|---|---|
'summarization' | Condense text |
'classification' | Categorize content |
'extraction' | Extract structured data |
'generation' | Generate new content |
'reasoning' | Perform complex reasoning |
The task describes the intended AI capability rather than a specific model or vendor.
@tAIEmbed
Declares that an operation produces embeddings for vector storage or search.
The metadata describes the embedding requirement and target storage context so an AI consumer can handle the embedding operation.
@tAIRAG
Declares a retrieval-augmented generation pipeline.
The declaration specifies the retrieval collection, number of results, and whether retrieved sources should be included in the result.
@tAIGuard
Declares content-safety checks for AI input or output.
Policies
| Policy | Description |
|---|---|
'toxicity' | Hate speech and harassment |
'pii' | Personal information leakage |
'spam' | Spam and promotional content |
'nsfw' | Not-safe-for-work content |
'jailbreak' | Prompt injection attempts |
Actions
| Action | Description |
|---|---|
'block' | Reject the request |
'flag' | Allow the request but flag it for review |
'warn' | Allow the request with a warning |
The decorator describes the required safety policy; the AI consumer is responsible for enforcing it.
@tAIModel
Selects an AI model by capability rather than by vendor or model name.
Capabilities
| Capability | Description |
|---|---|
'reasoning' | Complex logical reasoning |
'coding' | Code generation and review |
'summarization' | Text condensation |
'vision' | Image understanding |
'embedding' | Vector embeddings |
This allows the application to describe the required model capability while leaving model selection to the AI infrastructure.
@tAITokenBudget
Declares input, output, and cost limits for an AI operation.
The budget provides explicit resource constraints for AI execution.
Full AI Example
AI decorators can be composed with HTTP, authentication, quota, caching, and other AxilJS semantics:
The AI consumer can read the tAI* metadata and orchestrate the provider call, safety checks, budget enforcement, and other declared semantics.
Composable AI Semantics
AI decorators describe independent concerns:
tAICompletedefines the AI task.tAIModeldefines the required model capability.tAIGuarddefines content-safety requirements.tAITokenBudgetdefines execution limits.tAIRAGdefines retrieval-augmented generation.tAIEmbeddefines embedding requirements.
They can also be composed with non-AI decorators such as tAuth, tQuota, tCache, and tHttp.
This gives an AI operation a declarative contract without requiring its business logic to directly encode provider-specific orchestration.
Reference
| Decorator | Purpose |
|---|---|
tAIComplete | Declare an LLM completion task |
tAIEmbed | Produce embeddings for storage or search |
tAIRAG | Declare a retrieval-augmented generation pipeline |
tAIGuard | Define AI content-safety policies |
tAIModel | Select a model by capability |
tAITokenBudget | Define input, output, and cost limits |
AxilJS AI decorators make AI behavior explicit, composable, and provider-independent. The application declares what AI capability it needs; an AI consumer can determine how that capability is fulfilled.