Skip to content

.useLLM()


AgentForceAgent Optional Chainable

Configure the Large Language Model (LLM) provider and specific model that the agent will use for processing tasks. All parameters are optional with sensible defaults (provider="ollama", model="gemma3:4b").

useLLM(provider?: ProviderType, model?: string, modelConfig?: ModelConfig): AgentForceAgent
Parameter
Type
Default
Description
provider
ProviderType
"ollama"
The LLM provider ("ollama", "openrouter", "google", "openai", "anthropic")
model
string
"gemma3:4b"
The specific model name/identifier
modelConfig
ModelConfig
undefined
Optional model configuration (temperature, maxTokens, etc.)

Returns the AgentForceAgent instance for method chaining.

import { AgentForceAgent } from '@agentforce/adk';
// Uses default: provider="ollama", model="gemma3:4b"
const agent = new AgentForceAgent({
name: "DefaultAgent"
})
.useLLM()
.prompt("Write a short story");
const response = await agent.output("text");

Configure temperature, max tokens, and other model parameters:

import { AgentForceAgent } from '@agentforce/adk';
const agent = new AgentForceAgent({ name: "CreativeAgent" })
.useLLM("ollama", "phi4-mini:latest", {
temperature: 0.8,
maxTokens: 8192
})
.prompt("Write a creative story");
const response = await agent.output("text");

The useLLM() method supports fluent chaining with other AgentForceAgent methods:

const agent = new AgentForceAgent({ name: "ChatBot" })
.useLLM("ollama", "gemma3:4b")
.systemPrompt("You are a helpful assistant")
.prompt("What is the capital of France?")
.debug();
const response = await agent.output("text");
// Local Ollama for development
const devAgent = new AgentForceAgent({ name: "DevAgent" })
.useLLM("ollama", "phi4-mini:latest");
// OpenRouter for production
const prodAgent = new AgentForceAgent({ name: "ProdAgent" })
.useLLM("openrouter", "moonshotai/kimi-k2:free");
// Google Gemini for specific tasks
const geminiAgent = new AgentForceAgent({ name: "GeminiAgent" })
.useLLM("google", "gemini-2.5-flash");
// Switch providers on the same agent
const flexibleAgent = new AgentForceAgent({ name: "FlexAgent" })
.useLLM("ollama", "llama2")
.useLLM("google", "gemini-2.5-flash"); // Overrides previous setting

The useLLM() method supports fluent chaining with other AgentForceAgent methods:

const agent = new AgentForceAgent({ name: "ChainedAgent" })
.useLLM("ollama", "phi4-mini:latest")
.systemPrompt("You are a helpful assistant")
.prompt("Explain machine learning")
.debug();
const response = await agent.output("text");
Parameter
Type
Default
Description
phi4-mini-reasoning
~4GB
Good
Balances efficiency with advanced reasoning ability
gemma3:4b
~4GB
Fast
Balanced performance - **Default model**
gpt-oss:20b
~13GB
Fast
General purpose - Stable, reliable
Parameter
Type
Default
Description
moonshotai/kimi-k2:free
Moonshot
Free
Free tier usage - Good for testing
mistralai/mistral-small
Mistral
Low
General tasks - Cost-effective
Parameter
Type
Default
Description
gemini-1.5-flash
Fast responses
High
Optimized for speed
gemini-1.5-pro
Complex tasks
Very High
Most capable
interface ModelConfig {
temperature?: number; // 0.0 to 2.0 (creativity level)
maxTokens?: number; // Maximum response length
topP?: number; // 0.0 to 1.0 (nucleus sampling)
// Additional provider-specific options
}

Local Development

Provider: Ollama

Best for: Privacy, offline work, no API costs

Models: phi4-mini:latest, gemma3:4b

Production Scale

Provider: OpenRouter

Best for: Scalability, latest models, reliability

Models: mistralai/mistral-small, moonshotai/kimi-k2:free

Creative Tasks

Provider: Google Gemini

Best for: Content generation, complex reasoning

Models: gemini-1.5-pro, gemini-1.5-flash

Fast Responses

Provider: Multiple

Best for: Quick interactions, chatbots

Models: gemma3:4b, gemini-1.5-flash

// Development - Use local Ollama
const devAgent = new AgentForceAgent({ name: "DevAgent" })
.useLLM("ollama", "phi4-mini:latest", { temperature: 0.3 });
// Production - Use cloud provider
const prodAgent = new AgentForceAgent({ name: "ProdAgent" })
.useLLM("openrouter", "mistralai/mistral-small", { maxTokens: 2048 });
// Creative tasks - Higher temperature
const creativeAgent = new AgentForceAgent({ name: "CreativeAgent" })
.useLLM("google", "gemini-1.5-pro", { temperature: 0.8 });
// Factual tasks - Lower temperature
const factualAgent = new AgentForceAgent({ name: "FactualAgent" })
.useLLM("ollama", "gemma3:4b", { temperature: 0.1 });
// Wrong model name
.useLLM("ollama", "non-existent-model") // Check available models
// High temperature for factual tasks
.useLLM("google", "gemini-1.5-flash", { temperature: 1.5 }) // Use 0.1-0.3
// Large model when small works
.useLLM("ollama", "llama2:70b") // Consider gemma3:4b for most tasks
// Missing error handling
// Always wrap in try/catch for production
try {
const agent = new AgentForceAgent({ name: "SafeAgent" })
.useLLM("ollama", "gemma3:4b")
.prompt("Test prompt");
const response = await agent.output("text");
console.log(response);
} catch (error) {
console.error("LLM Error:", error.message);
// Handle provider unavailable, model not found, etc.
}