01Providers
The core package exports one provider class for Ollama. The other local servers use the OpenAI-compatible provider class.
OllamaProvider: Ollama. The default base URL ishttp://localhost:11434, or the value ofOLLAMA_BASE_URL.LMStudioProvider: LM Studio's local server.LocalAIProvider: LocalAI.VLLMProvider: vLLM's OpenAI-compatible server.TextGenerationWebUIProvider: Text Generation WebUI, with its OpenAI extension enabled.OpenAICompatibleProvider: any server that implements the OpenAI chat API. Takes an optionalapiKeyanddefaultHeaders.
Note
02Run a model with Ollama
Pass the provider to the Agent constructor with the agent config and a ToolRegistry. The config's provider field is the string 'ollama'.
import { Agent, OllamaProvider, ToolRegistry } from '@lov3kaizen/agentsea-core';
const provider = new OllamaProvider({ baseUrl: 'http://localhost:11434', timeout: 60000 });
await provider.pullModel('llama3');
const agent = new Agent(
{ name: 'local-assistant', description: 'Local assistant', model: 'llama3', provider: 'ollama' },
provider,
new ToolRegistry(),
);
const response = await agent.execute('Hello!', {
conversationId: 'conv-1',
sessionData: {},
history: [],
});
console.log(response.content);Warning
agent.registerProvider. Pass the provider to the Agent constructor, as shown here.03Ollama setup
Install Ollama, start the server, and pull a model.
OllamaProvider has two helpers. listModels() returns the names of the installed models. pullModel(name) downloads a model.
- llama3, mistral and mixtral: general purpose.
- codellama and deepseek-coder: code.
- phi, gemma and tinyllama: smaller models.
ollama serve
ollama pull llama304Streaming
Agent.executeStream yields event objects. Content chunks have type 'content' and a content string. The stream ends with a 'done' event, or an 'error' event if the run fails.
const context = { conversationId: 'conv-2', sessionData: {}, history: [] };
for await (const event of agent.executeStream('Tell me a short story', context)) {
if (event.type === 'content') {
process.stdout.write(event.content ?? '');
}
}Note
05Environment variables
OllamaProvider reads OLLAMA_BASE_URL when no baseUrl is passed. Other local providers take their base URL and key in the constructor. The core package does not read LMSTUDIO_BASE_URL, LOCALAI_BASE_URL, CUSTOM_LLM_BASE_URL or CUSTOM_LLM_API_KEY.
export OLLAMA_BASE_URL=http://localhost:1143406Troubleshooting
- Timeouts on slow hardware: raise the timeout option. OllamaProvider defaults to 60000 ms.
- Model not found: pull the model first with pullModel() or ollama pull.
- Out of memory: use a smaller or quantized model and shorten maxTokens.