Utilities for building agentic AI systems with structured outputs in Deno.
- 🛠️ Schema-Enforced Completions - Ensure LLM responses adhere to JSON schemas
- 🤖 System Prompt Integration - Easily combine OpenAI-compatible endpoint
- 📝 Optional Reasoning Capture - Get model reasoning alongside structured responses
- 🚦 Type Safety - Written in TypeScript with strict type checking
deno add @deno-agent/utilsimport { completeWithSchema } from "@your-username/ai-utils"
// Example schema
const answerSchema = {
type: "object",
properties: {
answer: { type: "string" },
confidence: { type: "number" },
},
required: ["answer"],
}
// Run completion
const [content, reasoning] = await completeWithSchema(
"your-api-key",
"https://api.together.xyz/v1",
answerSchema,
"You are a helpful assistant that answers questions precisely.",
"What is the capital of France?",
"meta-llama/Llama-3-70b-chat-hf"
)
// Parse and use results
const result = JSON.parse(content)
console.log("Answer:", result.answer)
console.log("Reasoning:", reasoning)apiKey: string - API key for your LLM provider baseURL: string - Base URL of OpenAI-compatible API endpoint schema: object - JSON Schema for response validation systemPrompt: string - Base system prompt userPrompt: string - User instruction/question model: string (optional) - Model name (default: "meta-llama/Llama-3.3-70B-Instruct")
Tuple containing:
JSON string matching the schema Optional reasoning string (if supported by model)
The function will throw an error if:
No content is generated by the model The response doesn't match the schema (handled by API provider) Network/authentication issues occur Model Compatibility
MIT License