agente-toolkit
Version:
A barebones TypeScript library for building AI agents with intelligent tool execution and self-correction capabilities
83 lines (80 loc) • 2.77 kB
JavaScript
;
/**
* Utility class that provides specialized logging methods using the basic AgentLogger interface.
* This helps maintain rich logging semantics while using the injectable logger pattern.
*/
class LoggerUtils {
constructor(logger) {
this.logger = logger;
}
logPrompt(prompt, meta) {
this.logger.debug('Sending prompt to model', {
prompt: this.truncateForLog(prompt, 100),
...meta,
});
}
logModelResponse(response, meta) {
this.logger.debug('Received model response', {
response: this.truncateForLog(response, 100),
...meta,
});
}
logPlanCreation(message, tools, plan) {
var _a;
this.logger.info('Created execution plan', {
userMessage: message,
availableTools: tools.map(t => t.name),
planSteps: ((_a = plan.steps) === null || _a === void 0 ? void 0 : _a.length) || 0,
});
}
logToolExecution(toolName, params, result, duration) {
this.logger.info(`Executed tool: ${toolName}`, {
tool: toolName,
params: typeof params === 'object' ? Object.keys(params) : params,
result: this.truncateForLog(String(result), 50),
duration: duration ? `${duration}ms` : undefined,
});
}
logParameterResolution(stepId, originalParams, resolvedParams) {
this.logger.debug(`Resolved parameters for ${stepId}`, {
stepId,
original: originalParams,
resolved: resolvedParams,
});
}
logMemoryOperation(operation, details) {
this.logger.debug(`Memory operation: ${operation}`, details);
}
logValidationError(toolName, errors) {
this.logger.warn(`Parameter validation failed for ${toolName}`, {
tool: toolName,
errors,
});
}
logAgentStart(agentType) {
this.logger.info('Agent session started', { agentType });
}
logAgentEnd() {
this.logger.info('Agent session ended');
}
logRunStart(meta) {
this.logger.info('Run started', meta);
}
logRunEnd(meta) {
this.logger.info('Run ended', meta);
}
logStepStart(stepId, toolName, meta) {
this.logger.debug(`Step started: ${stepId}`, { stepId, toolName, ...meta });
}
logStepEnd(stepId, toolName, durationMs, meta) {
this.logger.info(`Step ended: ${stepId}`, { stepId, toolName, duration: durationMs, ...meta });
}
truncateForLog(text, maxLength) {
if (text.length <= maxLength) {
return text;
}
return `${text.substring(0, maxLength)}...`;
}
}
exports.LoggerUtils = LoggerUtils;
//# sourceMappingURL=loggerUtils.js.map