AgentSea

Concept

Agents

Agents are the core building blocks of AgentSea. They represent autonomous AI entities that can reason, use tools, and maintain conversation context.

01What is an agent?

An agent in AgentSea is an intelligent entity powered by a Large Language Model (LLM) that can:

  • Process natural language inputs and generate responses
  • Use tools to perform actions (API calls, file operations, calculations, etc.)
  • Maintain conversation history and context
  • Make decisions about which tools to use and when
  • Stream responses for real-time interactions

02Creating an agent

Here is a basic example of creating an agent:

TS
import {
  Agent,
  AnthropicProvider,
  ToolRegistry,
  BufferMemory,
} from '@lov3kaizen/agentsea-core';

// Provider, tool registry and memory
const provider = new AnthropicProvider(process.env.ANTHROPIC_API_KEY);
const toolRegistry = new ToolRegistry();
const memory = new BufferMemory(50); // Keep last 50 messages

// Create agent
const agent = new Agent(
  {
    name: 'customer-support-agent',
    description: 'A helpful customer support assistant',
    model: 'claude-sonnet-4-6',
    provider: 'anthropic',
    systemPrompt: 'You are a friendly customer support agent...',
    tools: [],
    temperature: 0.7,
    maxTokens: 2048,
  },
  provider,
  toolRegistry,
  memory,
);

03Configuration

The agent configuration object accepts the following properties:

name: string
Unique identifier for the agent.
description: string
What the agent is for.
model: string
LLM model ID, for example claude-sonnet-4-6.
provider: string
Provider name, for example anthropic, openai, gemini or ollama.
systemPrompt?: string
Instructions for the agent's behavior.
tools?: Tool[]
Tools the agent can call.
temperature?: number
Randomness. Lower is more focused. The Anthropic provider leaves temperature out for models that reject it.
maxTokens?: number
Maximum response length.
maxIterations?: number
Maximum LLM calls in one execution, including tool-call rounds. Defaults to 10.

04Executing an agent

To execute an agent, call execute() with an input string and a context:

TS
const response = await agent.execute(
  'What is the weather like today?',
  {
    conversationId: 'user-123',
    sessionData: { userId: '123', location: 'San Francisco' },
    history: [],
  },
);

console.log(response.content); // Agent's response
console.log(response.toolCalls); // Tool calls made during the run
console.log(response.metadata); // tokensUsed, latencyMs, iterations

Note

When the agent has a memory store, history is loaded from it by conversationId. context.history is only used when no memory store is configured.

05Streaming responses

For real-time interactions, use executeStream() to receive events as they are generated:

TS
for await (const event of agent.executeStream(
  'Write a story about a robot',
  context,
)) {
  if (event.type === 'content') {
    process.stdout.write(event.content);
  } else if (event.type === 'tool_calls') {
    for (const call of event.toolCalls) {
      console.log('Using tool:', call.tool);
    }
  } else if (event.type === 'error') {
    console.error(event.error);
  }
}

Other event types are iteration, tool_result and done, which carries the run metadata.

06Agents with tools

Agents become powerful when equipped with tools:

TS
import {
  Agent,
  AnthropicProvider,
  ToolRegistry,
  calculatorTool,
  httpRequestTool,
} from '@lov3kaizen/agentsea-core';

// Register tools
const toolRegistry = new ToolRegistry();
toolRegistry.register(calculatorTool);
toolRegistry.register(httpRequestTool);

// Create agent with tools
const agent = new Agent(
  {
    name: 'data-analyst',
    description: 'Fetches and analyzes data',
    model: 'claude-sonnet-4-6',
    provider: 'anthropic',
    systemPrompt: 'You are a data analyst that can fetch and analyze data.',
    tools: [calculatorTool, httpRequestTool],
  },
  new AnthropicProvider(),
  toolRegistry,
);

// The agent calls tools as the model requests them
const response = await agent.execute(
  'Fetch data from https://api.example.com/stats and calculate the average',
  context,
);

07Memory

Agents can use different memory stores to keep context across calls. The memory argument is optional. Each store implements the same save, load and clear interface.

TS
import {
  Agent,
  AnthropicProvider,
  BufferMemory, // In-memory, simple
  RedisMemory, // Persistent, scalable
  SummaryMemory, // Summarizes older messages
} from '@lov3kaizen/agentsea-core';

// Option 1: Buffer memory, keeps the last 100 messages
const bufferMemory = new BufferMemory(100);

// Option 2: Redis memory, persistent
const redisMemory = new RedisMemory({
  host: 'localhost',
  port: 6379,
  ttl: 86400, // 24 hours, in seconds
});

// Option 3: Summary memory, keeps the most recent messages and summarizes the rest
const summaryMemory = new SummaryMemory(
  new AnthropicProvider(),
  20, // maxRecentMessages
  'claude-haiku-4-5', // summaryModel
);

const agent = new Agent(config, provider, toolRegistry, redisMemory);

For the full set of options, see the memory package reference.

08Multiple providers

Switch between Anthropic Claude and OpenAI by changing the provider instance:

TS
import {
  Agent,
  AnthropicProvider,
  OpenAIProvider,
  ToolRegistry,
} from '@lov3kaizen/agentsea-core';

const toolRegistry = new ToolRegistry();

// Anthropic Claude
const claudeAgent = new Agent(
  {
    name: 'claude-agent',
    description: 'Claude-backed agent',
    model: 'claude-sonnet-4-6',
    provider: 'anthropic',
  },
  new AnthropicProvider(),
  toolRegistry,
);

// OpenAI GPT
const gptAgent = new Agent(
  {
    name: 'gpt-agent',
    description: 'OpenAI-backed agent',
    model: 'gpt-4-turbo-preview',
    provider: 'openai',
  },
  new OpenAIProvider(),
  toolRegistry,
);

09Local providers

Run agents with local LLMs for privacy, cost savings and offline operation:

TS
import { Agent, OllamaProvider, ToolRegistry } from '@lov3kaizen/agentsea-core';

const toolRegistry = new ToolRegistry();

// Ollama
const localAgent = new Agent(
  {
    name: 'local-agent',
    description: 'Runs on a local Ollama server',
    model: 'llama3.2',
    provider: 'ollama',
    systemPrompt: 'You are a helpful assistant running locally.',
  },
  new OllamaProvider({
    baseUrl: 'http://localhost:11434',
    timeout: 60000,
  }),
  toolRegistry,
);

const response = await localAgent.execute('Hello!', context);
  • Data privacy: prompts and responses stay on your machine
  • No per-token API costs
  • Low latency: no network round trip to a hosted API
  • Works offline once the model is downloaded

Complete guide to local and open source providers

10Best practices

  • System prompts: write clear, specific system prompts that define the agent's role and behavior.
  • Temperature: use a lower temperature (0.0 to 0.3) for factual tasks and a higher one (0.7 to 1.0) for creative tasks.
  • Memory: choose the store for the job. Buffer for simple cases, Redis for production, Summary for long conversations.
  • Tools: only provide tools that are relevant to the agent's purpose.
  • Error handling: wrap agent execution in try/catch. Errors are rethrown as Agent execution failed: ....
  • Streaming: use streaming in interactive applications.

11Next steps