@deno-agents/utils@1.0.1
Agentic AI Utilities (Deno)
Utilities for building agentic AI systems with structured outputs in Deno.
Features
- 🛠️ 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
Installation
deno add @deno-agent/utils
Usage
import { 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)
API Reference
completeWithSchema(apiKey, baseURL, schema, systemPrompt, userPrompt, model?)`
Parameters:
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")
Returns: Promise<[string, string | undefined]>
Tuple containing:
JSON string matching the schema Optional reasoning string (if supported by model)
Error Handling
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
License
MIT License
Add Package
deno add jsr:@deno-agents/utils
Import symbol
import { completeWithSchema } from "@deno-agents/utils";
Import directly with a jsr specifier
import { completeWithSchema } from "jsr:@deno-agents/utils";