How truefoundry/trueforge works
Purpose and Entry Points
TrueForge is an open-source agent harness: it executes LLM agent turns with sessions, streaming, tools, approvals, skills, sandboxing, and context management. The deployable Node.js server starts through packages/trueforge/src/main.ts; CLI/local startup is packages/trueforge/src/cli.ts. The HTTP application is assembled in packages/trueforge/src/app.ts; scheduled work has a separate controller entry point at packages/trueforge/src/controller-main.ts.
Server API and Contract Boundary
The server exposes REST/SSE endpoints for agents, sessions/turns, configuration resources, schedules, metrics, and authentication. Route definitions separate transport from API implementations:
• packages/trueforge/src/routes/sessionRoutes.ts
• packages/trueforge/src/routes/turnRoutes.ts
• packages/trueforge/src/apis/sessions.ts
Request/response schemas in packages/trueforge/src/schemas/ are the server’s validation boundary. OpenAPI is emitted from the server and drives generated client SDKs via .github/fern/openapi/openapi.json.
Agent Execution Core
@truefoundry/trueforge-core contains runtime-agnostic execution logic. An incoming turn resolves its agent/session resources, creates an agent thread, invokes the model, processes streamed events/tool calls, and persists thread/turn state. Main orchestration seams:
• packages/trueforge-core/src/core/runtime/AgentThreadOrchestrator.ts
• packages/trueforge-core/src/core/runtime/AgentThread.ts
• packages/trueforge-core/src/agent-session/Sessions.ts
The LLM interface decouples orchestration from providers; the supplied adapter uses the Vercel AI stack/OpenAI-shaped messages: packages/trueforge-core/src/core/llm/ILLM.ts and packages/trueforge-core/src/core/llm/VercelAILLM.ts.
Tools, Capabilities, and Human Interaction
Agent specifications enable built-in capabilities such as context compaction, deferred/large tool responses, web search, OpenUI, dynamic subagents, and ask-user prompts. Capabilities modify context or tool-response handling around the core loop:
• packages/trueforge-core/src/core/capabilities/AgentCapability.ts
• packages/trueforge-core/src/core/capabilities/builtins/ContextCompaction.ts
• packages/trueforge-core/src/core/capabilities/builtins/DynamicSubAgents.ts
MCP is the primary external-tool boundary. Local and remote server adapters normalize available tools, select/load them, execute calls, and surface authorization/approval events: packages/trueforge-core/src/core/mcp/RemoteMCP.ts, packages/trueforge-core/src/core/mcp/ToolSet.ts, packages/trueforge-core/src/core/mcp/executeToolCalls.ts.
Persistence, Identity, and Runtime Coordination
The server abstracts agents, sessions, providers, skills, OAuth tokens, schedules, and metrics behind stores, with SQLite for local mode and Postgres for hosted mode. Core examples are packages/trueforge/src/db/sqlite/session-store/SqliteSessionStore.ts and packages/trueforge/src/db/postgres/session-store/PostgresSessionStore.ts. Migrations live alongside each implementation.
Authentication/authorization is configurable, including standalone and OIDC modes: packages/trueforge/src/auth/createAuthenticator.ts and packages/trueforge/src/auth/authorizer.ts. Hosted multi-replica coordination uses Redis for event subscriptions and runtime state: packages/trueforge/src/runtime/event-subscription/redis.ts, packages/trueforge/src/runtime/redis.ts.
Sandboxes and Scheduled Execution
Sandboxing is a provisioned-on-demand tool execution boundary. Core supports Daytona and TrueFoundry sandbox providers plus NATS-based Code Mode transport: packages/trueforge-core/src/core/sandbox/Sandbox.ts, packages/trueforge-core/src/core/sandbox/provider/DaytonaProvider.ts, packages/trueforge-core/src/core/sandbox/codeMode/nats/CodeModeNatsTransport.ts. The server also implements a local sandbox provider under packages/trueforge/src/sandbox/local/provider/LocalSandboxProvider.ts.
Schedules are persisted then dispatched by the controller, which creates unattended session work: packages/trueforge/src/controller/Controller.ts and packages/trueforge/src/controller/scheduleDispatch.ts.
Clients, UI, and Deployment
Generated TypeScript and Python SDKs consume the HTTP contract: packages/trueforge-sdk/src/Client.ts and python/trueforge_sdk/src/trueforge_sdk/client.py. The bundled React frontend boots at packages/frontend/src/main.ts; the embeddable UI package composes chat/server adapters through packages/trueforge-ui/src/containers/TrueForgeUI.tsx and packages/trueforge-ui/src/plugins/trueforge-agent-server-adapter/client.ts.
Runtime targets are Node.js 22.14+, Docker Compose, Railway, and Kubernetes Helm. Production topology is server/controller plus Postgres and Redis; Helm manifests define both application and controller deployments: charts/trueforge/templates/deployment.yaml and charts/trueforge/templates/controller-deployment.yaml.
Main entry points: app.ts HTTP application · AgentThread.ts Agent thread · AgentThreadOrchestrator.ts Agent thread orchestrator · sessionRoutes.ts REST and SSE routes
Components 22
Node.js Server
- Server entry
packages/trueforge/src/main.ts - CLI / local startup
packages/trueforge/src/cli.ts - HTTP application
packages/trueforge/src/app.ts - REST and SSE routes
packages/trueforge/src/routes/sessionRoutes.ts - Session API
packages/trueforge/src/apis/sessions.ts - Request/response schemas · Also emits the OpenAPI contract.
- Authentication & authorization
packages/trueforge/src/auth/createAuthenticator.ts
Execution Core
- Agent thread orchestrator
packages/trueforge-core/src/core/runtime/AgentThreadOrchestrator.ts - Agent thread · Processes streaming events and tool calls.
packages/trueforge-core/src/core/runtime/AgentThread.ts - Session runtime
packages/trueforge-core/src/agent-session/Sessions.ts - LLM interface & Vercel adapter
packages/trueforge-core/src/core/llm/ILLM.ts - Agent capabilities · Includes compaction and dynamic subagents.
packages/trueforge-core/src/core/capabilities/AgentCapability.ts - MCP tool boundary · Normalizes, loads, and executes local or remote tools.
packages/trueforge-core/src/core/mcp/ToolSet.ts - Sandbox providers · Daytona, TrueFoundry, local, and NATS Code Mode.
packages/trueforge-core/src/core/sandbox/Sandbox.ts
Hosted Runtime
- Resource stores · Agents, sessions, providers, skills, tokens, schedules, and metrics.
packages/trueforge/src/db/sqlite/session-store/SqliteSessionStore.ts - Postgres
packages/trueforge/src/db/postgres/session-store/PostgresSessionStore.ts - Redis coordination
packages/trueforge/src/runtime/redis.ts - Schedule controller · Creates unattended session work.
packages/trueforge/src/controller/Controller.ts - Helm deployments · Deploys server and controller replicas.
charts/trueforge/templates/deployment.yaml
Clients & UI
- Generated SDKs · Generated from the emitted OpenAPI contract.
packages/trueforge-sdk/src/Client.ts - Bundled React frontend
- Embeddable TrueForge UI
packages/trueforge-ui/src/containers/TrueForgeUI.tsx
Connections 23
- Server entry → HTTP application: starts
- CLI / local startup → HTTP application: starts locally
- HTTP application → Authentication & authorization: authenticates requests
- HTTP application → REST and SSE routes: mounts
- REST and SSE routes → Session API: dispatches
- REST and SSE routes → Request/response schemas: validates with
- Session API → Agent thread orchestrator: starts turns
- Agent thread orchestrator → Session runtime: resolves and persists
- Agent thread orchestrator → Agent thread: creates
- Agent thread → LLM interface & Vercel adapter: invokes model
- Agent thread → Agent capabilities: applies
- Agent thread → MCP tool boundary: executes tool calls
- MCP tool boundary → Sandbox providers: uses isolated tools
- Session runtime → Resource stores: uses
- Resource stores → Postgres: hosted implementation
- HTTP application → Redis coordination: coordinates replicas
- Schedule controller → Resource stores: reads schedules
- Schedule controller → Agent thread orchestrator: dispatches unattended work
- Request/response schemas → Generated SDKs: OpenAPI generates
- Bundled React frontend → HTTP application: consumes API
- Embeddable TrueForge UI → HTTP application: uses server adapter
- Helm deployments → Server entry: deploys server
- Helm deployments → Schedule controller: deploys controller