Local Development
Provider: Ollama
Best for: Privacy, offline work, no API costs
Models: phi4-mini:latest
, gemma3:4b
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
provider
ProviderType
"ollama"
model
string
"gemma3:4b"
modelConfig
ModelConfig
undefined
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");
import { AgentForceAgent } from '@agentforce/adk';
const agent = new AgentForceAgent({ name: "StoryAgent"}) .useLLM("ollama", "phi4-mini:latest") .prompt("Write a short story");
const response = await agent.output("text");
import { AgentForceAgent } from '@agentforce/adk';
const agent = new AgentForceAgent({ name: "AnalysisAgent"}) .useLLM("openrouter", "moonshotai/kimi-k2:free") .systemPrompt("You are a data analyst") .prompt("Analyze this data");
const response = await agent.output("json");
import { AgentForceAgent } from '@agentforce/adk';
const agent = new AgentForceAgent({ name: "GeminiAgent"}) .useLLM("google", "gemini-1.5-flash") .prompt("Explain quantum computing");
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 developmentconst devAgent = new AgentForceAgent({ name: "DevAgent" }) .useLLM("ollama", "phi4-mini:latest");
// OpenRouter for productionconst prodAgent = new AgentForceAgent({ name: "ProdAgent" }) .useLLM("openrouter", "moonshotai/kimi-k2:free");
// Google Gemini for specific tasksconst geminiAgent = new AgentForceAgent({ name: "GeminiAgent" }) .useLLM("google", "gemini-2.5-flash");
// Switch providers on the same agentconst 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");
phi4-mini-reasoning
~4GB
Good
gemma3:4b
~4GB
Fast
gpt-oss:20b
~13GB
Fast
moonshotai/kimi-k2:free
Moonshot
Free
mistralai/mistral-small
Mistral
Low
gemini-1.5-flash
Fast responses
High
gemini-1.5-pro
Complex tasks
Very High
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 Ollamaconst devAgent = new AgentForceAgent({ name: "DevAgent" }) .useLLM("ollama", "phi4-mini:latest", { temperature: 0.3 });
// Production - Use cloud providerconst prodAgent = new AgentForceAgent({ name: "ProdAgent" }) .useLLM("openrouter", "mistralai/mistral-small", { maxTokens: 2048 });
// Creative tasks - Higher temperatureconst creativeAgent = new AgentForceAgent({ name: "CreativeAgent" }) .useLLM("google", "gemini-1.5-pro", { temperature: 0.8 });
// Factual tasks - Lower temperatureconst 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.}
.systemPrompt()
- Set system instructions.prompt()
- Set the main prompt.output()
- Execute and get response.debug()
- Enable debug logging