Skip to main content
Access global state with convenient singleton objects for config, memory, observability, and workflows.

Quick Start

1

Agent with Global Config

import { Agent, config } from 'praisonai';

// Set global defaults for all agents
config.set('verbose', true);
config.set('model', 'gpt-4o-mini');

const agent = new Agent({
  name: "Assistant",
  instructions: "Be helpful"
});

await agent.start("Hello!");
2

Agent with Global Memory

import { Agent, memory } from 'praisonai';

// Store shared context for agents
memory.set('user_id', 'user-123');
memory.set('preferences', { language: 'en' });

const agent = new Agent({
  name: "Personalized Assistant",
  instructions: `Help user ${memory.get('user_id')} in their preferred language`
});

await agent.start("Recommend a movie");

Config Singleton

Global configuration storage:
import { config } from 'praisonai';

// Set a value
config.set('api_key', 'sk-...');
config.set('model', 'gpt-4o');

// Get a value with default
const model = config.get('model', 'gpt-4o-mini');

// Get all config
const allConfig = config.getAll();

// Clear all config
config.clear();

Config Methods

MethodDescription
get(key, default?)Get value by key
set(key, value)Set a value
getAll()Get all config as object
clear()Clear all config

Memory Singleton

Global memory storage:
import { memory } from 'praisonai';

// Store values
memory.set('context', { topic: 'AI' });
memory.set('history', []);

// Check existence
if (memory.has('context')) {
  const ctx = memory.get('context');
}

// Delete a key
memory.delete('context');

// Get all keys
const keys = memory.keys();

// Get size
const count = memory.size();

// Clear all
memory.clear();

Memory Methods

MethodDescription
get(key)Get value by key
set(key, value)Set a value
has(key)Check if key exists
delete(key)Delete a key
keys()Get all keys
size()Get number of entries
clear()Clear all memory

Observability Singleton

Global observability control:
import { obs } from 'praisonai';

// Enable observability
obs.enable();

// Enable with provider
obs.enable(langfuseProvider);

// Check if enabled
if (obs.isEnabled()) {
  // Trace an event
  obs.trace('agent_start', { name: 'Assistant' });
  
  // Create a span
  const span = obs.span('tool_call');
  // ... do work ...
  span.end();
}

// Get provider
const provider = obs.getProvider();

// Disable
obs.disable();

Obs Methods

MethodDescription
enable(provider?)Enable observability
disable()Disable observability
isEnabled()Check if enabled
getProvider()Get current provider
trace(name, data?)Emit a trace event
span(name)Create a span

Workflows Singleton

Global workflow registry:
import { workflows } from 'praisonai';

// Register a workflow
workflows.register('research', myResearchWorkflow);
workflows.register('analysis', myAnalysisWorkflow);

// Get a workflow
const research = workflows.get('research');

// Check existence
if (workflows.has('research')) {
  // Run workflow
}

// List all workflows
const names = workflows.list();

// Remove a workflow
workflows.remove('research');

// Clear all
workflows.clear();

Workflows Methods

MethodDescription
register(name, workflow)Register a workflow
get(name)Get workflow by name
has(name)Check if workflow exists
list()List all workflow names
remove(name)Remove a workflow
clear()Clear all workflows

Tools Registry

Register and manage tools globally:
import { Tools, ToolDefinition } from 'praisonai';

const toolsRegistry = new Tools();

// Register a tool
toolsRegistry.register({
  name: 'calculator',
  description: 'Perform calculations',
  execute: ({ expression }) => eval(expression)
});

// Get a tool
const calc = toolsRegistry.get('calculator');

// Check existence
if (toolsRegistry.has('calculator')) {
  const result = calc.execute({ expression: '2 + 2' });
}

// List all tools
const allTools = toolsRegistry.list();

// Get count
console.log(`${toolsRegistry.count} tools registered`);

// Remove a tool
toolsRegistry.remove('calculator');

// Clear all
toolsRegistry.clear();

Common Patterns

import { config, memory, obs } from 'praisonai';

function initializeApp() {
  // Set global config
  config.set('llm', process.env.LLM_MODEL || 'gpt-4o-mini');
  config.set('verbose', process.env.DEBUG === 'true');
  
  // Initialize memory
  memory.set('app_start', new Date());
  memory.set('request_count', 0);
  
  // Enable observability in production
  if (process.env.NODE_ENV === 'production') {
    obs.enable(langfuseProvider);
  }
}

Best Practices

Set up global singletons at app startup before any agents run.
Store environment-specific settings in config for easy access.
Call memory.clear() in test teardown to avoid state leakage.
Observability adds overhead - enable only in production or debugging.