Configuration

Complete configuration reference for the TypeScript SDK

AgentConfig

Main configuration interface for creating an Agent.

import { Agent } from '@agentfield/sdk';

const agent = new Agent({
  nodeId: 'my-agent',
  agentFieldUrl: 'http://localhost:8080',
  port: 8001,
  aiConfig: { model: 'gpt-4o' },
  memoryConfig: { defaultScope: 'workflow' },
  didEnabled: true,
  devMode: false
});

Prop

Type

AIConfig

Configure LLM behavior, rate limiting, and circuit breaker.

const agent = new Agent({
  nodeId: 'my-agent',
  aiConfig: {
    provider: 'openai',
    model: 'gpt-4o',
    temperature: 0.7,
    maxTokens: 2000,
    enableRateLimitRetry: true,
    rateLimitMaxRetries: 20,
    rateLimitBaseDelay: 1.0,
    rateLimitMaxDelay: 300.0
  }
});

Prop

Type

The SDK auto-detects provider based on environment variables: OPENROUTER_API_KEY triggers OpenRouter, otherwise OPENAI_API_KEY is used for OpenAI.

Provider Examples

const agent = new Agent({
  nodeId: 'my-agent',
  aiConfig: {
    provider: 'openai',
    model: 'gpt-4o',
    apiKey: process.env.OPENAI_API_KEY
  }
});
const agent = new Agent({
  nodeId: 'my-agent',
  aiConfig: {
    provider: 'openrouter',
    model: 'anthropic/claude-3-5-sonnet',
    apiKey: process.env.OPENROUTER_API_KEY
  }
});
const agent = new Agent({
  nodeId: 'my-agent',
  aiConfig: {
    provider: 'anthropic',
    model: 'claude-3-5-sonnet-20241022',
    apiKey: process.env.ANTHROPIC_API_KEY
  }
});
const agent = new Agent({
  nodeId: 'my-agent',
  aiConfig: {
    provider: 'ollama',
    model: 'llama3.2',
    baseUrl: 'http://localhost:11434/v1'
  }
});

MemoryConfig

Configure default memory behavior.

const agent = new Agent({
  nodeId: 'my-agent',
  memoryConfig: {
    defaultScope: 'workflow',
    ttl: 3600
  }
});

Prop

Type

Environment Variables

The SDK reads these environment variables:

# AI Provider (auto-detected based on which key is set)
OPENAI_API_KEY="sk-..."
OPENROUTER_API_KEY="sk-or-v1-..."
ANTHROPIC_API_KEY="sk-ant-..."

# Model Configuration
AI_MODEL="gpt-4o"
AI_BASE_URL="https://api.openai.com/v1"

# Control Plane
AGENTFIELD_URL="http://localhost:8080"

Environment variables are overridden by explicit configuration passed to the Agent constructor.

Complete Example

import { Agent } from '@agentfield/sdk';

const agent = new Agent({
  // Identity
  nodeId: 'production-agent',
  version: '2.0.0',
  teamId: 'engineering',

  // Server
  port: 8080,
  host: '0.0.0.0',
  publicUrl: 'https://agent.company.com',

  // Control Plane
  agentFieldUrl: 'https://agentfield.company.com',
  heartbeatIntervalMs: 5000,

  // AI Configuration
  aiConfig: {
    provider: 'openai',
    model: 'gpt-4o',
    temperature: 0.7,
    maxTokens: 4000,
    enableRateLimitRetry: true,
    rateLimitMaxRetries: 20,
    rateLimitBaseDelay: 1.0,
    rateLimitMaxDelay: 300.0,
    rateLimitCircuitBreakerThreshold: 10
  },

  // Memory
  memoryConfig: {
    defaultScope: 'workflow'
  },

  // Features
  didEnabled: true,
  devMode: false,
  deploymentType: 'long_running',

  // Headers
  defaultHeaders: {
    'X-Team-ID': 'engineering'
  }
});

await agent.serve();