Skip to main content
Every Runflow project follows a simple convention: a main.ts file at the root that exports an async function main(). As your project grows, you organize code into folders that map directly to SDK concepts.

Entry Point: main.ts

The main.ts file is the only required file. It must export an async function main(input) — this is the contract between your code and the Runflow engine.
main.ts
What main() receives:
  • input.message — the user’s message (always present)
  • input.sessionId — session identifier (for memory continuity)
  • input.email, input.phone — user identifiers (depends on your integration)
  • Any other fields your integration sends
What main() returns:
  • An object with at least message — the agent’s response
  • Any additional metadata you want to pass back

Project Sizes

Simple Project

For a basic agent with one or two tools, keep everything minimal:

Medium Project

When you have multiple tools and want better organization:

Complex Project

For enterprise agents with workflows, connectors, and integrations:

Folder Guide

tools/

One file per tool. Each file exports a single tool created with createTool().
tools/create-ticket.ts
Use an index.ts to re-export all tools:
tools/index.ts
Then import them cleanly in your agent:
agent.ts

prompts/

Centralize your prompts in a dedicated file, especially when they’re long or have multiple scenarios:
prompts/index.ts
For prompts managed through the Runflow portal, use loadPrompt() instead of local files. See Prompts for details.

workflows/

Store workflow definitions in dedicated files:
workflows/lead-qualification.ts

connectors/

When using multiple connectors, configure them in dedicated files:
connectors/hubspot.ts

config/

For projects with many constants, enums, or configuration values:
config/settings.ts

Separating the Agent from main.ts

As your project grows, move the agent definition to its own file. This keeps main.ts focused on orchestration:
agent.ts
main.ts

Next Steps

Best Practices

Tips for writing effective agents

Tools

Learn how to create tools

Workflows

Build multi-step workflows

Prompts

Manage prompt templates