> ## Documentation Index
> Fetch the complete documentation index at: https://incredible-42686482-cursor-create-detailed-ai-agent-cookboo.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Application State Management

> Maintain and update app state with function calls and tool results

### To-Do List Manager

Incredible can manage **stateful applications**, where actions mutate state. With this you can build entirely new software and applications from the ground up using these models. Not just connecting it to an already existing system. A simple example of a stateful application would be a to-do list manager.

```bash
curl https://api.incredible.one/v1/chat-completion \
  --header "Content-Type: application/json" \
  --data '{
    "model": "small-1",
    "functions": [
		  {
		    "name": "create_new_todo_list",
		    "description": "Create a new todo list",
		    "parameters": {
		      "type": "object",
		      "properties": {
		        "name": { "type": "string", "description": "Name of the todo list" }
		      },
		      "required": ["name"]
		    }
		  },
		  {
		    "name": "add_todo_item",
		    "description": "Add a new item to an existing todo list",
		    "parameters": {
		      "type": "object",
		      "properties": {
		        "list_id": { "type": "string", "description": "The ID of the list" },
		        "title": { "type": "string", "description": "The todo item title" },
		        "due_date": { "type": "string", "format": "date", "description": "Optional due date in YYYY-MM-DD" }
		      },
		      "required": ["list_id", "title"]
		    }
		  }
		],
    "messages": [
      {
        "role": "user",
        "content": "Add a high priority task to review quarterly reports by Friday, and show me all my current tasks"
      }
    ]
  }'
```

### Example Scenario

1. **User:** "Add a task to review quarterly reports by Friday."

2. **AI:** "You don’t have a to-do list yet. Do you want me to create one? Here are 3 suggestions:
   * Work Tasks
   * Personal Errands
   * Long-term Projects"

3. **User:** "Yes, create work tasks.”

   → AI calls `create_new_todo_list`

4. **AI:** "Okay, I created a list called '*Work Tasks'.* Now I’ll add your item."

   → AI calls `add_todo_item` with `title=Review quarterly reports`, `due_date=Friday`

5. **AI:** "Done! You now have 1 todo in your *Work Tasks* list."

### Delete a Todo List

Here’s how you can define the function to remove an entire list:

```bash
{
    "model": "small-1",
    "functions": [
      {
        "name": "delete_todo_list",
        "description": "Delete an existing todo list",
        "parameters": {
          "type": "object",
          "properties": {
            "list_id": { "type": "string", "description": "The ID of the list to delete" }
          },
          "required": ["list_id"]
        }
      }
    ],
    "messages": [
      {
        "role": "user",
        "content": "Delete my list with ID 12345"
      }
    ]
}
```

### Remove an Item from Todo List

Here’s how you can define the function to remove an item from todo list:

```json
{
  "name": "remove_todo_item",
  "description": "Remove an item from a todo list",
  "parameters": {
    "type": "object",
    "properties": {
      "list_id": {
        "type": "string",
        "description": "The ID of the list"
      },
      "item_id": {
        "type": "string",
        "description": "The ID of the item to remove"
      }
    },
    "required": [
      "list_id",
      "item_id"
    ]
  }
}
```
