Tasks
Overview
In Cogfy, a task is counted whenever there is an execution that involves an external provider or a resource-intensive operation (e.g., an operation that takes a file as input). This applies to both operations and chat-based interactions:
Operations: A task is counted when an operation is executed that includes a provider (e.g., an API) or is otherwise resource-intensive (e.g., involves processing a file).
Chats: A task is counted when a tool is executed or a middleware is triggered and it involves a provider (e.g., calling an API, accessing an external service) or performs a costly computation.
Each task reflects a meaningful action that typically involves external communication or significant processing. This model ensures that task usage is tied to impactful and resource-consuming operations.
Examples
Task Count in Operations
If you run a prompt operation that sends the input to a language model provider (such as an LLM), it will count as 1 task:

Or if you run a resize image operation, it will also count as 1 task:

If you would like to create a more complex flow that includes multiple operations, you can do so by chaining them together. In this example, each operation will count as a separate task, and will cost 2 tasks in total:

Task Count in Chats
In this example, we have a basic chatbot that uses three middlewares: History, Instructions, and OpenAI:

Only the OpenAI middleware will count as a task, since it is the only one that relies on an external provider. The other two — History and Instructions — are internal and do not trigger external operations, so they do not count as tasks. As a result, for each message sent to the bot, 1 task will be counted:

If you want to create a more complex chatbot that uses tools (such as function calling), the execution of the tool will count as a task. In this example, we have a chat that uses a tool to do a http request to an external API:

So, when the user sends a message requesting to call the tool, it will count as 3 tasks in total:
- The LLM requiring to call the tool (1 task - OpenAI middleware)
- The tool execution (1 task - Tool middleware)
- The LLM response (1 task - OpenAI middleware)
