Skip to content

AgentForceServer


AgentForceServer Server Class HTTP Server

Technical documentation for the AgentForceServer class structure and API.

/**
* Represents a server instance within the AgentForce framework.
* This class provides the core functionality for creating and managing servers,
* including configuration of name and logging.
*
* @class AgentForceServer
*/
import {
serve,
addRouteAgent,
addRoute,
addFormTrigger,
addWorkflowTrigger,
useOpenAICompatibleRouting,
useOllamaCompatibleRouting,
type RouteAgent,
type StaticRoute,
type RouteAgentSchema,
} from "./server/mod";
import type { AgentForceAgent } from "./agent";
import type { ServerConfig, AgentForceLogger } from "./types";
import { defaultLogger } from "./logger";
constructor(config: ServerConfig)

Parameters:

  • config: ServerConfig - Configuration object containing server initialization settings

Description: Constructs the AgentForceServer class with the provided configuration. Initializes the server’s name and logger from the config object.

private name: string;
private serverLogger: AgentForceLogger;
private routeAgents: RouteAgent[] = [];
private staticRoutes: StaticRoute[] = [];

None - All methods are public in this class.

public getName(): string
public getLogger(): AgentForceLogger
public getRouteAgents(): RouteAgent[]
public getStaticRoutes(): StaticRoute[]
public addToRouteAgents(routeAgent: RouteAgent): void
public addToStaticRoutes(staticRoute: StaticRoute): void

Returns AgentForceServer instance for method chaining:

addRouteAgent(method: string, path: string, agent: AgentForceAgent, schema?: RouteAgentSchema): AgentForceServer
addRoute(method: string, path: string, responseData: any): AgentForceServer
addFormTrigger(formName: string, htmlFilePath: string, agent: AgentForceAgent, schema?: RouteAgentSchema): AgentForceServer
addWorkflowTrigger(method: string, path: string, workflowFilePath: string): AgentForceServer
useOpenAICompatibleRouting(agent: AgentForceAgent): AgentForceServer
useOllamaCompatibleRouting(agent: AgentForceAgent): AgentForceServer

Execute the server and return results (ends the chain):

serve(host?: string, port?: number): Promise<void>

All public methods are bound to their respective implementations from the ./server/mod module:

// Chainable methods
addRouteAgent: (method: string, path: string, agent: AgentForceAgent, schema?: RouteAgentSchema) => AgentForceServer = addRouteAgent.bind(this);
addRoute: (method: string, path: string, responseData: any) => AgentForceServer = addRoute.bind(this);
addFormTrigger: (formName: string, htmlFilePath: string, agent: AgentForceAgent, schema?: RouteAgentSchema) => AgentForceServer = addFormTrigger.bind(this);
addWorkflowTrigger: (method: string, path: string, workflowFilePath: string) => AgentForceServer = addWorkflowTrigger.bind(this);
useOpenAICompatibleRouting: (agent: AgentForceAgent) => AgentForceServer = useOpenAICompatibleRouting.bind(this);
useOllamaCompatibleRouting: (agent: AgentForceAgent) => AgentForceServer = useOllamaCompatibleRouting.bind(this);
// Terminal/Non-chainable methods
serve: (host?: string, port?: number) => Promise<void> = serve.bind(this);