# How to Create a Task

Task creation is as easy as creating and deploying a new smart contract. Task authors should follow the interface at [ITask.cairo](/developers/automation/itask.cairo.md) create a task that defines their automation.

### Get our help

The Yagi team is happy to help in brainstorming different ideas for tasks that could be helpful to your protocol as well as task development.

Just ask on [Discord](https://discord.gg/49TYpjfkUn) or [Twitter](https://www.twitter.com/yagi_fi).

### Example task

This is an example task that maintains a counter to be called at least every minute. Note: there is nothing currently preventing the counter to be called more frequently.

```
## SPDX-License-Identifier: AGPL-3.0-or-later

%lang starknet

from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.starknet.common.syscalls import get_block_timestamp
from starkware.cairo.common.math_cmp import is_le

## @title Example counter task.
## @description Incrementable counter.
## @author Peteris <github.com/Pet3ris>

#############################################
##                 STORAGE                 ##
#############################################

@storage_var
func __counter() -> (counter: felt):
end

@storage_var
func __lastExecuted() -> (lastExecuted: felt):
end

#############################################
##                 GETTERS                 ##
#############################################

@view
func counter{
        syscall_ptr : felt*,
        pedersen_ptr : HashBuiltin*,
        range_check_ptr
    }() -> (counter: felt):
    let (counter) = __counter.read()
    return (counter)
end

@view
func lastExecuted{
        syscall_ptr : felt*,
        pedersen_ptr : HashBuiltin*,
        range_check_ptr
    }() -> (lastExecuted: felt):
    let (lastExecuted) = __lastExecuted.read()
    return (lastExecuted)
end

#############################################
##                  TASK                   ##
#############################################

@view
func probeTask{
        syscall_ptr : felt*,
        pedersen_ptr : HashBuiltin*,
        range_check_ptr
    }() -> (taskReady: felt):
    alloc_locals

    let (lastExecuted) = __lastExecuted.read()
    let (block_timestamp) = get_block_timestamp()
    let deadline = lastExecuted + 60
    let (taskReady) = is_le(deadline, block_timestamp)

    return (taskReady=taskReady)
end

@external
func executeTask{
        syscall_ptr : felt*,
        pedersen_ptr : HashBuiltin*,
        range_check_ptr
    }() -> ():
    # One could call `probeTask` here; it depends
    # entirely on the application.

    let (counter) = __counter.read()
    let new_counter = counter + 1
    let (block_timestamp) = get_block_timestamp()
    __lastExecuted.write(block_timestamp)
    __counter.write(new_counter)
    return ()
end

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.yagi.fi/developers/automation/how-to-create-a-task.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
