Skip to content

AGENTS.md

126 lines · 3.9 KB · Markdown
Raw

@kody/ai — agent notes

Human setup and intent live in README.md. This file is for agents: imports, smoke/dryRun execute snippets, and edge cases. Secrets by name only — never paste key values. Do not disable live webhooks or jobs (this package ships none).

Secrets / storage

KindNameNotes
User secretopenaiApiKeyHost api.openai.com
User secretanthropicApiKeyHost api.anthropic.com
User secretgroqApiKeyHost api.groq.com
User secretcloudflareApiTokenHosts api.cloudflare.com, gateway.ai.cloudflare.com
User secretopenaiCompatibleApiKeyApprove the host you pass as baseUrl
Package storage (after fork)provider, model, baseUrl, cloudflareAccountId, cloudflareAiGatewayIdReadable defaults via ./settings

Multi-account: account: "work" → openaiApiKey-work (or matching provider secret), or pass apiKeySecret explicitly. Live @kody/ai storage is the platform bucket — fork (or invoke the user's copy) before writing defaults.

Import paths

ExportImport
root dispatcher / re-exportskody:@kody/ai
one chat completion (generateText)kody:@kody/ai/complete
structured JSON (generateObject)kody:@kody/ai/generate-object
model-only step + default tool schemaskody:@kody/ai/model-step
optional tool-using agent turnkody:@kody/ai/turn
fork-local provider/model defaultskody:@kody/ai/settings
console steps / prefilled secret URLskody:@kody/ai/guide
smoke-testkody:@kody/ai/smoke-test
typeskody:@kody/ai/types

Prefer static kody:@kody/ai/... imports from execute. Do not lead with packages.invoke. Prefer runModelStep when a host package should execute tools in its own package context (correct secret allowlists). runAgentTurn still runs tools as package ai.

Smoke test (read-only)

Safe before credentials: returns { ok: true, live: false } plus setup URLs. With a secret and host approval, lists models only — no completion tokens.

import smokeTest from 'kody:@kody/ai/smoke-test'

export default async function main() {
	return await smokeTest()
}

Equivalent via root:

import ai from 'kody:@kody/ai'

export default async function main() {
	return await ai()
}

dryRun / confirm

./settings writes default to dry-run and need confirm: true. Completions are live when you pass messages (that is the helper). Pass dryRun: true to preview the provider, model, URL, and body without calling the vendor.

import { generateText } from 'kody:@kody/ai'

export default async function main() {
	return await generateText({
		provider: 'openai',
		messages: [{ role: 'user', content: 'Say hello in one word.' }],
		dryRun: true,
	})
}

Live completion after the secret exists:

import { generateText } from 'kody:@kody/ai'

export default async function main() {
	return await generateText({
		provider: 'openai',
		messages: [{ role: 'user', content: 'Say hello in one word.' }],
	})
}

Structured JSON:

import { generateObject } from 'kody:@kody/ai'

export default async function main() {
	return await generateObject({
		provider: 'openai',
		messages: [{ role: 'user', content: 'Label this: I love this package' }],
		schema: {
			type: 'object',
			properties: {
				label: { type: 'string', enum: ['positive', 'neutral', 'negative'] },
			},
			required: ['label'],
			additionalProperties: false,
		},
		dryRun: true,
	})
}

Edge cases

SymptomWhat to do
Missing API key / 401Save the provider secret and approve its host
Cloudflare missing accountFork, then ./settings with cloudflareAccountId and confirm: true
openai-compatible missing baseUrlPass baseUrl (https) or store it in ./settings on your fork
Unknown providerUse openai, anthropic, groq, cloudflare, or openai-compatible