Documentation Index
Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
Use this file to discover all available pages before exploring further.
Code Mode
Code Mode provides AI-powered code generation and editing capabilities for agents.
Installation
Quick Start
import { Agent, codeMode } from 'praisonai-ts';
const codeTool = codeMode({
language: 'typescript',
});
const agent = new Agent({
name: 'CodeAgent',
instructions: 'You help write and edit code.',
tools: [codeTool],
});
const response = await agent.chat('Write a function to calculate fibonacci numbers');
Configuration
interface CodeModeConfig {
/** Programming language */
language?: 'typescript' | 'javascript' | 'python' | 'go' | 'rust';
/** Enable code formatting */
format?: boolean;
/** Enable linting */
lint?: boolean;
/** Working directory */
workDir?: string;
}
Usage Examples
Generate Code
const codeTool = codeMode({ language: 'python' });
const agent = new Agent({
name: 'PythonCoder',
instructions: 'You write Python code.',
tools: [codeTool],
});
await agent.chat('Create a class for managing a todo list');
Edit Existing Code
const codeTool = codeMode({
language: 'typescript',
workDir: './src',
});
const agent = new Agent({
name: 'CodeEditor',
instructions: 'You help refactor and improve code.',
tools: [codeTool],
});
await agent.chat('Refactor the utils.ts file to use async/await');
interface CodeModeInput {
/** Action to perform */
action: 'generate' | 'edit' | 'explain' | 'review';
/** Code or description */
content: string;
/** Target file path (for edit) */
filePath?: string;
}
interface CodeModeResult {
/** Generated or edited code */
code: string;
/** Explanation */
explanation?: string;
/** File path if saved */
filePath?: string;
/** Language */
language: string;
}
Environment Variables
| Variable | Required | Description |
|---|
OPENAI_API_KEY | Yes | For code generation |