Get started with @anvia/extensions ​
This page builds one agent that reads a workspace, never leaks credentials in its answers, keeps tool output small, and reports usage after each run.
Install ​
sh
pnpm add @anvia/core @anvia/openai @anvia/extensions zodAny provider package works; this example uses OpenAI. Run it on Node.js 20.3 or newer.
Build the agent ​
ts
import { Agent } from '@anvia/core'
import { OpenAIClient } from '@anvia/openai'
import { filesystem } from '@anvia/extensions/tools/fs'
import { secretLeakGuardrail } from '@anvia/extensions/guardrails'
import { toolOutputLimit } from '@anvia/extensions/middlewares'
import { usageHook } from '@anvia/extensions/hooks'
const client = new OpenAIClient({ apiKey: process.env.OPENAI_API_KEY! })
const agent = new Agent({
id: 'workspace-reader',
model: client.completionModel({ modelId: 'gpt-5.6-sol', api: 'responses' }),
instructions: 'Answer questions about the project using the files in the workspace.',
tools: [filesystem({ rootDir: './workspace', readOnly: true })],
guardrails: [secretLeakGuardrail()],
middlewares: [toolOutputLimit({ maxChars: 8_000 })],
lifecycle: [
usageHook({
onReport: (report) => {
console.log(report.status, report.steps, report.toolCalls, report.usage.totalTokens)
},
}),
],
})
const response = await agent.generate({ prompt: 'What does the README say about setup?' })
if (response.type === 'response') console.log(response.output)What each piece does:
filesystem({ rootDir, readOnly: true })registersread_file,list_files, andgrep, confined to./workspaceafter resolving symlinks. WithoutreadOnly, it also addswrite_file,edit_file, anddelete_file; onlydelete_filerequires approval by default.secretLeakGuardrail()checks the final answer against built-in credential patterns (API keys, tokens, JWTs, private keys) and blocks the response on a match.toolOutputLimit({ maxChars })truncates any tool result longer than 8,000 characters before the model sees it.usageHook({ onReport })reports status, steps, tool calls, failures, duration, and token usage once per run.lifecycleaccepts an array, so you can addcostHookorauditHookbeside it.
The toolkit's built-in instructions are appended to the agent's instructions. Pass instructions: false to the toolkit to omit them, or a string to replace them. See Toolkits for how toolkit options are applied.
Next steps ​
- Pick more toolkits, or wrap one with
withToolRetryorwithToolCache. - Add guardrails, middlewares, and hooks.
- Read Security before enabling
shell, write access, or network tools.