agent-core

The endpoint-agnostic half of an OpenAI-compatible agent loop.

Get started GitHub ↗

What it does

An agent that talks to OpenAI, Ollama, llama.cpp, vLLM or OpenRouter through the same API ends up writing the same plumbing: pooled clients, retries, streaming, and working out what each server refuses. This package is that plumbing, extracted from three servers that had each written it separately and drifted apart. Prompts, tools and what a run is for stay with the caller.

Get started

ESM only, Node 22 or later. openai (version 6 or later) is a peer dependency.

npm install @cubicecho/agent-core openai
import { runAgentLoop } from "@cubicecho/agent-core";

const { turn } = await runAgentLoop({
  config: {
    baseUrl: "http://localhost:11434/v1", // any OpenAI-compatible endpoint
    apiKey: "",
    model: "qwen3",
    maxTokens: 1024,
    temperature: 0.2,
    maxToolIterations: 8,
  },
  messages: [{ role: "user", content: "What changed in the last release?" }],
  tools, // OpenAI tool definitions, if the run has any
  dispatch: async ({ name, args }) => callTool(name, args), // returns what the model reads
});

console.log(turn.content);