diff --git a/README.md b/README.md index 5219c27..9103761 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,7 @@ flowchart TD | --------- | ----------------------------------------- | | 🔴 Red | Your input prompt (`You >`) | | 🔵 Blue | Agent response (`Agent >`) | +| 🟣 Magenta| Response time (`responded in 1.2s`) | | 🟡 Yellow | Chosen tool name | | 🟢 Green | Agent reasoning (why it picked that tool) | diff --git a/src/agent.js b/src/agent.js index d1f43dd..17459f1 100644 --- a/src/agent.js +++ b/src/agent.js @@ -1,3 +1,4 @@ +const { calculateResponseTime } = require("./help"); const { askLLM } = require("./llm"); const { tools } = require("./tools"); @@ -69,11 +70,16 @@ async function runAgent(userInput, messages = []) { if (messages.length === 0) { messages.push({ role: "system", content: SYSTEM_PROMPT }); } - + messages.push({ role: "user", content: userInput }); console.log("\x1b[41m [Agent Thinking...] \x1b[0m"); + const startTime = Date.now(); const response = await askLLM(messages); + const endTime = Date.now(); + const responseTimeSeconds = calculateResponseTime(startTime, endTime); + console.log(`\x1b[45m [Responded in: ${responseTimeSeconds}s] \x1b[0m`); + messages.push({ role: "assistant", content: response }); if (response.startsWith("TOOL")) { diff --git a/src/help.js b/src/help.js index 798b9c1..b7a4476 100644 --- a/src/help.js +++ b/src/help.js @@ -9,7 +9,10 @@ function printHelp() { const toolLabel = (name) => `[${name}]`; const toolsSummary = Object.entries(tools) - .map(([name, details]) => ` ${toolLabel(name).padEnd(16, " ")} ${details.description}`) + .map( + ([name, details]) => + ` ${toolLabel(name).padEnd(16, " ")} ${details.description}`, + ) .join("\n"); const lines = [ @@ -33,4 +36,9 @@ function printHelp() { console.log(lines.join("\n")); } -module.exports = { printHelp }; \ No newline at end of file +function calculateResponseTime(startTime, endTime) { + const diffMs = endTime - startTime; + const diffSnd = diffMs / 1000; + return diffSnd; +} +module.exports = { printHelp, calculateResponseTime }; diff --git a/src/llm.js b/src/llm.js index a1c9b3a..32013e5 100644 --- a/src/llm.js +++ b/src/llm.js @@ -2,8 +2,13 @@ const { GoogleGenAI } = require("@google/genai"); require("dotenv").config({ quiet: true }); async function askLLM(messages) { - if (!process.env.GEMINI_API_KEY || process.env.GEMINI_API_KEY === "your_gemini_api_key_here") { - console.error("\x1b[31mError: GEMINI_API_KEY is not configured.\x1b[0m\n Copy \x1b[33m.env.example\x1b[0m to \x1b[33m.env\x1b[0m and add your API key from \x1b[34mhttps://aistudio.google.com/app/apikey\x1b[0m"); + if ( + !process.env.GEMINI_API_KEY || + process.env.GEMINI_API_KEY === "your_gemini_api_key_here" + ) { + console.error( + "\x1b[31mError: GEMINI_API_KEY is not configured.\x1b[0m\n Copy \x1b[33m.env.example\x1b[0m to \x1b[33m.env\x1b[0m and add your API key from \x1b[34mhttps://aistudio.google.com/app/apikey\x1b[0m", + ); process.exit(1); }