ContextAgent
ContextAgent provides enhanced context management with RAG and conversation history.Quick Start
Copy
import { createContextAgent } from 'praisonai';
const agent = createContextAgent({
instructions: 'You are a helpful assistant.',
llm: 'openai/gpt-4o-mini'
});
const response = await agent.chat('What is TypeScript?');
console.log(response.text);
Configuration
Copy
interface ContextAgentConfig {
name?: string;
instructions: string;
llm?: string;
knowledgeBase?: KnowledgeBase;
contextWindow?: number; // Max messages to keep
maxContextTokens?: number; // Max tokens in context
verbose?: boolean;
}
With Knowledge Base
Copy
import { createContextAgent, createKnowledgeBase } from 'praisonai';
const kb = createKnowledgeBase({
embeddings: 'openai/text-embedding-3-small'
});
await kb.add({ content: 'TypeScript is a typed superset of JavaScript.' });
const agent = createContextAgent({
instructions: 'Answer questions using the knowledge base.',
knowledgeBase: kb
});
const response = await agent.chat('What is TypeScript?');
// Response will include relevant context from knowledge base
Response Format
Copy
interface ContextResponse {
text: string;
context?: SearchResult[]; // RAG context if knowledge base is used
}
CLI Usage
Copy
praisonai-ts context chat "What is TypeScript?"
praisonai-ts context summarize "Long text to summarize..."
praisonai-ts context chat "Hello" --max-messages 20 --json

