AgentSea

Guide

Local models

Run agents against models on your own machine or on a self-hosted server that speaks the OpenAI chat API.

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 is http://localhost:11434, or the value of OLLAMA_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 optional apiKey and defaultHeaders.

Note

Default ports: LM Studio 1234, LocalAI 8080, vLLM 8000 and Text Generation WebUI 5000. Confirm these for your setup.

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'.

TS
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

Do not call 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.
BASH
ollama serve
ollama pull llama3

04Streaming

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.

TS
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

The streaming method is executeStream.

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.

BASH
export OLLAMA_BASE_URL=http://localhost:11434

06Troubleshooting

  • 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.