PraisonAI agents can seamlessly switch between LLM providers like OpenAI, Anthropic, Google, and more. Under the hood, agents are powered by the AI SDK for multi-provider support, but you interact with the simple Agent abstraction.
import { Agent } from 'praisonai';// Create an agent with any providerconst agent = new Agent({ instructions: 'You are a helpful assistant.', llm: 'openai/gpt-4o-mini' // or 'anthropic/claude-3-haiku-20240307'});// Chat with the agentconst response = await agent.chat('Hello, how are you?');console.log(response);
import { Agent } from 'praisonai';// OpenAI Agentconst openaiAgent = new Agent({ instructions: 'You are a creative writer.', llm: 'openai/gpt-4o-mini'});// Anthropic Agentconst claudeAgent = new Agent({ instructions: 'You are a code reviewer.', llm: 'anthropic/claude-3-5-sonnet-latest'});// Google Agentconst geminiAgent = new Agent({ instructions: 'You are a research assistant.', llm: 'google/gemini-2.0-flash'});// Use each agentconst story = await openaiAgent.chat('Write a short story');const review = await claudeAgent.chat('Review this code: function add(a,b) { return a+b }');const research = await geminiAgent.chat('Explain quantum computing');
import { Agent } from 'praisonai';const agent = new Agent({ instructions: 'You are a poet.', llm: 'anthropic/claude-3-haiku-20240307', stream: true});// Streaming outputconst response = await agent.chat('Write a haiku about coding');// Output streams to console automatically
import { Agent } from 'praisonai';// Define a tool as a simple functionfunction getWeather(city: string): string { return JSON.stringify({ city, temperature: 22, condition: 'sunny' });}const agent = new Agent({ instructions: 'You help users check the weather.', llm: 'openai/gpt-4o-mini', tools: [getWeather]});const response = await agent.chat('What is the weather in Paris?');console.log(response); // Uses the tool and returns weather info
import { Agent } from 'praisonai';import { z } from 'zod';const PersonSchema = z.object({ name: z.string(), age: z.number(), city: z.string()});const agent = new Agent({ instructions: 'Extract person information from text.', llm: 'openai/gpt-4o-mini', outputSchema: PersonSchema});const result = await agent.chat('John is 30 years old and lives in Paris');// Returns: { name: 'John', age: 30, city: 'Paris' }
import { Agent } from 'praisonai';// Research agent using Claudeconst researcher = new Agent({ name: 'researcher', instructions: 'You research topics thoroughly.', llm: 'anthropic/claude-3-5-sonnet-latest'});// Writer agent using GPT-4const writer = new Agent({ name: 'writer', instructions: 'You write engaging content based on research.', llm: 'openai/gpt-4o'});// Workflow: Research then writeconst research = await researcher.chat('Research the history of AI');const article = await writer.chat(`Write an article based on: ${research}`);
export PRAISONAI_BACKEND=ai-sdk # Force AI SDK for all providersexport PRAISONAI_BACKEND=native # Force native providers onlyexport PRAISONAI_BACKEND=auto # Auto-select (default)
Verify the model name matches the provider’s naming convention.
Advanced: Backend Internals
The AI SDK backend is used internally to provide multi-provider support. You typically don’t need to interact with it directly.
// Internal - not recommended for direct useimport { resolveBackend } from 'praisonai';const { provider, source } = await resolveBackend('anthropic/claude-3-haiku-20240307');console.log(source); // 'ai-sdk' or 'legacy'
The backend resolver automatically:
Detects installed AI SDK provider packages
Falls back to native providers when AI SDK is unavailable
Injects attribution headers for multi-agent tracing