# Build

Build (aka Agent mode) enables conversational development inside Appfarm Create. Describe the desired app or functionality and follow along as the agent goes through the implementation tasks. Build mode is currently limited to certain parts of the platform; see [#current-limitations](#current-limitations "mention").

{% hint style="info" %}
If you are familiar with how building with Appfarm AI works, and want a practical guideline, please se the [Practical Guide to Appfarm AI](https://docs.appfarm.io/reference/appfarm-ai/practical-guide-to-appfarm-ai) section.
{% endhint %}

## Getting started

When your Solution has no apps, the [Apps](https://docs.appfarm.io/reference/apps) page will prompt you to describe an app for Appfarm AI to build with its agents.&#x20;

<figure><img src="https://29237295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiLU-xcHu0eLZiTxcmZ%2Fuploads%2FsgnlP6WZQcdMqCMK37tB%2Fimage.png?alt=media&#x26;token=6af930ab-9272-4e91-8849-4ec8a6a063db" alt=""><figcaption><p>Screenshot of the Apps page in Appfarm Create with a prompt to build a new app.</p></figcaption></figure>

Once a prompt has been submitted, the planning agent will create a plan for building the app, breaking the request down into implementation tasks. You can refine the plan by asking the agent to add, revise, or remove tasks.&#x20;

<figure><img src="https://29237295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiLU-xcHu0eLZiTxcmZ%2Fuploads%2Fo5GxqLWPBESYgppySzjc%2Fimage.png?alt=media&#x26;token=f1b2e0e0-d74f-4606-89e4-6e3e79d50f68" alt=""><figcaption></figcaption></figure>

Once you're satisfied with the plan, click **Build App**. The Appfarm AI sidebar will open with your initial prompt and the list of implementation tasks, and the builder agents will automatically start working on the first task.

## Working with the builder

### **Tasks and changes**

When building an app, or performing big changes to existing apps, the agents are working on **Tasks**. By default, all changes are automatically saved, and the agent has **Auto-run** enabled - meaning it will continue the task list until finished.

<figure><img src="https://29237295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiLU-xcHu0eLZiTxcmZ%2Fuploads%2FqmfGjVCsG9WuTu9VpqRo%2Fimage.png?alt=media&#x26;token=2db78177-c4e2-4259-a2c3-5743a64423cf" alt=""><figcaption></figcaption></figure>

If you want to stop the build process, you may click the **Stop**-icon in the bottom-right part of the AI Panel. A **Continue** button will appear. You may also disable Auto-run, meaning you must click Continue between each task.

The **Change history** panel lists all components created or touched by the agents. Click any item in the list to jump to its location in Appfarm Create. You may also **adjust anything visually** (e.g. change the order of input fields in a Dialog, or add an action node to an Action) while the agents are running (or after).

You can also view and **Undo** all changes done by the agents in the top-right Undo/Redo menu. You can only Undo when the agents are *not* running:

<p align="center"><br><img src="https://29237295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiLU-xcHu0eLZiTxcmZ%2Fuploads%2FmotuFzRYFJmz3J9jNNWn%2Fimage.png?alt=media&#x26;token=ce39ac35-b76b-4127-8571-5d3c5634b350" alt=""></p>

### **Error handling**

Like any AI tool, the agents can make mistakes. These mistakes may result in bugs in your app, such as faulty logic in an action or suboptimal UI. You can resolve these issues by prompting the agent—see the [#prompting-guide](#prompting-guide "mention") section for effective techniques—or by fixing them manually.

The agents may also make changes to your models that aren't technically valid in Appfarm Create. When the agent completes an operation, all changes pass through a validation layer. If any errors are detected, these are automatically sent back to the agents, which will then attempt to fix them. If the agents can't resolve the errors after several attempts, it will pause and ask whether you'd like it to continue.

Please help us avoid errors and improve the agent by providing [feedback](https://docs.appfarm.io/reference/appfarm-ai/..#feedback) when you encounter issues and click the <i class="fa-thumbs-up">:thumbs-up:</i> or <i class="fa-thumbs-down">:thumbs-down:</i> button after the response provided by the agent.

{% hint style="success" %}
Suppose Appfarm AI builds an app or functionality that does not seem to work during testing: try explaining to Appfarm AI *what* does not work in clear terms. If there are error messages in the [developer tools](https://docs.appfarm.io/reference/appfarm-client/developer-tools-for-apps), also copy this error message and add it to your prompt. In many cases, the AI will be able to fix the error or incorrect logic. *Example: If a Save button does not work, mark it inside Appfarm Create and type "Nothing happens when I click this Save button".*
{% endhint %}

### **Threads**

A thread is a conversation with the agent that may include a list of tasks. When you send a message to the agents, the entire thread is sent as context along with the status of all associated tasks. By default, Appfarm Create starts a new thread on a fresh reload of Appfarm Create.&#x20;

* **Start new thread:** Click the <i class="fa-plus">:plus:</i> icon in the top right corner of the Appfarm AI sidebar.
* **Show thread history:** Click the <i class="fa-clock-rotate-left">:clock-rotate-left:</i> icon in the top right corner of the Appfarm AI sidebar to view your ten most recent threads in the current Solution. Select any thread to continue the conversation and complete unfinished tasks.
* **Resume a previous thread:** Open the thread history and select the thread you wish to continue.

**When a thread gets too long, Appfarm AI will summarise it behind the scenes.** If tasks exist, those will remain in their full form.

{% hint style="success" %}
Even if Appfarm AI summarises long threads, it is recommended to start a new, clean thread once in a while. If the AI gets stuck, try to create a new thread or refresh Appfarm Create.&#x20;
{% endhint %}

### Agent Focus

Build mode is using all build-agents. This is self-orchestrated, meaning the top-level agent (the planning generalist) will delegate tasks to sub-agents with different capabilities.

When using build mode, you can actively choose one of the available sub-agents. We call this **Agent Focus**. You may select the Design agent directly, meaning you will talk directly to a specialized sub-agent.

<figure><img src="https://29237295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiLU-xcHu0eLZiTxcmZ%2Fuploads%2F7nXmLw0O0y4TWBw7XRPU%2Fimage.png?alt=media&#x26;token=20176032-ea5b-4fa0-9062-108266ff7f26" alt=""><figcaption></figcaption></figure>

The Design sub-agent is great for building beautiful designs. However, it does not have capabilities outside the scope of design - i.e. it does *not* connect to data sources as dynamically as the general agent mode, nor can it build data models, add data sources or actions (only simple navigation).

## Custom agent knowledge

The agent is instructed to follow a defined "best practices" for building Appfarm apps. For example:&#x20;

* Apps should use Dialogs for input (New/Edit records), Drawers for details pane (read-only details), both using the same runtime-only single cardinality data source.&#x20;
* Datasources: Use database-connected for listing (plural tense naming) and single-cardinality runtime-only for Dialogs/Drawers (create/edit/display details, with `" (temp)"` as naming postfix).
* Actions naming: Use the main entity as a prefix (e.g., prefix `"Projects - "` for all project-related actions).

You may override these instructions or add other preferences (naming, UI/layout, colours etc) with your own custom **Agent knowledge**. Agent knowledge is located in the Settings in Appfarm Create (found in the top-left menu, or Thread/AI Panel menu). *The Agent knowledge is defined on the solution level*, meaning it is shared across the developers in the same solution.

<figure><img src="https://29237295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiLU-xcHu0eLZiTxcmZ%2Fuploads%2F4wt4lqyELJoqFxWING0O%2Fimage.png?alt=media&#x26;token=87217445-da57-4777-b8fc-da9ee10c339a" alt=""><figcaption></figcaption></figure>

## How the agent works

When you give the agent a task or prompt, your application metadata (the views, actions etc) is sent as [context](https://docs.appfarm.io/reference/appfarm-ai/context-handling). Based on its system instructions, the custom [agent knowledge](#custom-agent-knowledge), and the current location/selected component in Appfarm Create - the agent determines the intent, identifies the available tools, and determines which ones to use. Through these tools, the agent learns how the many building blocks work in Appfarm Create. It then issues commands to insert, update, or delete parts of the application model. These commands function identically to actions performed by a human user, so the same guardrails and rules apply.

**Appfarm AI has access to web search.** In other words, you may refer to URLs. For example: 1) You may ask Appfarm AI to use colours and fonts from your homepage, or 2) you may provide a link to the documentation of an integration, in order to help Appfarm AI do better.

Read more about our [approach to AI](https://www.appfarm.io/ai/our-approach).

## Function Editor AI

Appfarm AI side-panel lives side-by-side with you while developing in Appfarm Create. It serves both as an agent ("building on its own") and an assistant ("your personal AI assistant").

However, you can also use AI inside the Function Editor. Inside the Function Editor, the AI lives standalone (independent of your current thread and dialogue). It may add app variables and data sources, and it is exceptionally good at writing code and adding function params that serve the purpose.&#x20;

<figure><img src="https://29237295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiLU-xcHu0eLZiTxcmZ%2Fuploads%2FwTjDzJIGnsL2qV9TDvp9%2Ffunction%20editor%20AI.png?alt=media&#x26;token=5ddd27dc-0d13-4e89-a145-13cc1c1ea5d6" alt=""><figcaption></figcaption></figure>

## Current limitations

The agent is currently able to work with the following concepts in Appfarm Create:

* [Apps](https://docs.appfarm.io/reference/apps)&#x20;
* [App data sources](https://docs.appfarm.io/reference/apps/data/data-sources)
* [App actions](https://docs.appfarm.io/reference/apps/actions)
* [UI](https://docs.appfarm.io/reference/apps/ui)
* [Functions](https://docs.appfarm.io/reference/platform-concepts/functions)
* [Conditions](https://docs.appfarm.io/reference/platform-concepts/conditions)
* [Themes](https://docs.appfarm.io/reference/resources/themes)
* [Object classes](https://docs.appfarm.io/reference/data-model/object-classes)
* [Enumerated types](https://docs.appfarm.io/reference/data-model/enumerated-types)

Appfarm AI has **not** yet been instructed to build

* [Shareable Components](https://docs.appfarm.io/reference/apps/ui/shareable-ui-components)
* Advanced charts / Gantt
* [Responsive design](https://docs.appfarm.io/how-to/user-interface/responsive-layout)
* Translations
* Offline support
* Performance analysis/improvements
* [Services](https://docs.appfarm.io/reference/services)
* Permissions and environment/login config
* Complex deletions for large solutions (requiring a chain of deletions in correct order)

Appfarm AI will gradually expand its support to more areas.
