TypeScript SDK: Setup and your first agent

Create and run a single agent in Node.js

In TypeScript, every agent starts with new Agent({ name, instructions }) and runs asynchronously with await agent.start(…). Set OPENAI_API_KEY (or point at local Ollama) in your environment.

Example

import { Agent } from 'praisonai';

async function main() {
  const agent = new Agent({
    name: 'DocsHelper',
    instructions: 'Answer developer questions in one clear sentence.',
    llm: 'gpt-4o-mini',
  });

  const reply = await agent.start('What is an HTTP 429 status code?');
  console.log(reply);
}

main();

Example explained

  • new Agent({ name, instructions, llm }) — Mirrors the Python Agent constructor with full TypeScript autocomplete.
  • await agent.start(…) — Executes the agent asynchronously and resolves to the final string reply.

Run completely offline with Ollama in TypeScript

Switch to a local Ollama model with one config string so development and privacy-sensitive apps never send data to a cloud API.

Example

import { Agent } from 'praisonai';

const localAgent = new Agent({
  name: 'LocalAssistant',
  instructions: 'Be concise.',
  llm: 'ollama/llama3.2',
});

console.log(await localAgent.start('Summarize why local models help privacy.'));

Example explained

  • llm: 'ollama/llama3.2' — Routes requests to your local Ollama server with zero API keys.

Common pitfall: forgetting ESM or tsx configuration

If Node throws SyntaxError: Cannot use import statement outside a module, add "type": "module" to package.json or run TypeScript directly with npx tsx index.ts.

Reference: documentation