Cogitator
API Reference

Core API

Complete API reference for @cogitator-ai/core — the main runtime package.

Classes

Cogitator

The main runtime class. Creates and manages agent execution.

import { Cogitator } from '@cogitator-ai/core';

const cogitator = new Cogitator(config: CogitatorConfig);

Methods:

MethodSignatureDescription
runrun(agent: Agent, input: string | RunOptions): Promise<RunResult>Execute an agent
closeclose(): Promise<void>Cleanup all resources

Agent

Represents an LLM agent with tools and instructions.

import { Agent } from '@cogitator-ai/core';

const agent = new Agent(config: AgentConfig);

AgentConfig:

PropertyTypeDefaultDescription
namestringrequiredAgent identifier
instructionsstring''System prompt
toolsTool[][]Available tools
modelstringModel override (provider/model)
temperaturenumberSampling temperature
maxTokensnumberMax tokens in response
responseFormatResponseFormatJSON mode / json_schema

ToolRegistry

Manages tool registration and lookup.

import { ToolRegistry } from '@cogitator-ai/core';

const registry = new ToolRegistry();
registry.register(tool);
registry.get('tool_name');
registry.list();

ReflectionEngine

Self-reflection and insight generation.

import { ReflectionEngine } from '@cogitator-ai/core';

ThoughtTreeExecutor

Tree-of-Thought reasoning over multiple paths.

import { ThoughtTreeExecutor } from '@cogitator-ai/core';

ConstitutionalAI

Safety guardrails with constitutional principles.

import { ConstitutionalAI, InputFilter, OutputFilter, ToolGuard } from '@cogitator-ai/core';

CostAwareRouter

Route requests to the cheapest capable model.

import { CostAwareRouter, BudgetEnforcer, ModelSelector } from '@cogitator-ai/core';

TimeTravel

Snapshot, replay, and fork agent executions.

import {
  TimeTravel,
  ExecutionReplayer,
  ExecutionForker,
  TraceComparator,
} from '@cogitator-ai/core';

CausalReasoner

Causal graph construction and counterfactual reasoning.

import { CausalReasoner, CausalGraphBuilder, CounterfactualReasoner } from '@cogitator-ai/core';

ContextManager

Manage conversation context within token limits.

import { ContextManager, SummarizeStrategy, SlidingWindowStrategy } from '@cogitator-ai/core';

PromptInjectionDetector

Detect and block prompt injection attacks.

import { PromptInjectionDetector } from '@cogitator-ai/core';

Factory Functions

tool()

Create a type-safe tool:

import { tool } from '@cogitator-ai/core';
import { z } from 'zod';

const myTool = tool({
  name: string,
  description: string,
  parameters: ZodSchema,
  execute: async (params, context?) => result,
});

agentAsTool()

Wrap an agent as a callable tool:

import { agentAsTool } from '@cogitator-ai/core';

const delegateTool = agentAsTool(agent, options?: AgentAsToolOptions);

withCache()

Add caching to any tool:

import { withCache } from '@cogitator-ai/core';

const cachedTool = withCache(myTool, { ttl: '5m', storage: cacheStorage });

LLM Backends

import {
  OllamaBackend,
  OpenAIBackend,
  AnthropicBackend,
  createLLMBackend,
} from '@cogitator-ai/core';
BackendProvider StringDescription
OllamaBackendollamaLocal Ollama models
OpenAIBackendopenaiOpenAI API
AnthropicBackendanthropicAnthropic Claude API

Built-in Tools

import { builtinTools, calculator, datetime, httpRequest /* ... */ } from '@cogitator-ai/core';

26 built-in tools: calculator, datetime, uuid, randomNumber, randomString, hash, base64Encode, base64Decode, sleep, jsonParse, jsonStringify, regexMatch, regexReplace, fileRead, fileWrite, fileList, fileExists, fileDelete, httpRequest, exec, webSearch, webScrape, sqlQuery, vectorSearch, sendEmail, githubApi.

Observability

import {
  LangfuseExporter,
  createLangfuseExporter,
  OTLPExporter,
  createOTLPExporter,
} from '@cogitator-ai/core';

Resilience Utilities

import {
  withRetry,
  CircuitBreaker,
  withFallback,
  withGracefulDegradation,
} from '@cogitator-ai/core';

On this page