> For the complete documentation index, see [llms.txt](https://docs.cyne.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cyne.ai/core-concept/dynamic-tasks.md).

# Dynamic Tasks

Dynamic Tasks are the core building blocks of the Cyne AI framework, enabling agents to perform specific tasks such as whale tracking, liquidity management, token swapping, and more.

### **Overview**

Each task in **Cyne AI** consists of the following key components:

* **name**: A unique identifier for the action.
* **similes**: Alternative names or triggers for the action.
* **description**: A detailed explanation of the action's purpose.
* **validate**: Logic to check whether the action can be executed based on the current context.
* **handler**: The implementation of the action's behavior.
* **examples**: Demonstrates how the action works in practice.

***

### **Action Structure**

The structure of an action in **Cyne AI** follows the format below:

```typescript
interface Action {
    name: string;
    similes: string[];
    description: string;
    validate: (runtime: IAgentRuntime, message: Memory) => Promise<boolean>;
    handler: (
        runtime: IAgentRuntime,
        message: Memory,
        state?: State
    ) => Promise<void>;
    examples: ActionExample[][];
    suppressInitialMessage?: boolean;
}
```

***

### **Key Components**

1. **name**: Unique name for the action.
2. **similes**: Triggers or alternative names that activate the action.
3. **description**: A clear and concise explanation of the action's functionality.
4. **validate**: Ensures the action can be executed under the current conditions.
5. **handler**: Defines the logic and operations executed by the action.
6. **examples**: Provides real-world usage examples.
7. **suppressInitialMessage**: Suppresses automatic responses if the action generates its own output.

***

### **Built-In Actions in Cyne AI**

#### **1. CONTINUE**

Continues the conversation by gathering more context or expanding on a topic.

```typescript
const continueAction: Action = {
    name: "CONTINUE",
    similes: ["ELABORATE", "KEEP_TALKING"],
    description: "Expands on a topic or gathers additional context.",
    validate: async () => true,
    handler: async (runtime, message, state) => {
        // Logic to continue the conversation
    },
};
```

***

#### **2. IGNORE**

Disengages gracefully from conversations when the discussion is finished or irrelevant.

```typescript
const ignoreAction: Action = {
    name: "IGNORE",
    similes: ["STOP_TALKING", "END_CONVERSATION"],
    description: "Stops responding when the conversation is no longer relevant.",
    handler: async () => true,
};
```

***

#### **3. TRACK\_WHALE**

Monitors large transactions on Solana and alerts users to potential market impacts.

```typescript
const trackWhaleAction: Action = {
    name: "TRACK_WHALE",
    similes: ["MONITOR_WHALE", "DETECT_WHALE"],
    description: "Tracks large token transactions in real time.",
    validate: async (runtime, message) => {
        const content = (message.content as Content).text;
        return /track whale/i.test(content);
    },
    handler: async (runtime, message, state) => {
        const whaleData = await runtime.getWhaleActivity();
        return `Whale Alert: ${whaleData.amount} SOL moved to Pool ${whaleData.pool}.`;
    },
};
```

***

#### **4. EXECUTE\_SWAP**

Facilitates token swaps using the DEX aggregator for optimal rates.

```typescript
const executeSwapAction: Action = {
    name: "EXECUTE_SWAP",
    similes: ["SWAP_TOKENS", "TRADE"],
    description: "Performs token swaps with the best available rates on the DEX aggregator.",
    validate: async (runtime, message) => {
        const content = (message.content as Content).text;
        return /\bswap\b/i.test(content) && content.includes("to");
    },
    handler: async (runtime, message, state) => {
        const [fromToken, toToken] = message.content.text.split("to").map((t) => t.trim());
        const swapResult = await runtime.dexAggregator.swap(fromToken, toToken);
        return `Swapped ${swapResult.amount} ${fromToken} to ${swapResult.amount} ${toToken} at the best rate.`;
    },
};
```

***

#### **5. ANALYZE\_RISK**

Performs risk analysis on a smart contract or liquidity pool.

```typescript
const analyzeRiskAction: Action = {
    name: "ANALYZE_RISK",
    similes: ["RISK_ANALYSIS", "CHECK_RISK"],
    description: "Evaluates the risk level of a given contract or liquidity pool.",
    validate: async (runtime, message) => {
        const address = (message.content as Content).text;
        return /0x[a-fA-F0-9]{40}/.test(address); // Validates Ethereum-style contract address
    },
    handler: async (runtime, message) => {
        const riskScore = await runtime.riskAnalyzer.analyze(message.content.text);
        return `Risk Analysis: The contract has a risk score of ${riskScore}. ${riskScore > 70 ? "High Risk!" : "Low Risk."}`;
    },
};
```

***

#### **6. GENERATE\_REPORT**

Creates detailed performance or trend reports.

```typescript
const generateReportAction: Action = {
    name: "GENERATE_REPORT",
    similes: ["CREATE_REPORT", "PORTFOLIO_REPORT"],
    description: "Generates a comprehensive report of portfolio performance or market trends.",
    validate: async (runtime, message) => {
        const text = (message.content as Content).text;
        return /generate report/i.test(text);
    },
    handler: async (runtime, message) => {
        const reportData = await runtime.generatePortfolioReport();
        return `Portfolio Report: ${reportData.summary}`;
    },
};
```

***

### **Creating Custom Actions**

#### **Basic Template**

```typescript
const customAction: Action = {
    name: "CUSTOM_ACTION",
    similes: ["ALTERNATIVE_TRIGGER"],
    description: "Defines the purpose of this action.",
    validate: async (runtime, message) => {
        // Custom validation logic
        return true;
    },
    handler: async (runtime, message, state) => {
        // Custom action logic
    },
    examples: [
        [
            {
                user: "{{user1}}",
                content: { text: "Trigger message" },
            },
            {
                user: "{{user2}}",
                content: { text: "Response", action: "CUSTOM_ACTION" },
            },
        ],
    ],
};
```

***

### **Best Practices for Actions**

* **Clear Purpose**: Define a single, well-focused purpose for each action.
* **Robust Validation**: Check prerequisites and validate inputs.
* **Error Handling**: Handle errors gracefully and provide meaningful feedback.
* **Comprehensive Documentation**: Provide examples and explain expected inputs, outputs, and scenarios.
