UNPKG

tinyagent-ts

Version:

Modern TypeScript framework for building AI agents with pluggable tools and ReAct reasoning

78 lines • 2.88 kB
#!/usr/bin/env node "use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); require("dotenv/config"); const index_1 = require("./index"); const readline_1 = require("readline"); /** * Basic chat agent that just forwards messages to the LLM */ let ChatAgent = class ChatAgent extends index_1.Agent { constructor() { super(); this.promptEngine.overwrite("agent", () => `You are a helpful AI assistant. You aim to be: - Helpful and friendly - Concise but informative - Direct in your responses You should avoid: - Making things up - Being overly verbose - Using unnecessary pleasantries`); } }; ChatAgent = __decorate([ (0, index_1.model)("anthropic/claude-3-sonnet"), __metadata("design:paramtypes", []) ], ChatAgent); async function startChat() { console.log(` šŸ¤– TinyAgent Chat Type your messages and press Enter. Type 'exit' or press Ctrl+C to quit. ---------------------------------------------------------`); const agent = new ChatAgent(); const rl = (0, readline_1.createInterface)({ input: process.stdin, output: process.stdout, }); const prompt = (query) => new Promise((resolve) => rl.question(query, resolve)); try { while (true) { const input = await prompt("\nYou: "); if (input.toLowerCase() === "exit") { break; } try { const response = await agent.run(input); console.log("\nšŸ¤–:", response.answer); } catch (error) { console.error("\nāŒ Error:", error instanceof Error ? error.message : error); } } } finally { rl.close(); console.log("\nGoodbye! šŸ‘‹"); } } // Start chat if run directly if (require.main === module) { if (!process.env.OPENROUTER_API_KEY) { console.error("āŒ Error: OPENROUTER_API_KEY environment variable is not set"); process.exit(1); } startChat().catch(error => { console.error("Fatal error:", error); process.exit(1); }); } //# sourceMappingURL=cli.js.map