close
Skip to main content

latest
Works with
It is unknown whether this package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
It is unknown whether this package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score82%
Publisheda year ago (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

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@deno-agents/utils

Import symbol

import { completeWithSchema } from "@deno-agents/utils";
or

Import directly with a jsr specifier

import { completeWithSchema } from "jsr:@deno-agents/utils";