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
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
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
index.ts to re-export all tools:
tools/index.ts
agent.ts
prompts/
Centralize your prompts in a dedicated file, especially when they’re long or have multiple scenarios:
prompts/index.ts
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