Skip to Content
UtilitiesgetTemperature

getTemperature

Problem

When you build an agent config, temperature is easy to forget — and some LLM providers behave unpredictably when temperature is undefined. Every agent you create needs a reliable default applied consistently without repeating the same null-check logic across files.


Solution

getTemperature takes your AgentConfig and returns a new config object with temperature guaranteed to be set. If you provided a temperature, it stays. If you did not, it defaults to 0.7. That is all it does — one responsibility, done cleanly.


Feature & Use-Case

Use getTemperature when:

  • You are building a custom agent wrapper and need to normalize the config before passing it to a provider
  • You want a guaranteed temperature on every config object without conditional logic in multiple places
  • You are building an agent factory that accepts partial configs from users

Import

import { getTemperature } from "llm-layer-engine";

Function Signature

function getTemperature(config: AgentConfig): AgentConfig

Parameters

ParameterTypeRequiredDescription
configAgentConfigYour agent config object
config.temperaturenumberOptional. Defaults to 0.7 if not provided

Return Value

Returns a new AgentConfig object — same as input, but with temperature always set.


Example — Basic Usage

import { getTemperature } from "llm-layer-engine"; const rawConfig = { provider: myProvider, model: "claude-3-5-sonnet-20241022", // temperature not set }; const finalConfig = getTemperature(rawConfig); console.log(finalConfig.temperature); // → 0.7

Example — Temperature Provided

const rawConfig = { provider: myProvider, model: "claude-3-5-sonnet-20241022", temperature: 0.2, }; const finalConfig = getTemperature(rawConfig); console.log(finalConfig.temperature); // → 0.2 (your value preserved)

Example — Inside a Custom Agent Factory

import { getTemperature } from "llm-layer-engine"; import type { AgentConfig } from "llm-layer-engine"; function buildMyAgent(partialConfig: Partial<AgentConfig>) { const safeConfig = getTemperature({ provider: myProvider, model: "claude-3-5-sonnet-20241022", ...partialConfig, }); // safeConfig.temperature is always defined here return safeConfig; }

Conclusion

getTemperature is a small but important utility. It removes the need for null-checking temperature in every file that touches agent config. Use it at the boundary where configs enter your system — factory functions, config builders, or agent initialization — and downstream code can always trust that config.temperature is a number.

Last updated on