Logic Functions & Skills
Relevant source files
The following files were used as context for generating this wiki page:
- packages/twenty-codex-plugin/references/develop-app/logic.md
- packages/twenty-apps/internal/twenty-partners/src/skills/twenty-partner-design-doc/design-doc-doctrine.md
- packages/twenty-codex-plugin/skills/develop-app/SKILL.md
- packages/twenty-codex-plugin/AGENTS.md
- packages/twenty-apps/community/github-connector/src/tests/logic-functions.integration-test.ts
- packages/twenty-codex-plugin/CHANGELOG.md
Logic Functions and Skills represent the primary extensibility layer for automation, AI behavior, and server-side logic within Twenty apps. Logic Functions are server-side scripts that handle record-level operations, integrations, and complex business logic, while Skills and Agents leverage these functions to provide AI-driven interactions and context-aware assistance within the CRM.
These components are modular extensions of the Twenty platform, allowing developers to define custom triggers, bulk record processing, and third-party service connections. They are designed to be idempotent and efficient, often utilized in workflows or as standalone processing units.
Sources: packages/twenty-codex-plugin/references/develop-app/logic.md:3-8, packages/twenty-codex-plugin/AGENTS.md:10-15
Logic Functions Architecture
Logic Functions are structured to separate trigger registration and write operations from pure business logic and external service interactions. A standard logic function file contains the registration of triggers, input validation, and the final writes to the database.
Code Organization & Standards
The project enforces a strict separation of concerns for logic functions to ensure maintainability and testability:
- Trigger/Write Logic: Contained within the
*.logic-function.tsor*.post-install.tsfile. - Pure Helpers: Parsers and mappers are extracted to
src/utils/<name>.util.ts. - Types: DTOs and API types are defined in
src/types/<name>.ts. - External Clients: Wrappers for external SDKs are placed in
src/<service>-client/<name>.ts.
Sources: packages/twenty-codex-plugin/skills/develop-app/SKILL.md:43-51, packages/twenty-codex-plugin/references/develop-app/logic.md:7-13
Implementation Constraints
| Constraint | Description |
|---|---|
| Soft Cap | Files exceeding 200 lines should be refactored. |
| Exports | One export per file is mandatory for helpers, types, and clients. |
| Naming | Files use kebab-case; types use PascalCase. |
| Secrets | Accessed via application-config helpers, never raw process.env. |
Sources: packages/twenty-codex-plugin/references/develop-app/logic.md:15-28, packages/twenty-codex-plugin/skills/develop-app/SKILL.md:53-56
Execution Flows
Logic functions can be executed in response to record changes, manual triggers, or as part of a post-installation process.
Bulk Processing Flow
By default, logic functions are designed for bulk record actions. When triggered from front-end selections, the function receives an array of record identifiers rather than executing repeatedly for each item.
The logic function returns a summary containing counts for success, no-matches, and failures to the caller.
Sources: packages/twenty-codex-plugin/references/develop-app/logic.md:33-47, packages/twenty-apps/community/github-connector/src/tests/logic-functions.integration-test.ts:30-40
Post-Install Hooks
Post-install hooks are a specialized type of logic function (definePostInstallLogicFunction) used to seed reference data, create default workflows, or set up roles upon app installation. These must be idempotent to prevent duplicate data on re-installation.
Sources: packages/twenty-codex-plugin/references/develop-app/logic.md:86-95
Skills & Agents
Skills and Agents define AI behavior within Twenty apps. They utilize logic functions to interact with workspace data and provide intelligent responses based on available context.
Skill Definition Requirements
Developers must provide concrete instructions for AI agents, including:
- Application Context: Description of when the skill applies.
- Required Data: The specific workspace or record context needed for the agent to function.
- Output Expectations: Defined shapes for responses, favoring readable answers over raw IDs or timestamps.
Sources: packages/twenty-codex-plugin/references/develop-app/logic.md:70-78, packages/twenty-apps/internal/twenty-partners/src/skills/twenty-partner-design-doc/design-doc-doctrine.md:120-125
Skill Types
| Skill | Purpose |
|---|---|
create-app | Scaffolding new Twenty apps. |
develop-app | Modifying entities, logic functions, and UI. |
manage-app | Handling remotes, deployments, and logs. |
publish-app | Preparing marketplace metadata and assets. |
use-twenty-mcp | Retrieving workspace records via MCP. |
Sources: packages/twenty-codex-plugin/AGENTS.md:18-28, packages/twenty-codex-plugin/CHANGELOG.md:88-95
Integration and External Connections
Logic Functions often serve as the bridge to external systems through Connection Providers.
Connection Provider Security
- Credential Storage: Secrets must be kept out of source code and public assets.
- OAuth Setup: Redirection URIs follow the pattern
<SERVER_URL>/apps/oauth/callback. - Validation: Functions must verify failure states for expired or missing credentials.
Sources: packages/twenty-codex-plugin/references/develop-app/logic.md:80-84, packages/twenty-codex-plugin/references/publish-app/prepare-for-app-store.md:58-60
Data Contracts for Logic Functions
The canonical payload for record actions uses the records key to establish context.
// Example Bulk Input Contract
type BulkInput<TRecord extends { id: string }> = {
records: TRecord[];
};
// Example Bulk Result Contract
type BulkResult = {
ok: boolean;
enrichedCount: number;
noMatchCount: number;
failedCount: number;
results: Array<{
id: string;
status: 'ENRICHED' | 'NO_MATCH' | 'FAILED';
error?: string;
}>;
};
Sources: packages/twenty-codex-plugin/references/develop-app/logic.md:49-68
Testing Logic Functions
Integration testing is critical for logic functions to ensure they return the expected payload shapes and handle errors gracefully.
Integration tests must target the isolated test instance on port 2021 rather than the standard dev instance to avoid state pollution during installation/uninstallation cycles.
Sources: packages/twenty-apps/community/github-connector/src/tests/logic-functions.integration-test.ts:16-30, packages/twenty-codex-plugin/CHANGELOG.md:45-50
Summary
Logic Functions and Skills form the core of Twenty's programmable layer. By enforcing modular code organization, bulk-first processing, and idempotent post-install hooks, the system provides a robust framework for CRM automation. Skills further extend this by providing a structured way to integrate AI agents that can interact with these logic functions to perform complex workspace tasks.