# Agent.Builder


```
class Agent.Builder
```

<br />

*** ** * ** ***

Builder for constructing `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent` instances.

## Summary

| ### Public constructors |
|---|
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#Builder()()` |

| ### Public functions |
|---|---|
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | `@https://errorprone.info/api/latest/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#addAppFunctionId(kotlin.String)(functionId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` Registers a specific AppFunction identifier (either a full ID such as `"com.example.MyAppFunctionService#createNote"` or a short method name such as `"createNote"`) to be made available to the agent. |
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | `@https://errorprone.info/api/latest/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#addAppFunctionIds(kotlin.collections.List)(functionIds: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html>)` Registers a list of AppFunction identifiers (either full IDs such as `"com.example.MyAppFunctionService#createNote"` or short method names such as `"createNote"`) to be made available to the agent. |
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | `@https://errorprone.info/api/latest/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#addAppFunctionIds(kotlin.Array)(vararg functionIds: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` Registers AppFunction identifiers (either full IDs such as `"com.example.MyAppFunctionService#createNote"` or short method names such as `"createNote"`) to be made available to the agent. |
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | `@https://errorprone.info/api/latest/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#addTool(com.google.mlkit.genai.agent.AgentTool)(tool: https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool)` Adds a single AppFunction tool (or a decorator wrapping one) to the agent. |
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | `@https://errorprone.info/api/latest/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#addTools(com.google.mlkit.genai.agent.AgentTool)(tool: https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool)` Adds a single AppFunction tool (or a decorator wrapping one) to the agent. |
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | `@https://errorprone.info/api/latest/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#addTools(kotlin.Array)(vararg tools: https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool)` Adds multiple AppFunction tools (or decorators wrapping them) to the agent. |
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | `@https://errorprone.info/api/latest/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#addTools(kotlin.collections.List)(tools: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool>)` Adds a collection of AppFunction tools (or decorators wrapping them) to the agent. |
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#build()()` Builds the `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent` instance. |
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | `@https://errorprone.info/api/latest/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#enableAppFunctions(kotlin.Boolean)(enabled: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` Enables automatic discovery and execution of functions annotated with `@androidx.appfunctions.AppFunction` across the calling application. |
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | `@https://errorprone.info/api/latest/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#setInstructions(kotlin.String)(instructions: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` Sets the system instructions for the agent. |
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | `@https://errorprone.info/api/latest/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#setMaxTurns(kotlin.Int)(maxTurns: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Sets the maximum execution steps allowed per turn before forced termination. |
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | `@https://errorprone.info/api/latest/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#setName(kotlin.String)(name: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` Sets the name of the agent. |

## Public constructors

### Builder

```
Builder()
```

## Public functions

### addAppFunctionId

```
@CanIgnoreReturnValue
fun addAppFunctionId(functionId: String): Agent.Builder
```

Registers a specific AppFunction identifier (either a full ID such as `"com.example.MyAppFunctionService#createNote"` or a short method name such as `"createNote"`) to be made available to the agent.

Scoping to specific function IDs disables package-level metadata instructions injection.

| Parameters |
|---|---|
| `functionId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | The AppFunction identifier or method name to enable. |

| Returns |
|---|---|
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | This builder |

### addAppFunctionIds

```
@CanIgnoreReturnValue
fun addAppFunctionIds(functionIds: List<String>): Agent.Builder
```

Registers a list of AppFunction identifiers (either full IDs such as `"com.example.MyAppFunctionService#createNote"` or short method names such as `"createNote"`) to be made available to the agent.

| Parameters |
|---|---|
| `functionIds: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html>` | The AppFunction identifiers or method names to enable. |

| Returns |
|---|---|
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | This builder |

### addAppFunctionIds

```
@CanIgnoreReturnValue
fun addAppFunctionIds(vararg functionIds: String): Agent.Builder
```

Registers AppFunction identifiers (either full IDs such as `"com.example.MyAppFunctionService#createNote"` or short method names such as `"createNote"`) to be made available to the agent.

| Parameters |
|---|---|
| `vararg functionIds: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | The AppFunction identifiers or method names to enable. |

| Returns |
|---|---|
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | This builder |

### addTool

```
@CanIgnoreReturnValue
fun addTool(tool: AgentTool): Agent.Builder
```

Adds a single AppFunction tool (or a decorator wrapping one) to the agent.

| Parameters |
|---|---|
| `tool: https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool` | Tool to add |

| Returns |
|---|---|
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | This builder |

| Throws |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-illegal-argument-exception/index.html` | if `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#addTool(com.google.mlkit.genai.agent.AgentTool)` is not an AppFunction tool discovered via `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(kotlinx.coroutines.CoroutineDispatcher)` (or a decorator wrapping one). |

### addTools

```
@CanIgnoreReturnValue
fun addTools(tool: AgentTool): Agent.Builder
```

Adds a single AppFunction tool (or a decorator wrapping one) to the agent.

| Parameters |
|---|---|
| `tool: https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool` | Tool to add |

| Returns |
|---|---|
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | This builder |

| Throws |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-illegal-argument-exception/index.html` | if `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#addTools(com.google.mlkit.genai.agent.AgentTool)` is not an AppFunction tool discovered via `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(kotlinx.coroutines.CoroutineDispatcher)` (or a decorator wrapping one). |

### addTools

```
@CanIgnoreReturnValue
fun addTools(vararg tools: AgentTool): Agent.Builder
```

Adds multiple AppFunction tools (or decorators wrapping them) to the agent.

| Parameters |
|---|---|
| `vararg tools: https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool` | Vararg tools to be made available to the agent |

| Returns |
|---|---|
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | This builder |

| Throws |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-illegal-argument-exception/index.html` | if any tool in `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#addTools(kotlin.Array)` is not an AppFunction tool discovered via `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(kotlinx.coroutines.CoroutineDispatcher)` (or a decorator wrapping one). |

### addTools

```
@CanIgnoreReturnValue
fun addTools(tools: List<AgentTool>): Agent.Builder
```

Adds a collection of AppFunction tools (or decorators wrapping them) to the agent.

| Parameters |
|---|---|
| `tools: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool>` | Tools to be made available to the agent |

| Returns |
|---|---|
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | This builder |

| Throws |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-illegal-argument-exception/index.html` | if any tool in `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#addTools(kotlin.collections.List)` is not an AppFunction tool discovered via `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(kotlinx.coroutines.CoroutineDispatcher)` (or a decorator wrapping one). |

### build

```
fun build(): Agent
```

Builds the `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent` instance.

### enableAppFunctions

```
@CanIgnoreReturnValue
fun enableAppFunctions(enabled: Boolean = true): Agent.Builder
```

Enables automatic discovery and execution of functions annotated with `@androidx.appfunctions.AppFunction` across the calling application.

When enabled, discovered functions are invoked automatically by `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentRunner` during a turn whenever the model emits a matching tool call. If a function requires user confirmation (Human-in-the-Loop), runtime permissions, or custom validation before execution, use `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AppFunctionAgentTools#discover(kotlinx.coroutines.CoroutineDispatcher)` instead, wrap the sensitive `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool`'s `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/AgentTool#execute(kotlin.collections.Map)` method to prompt the user before delegating, and register the wrapped tools via `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder#addTools(com.google.mlkit.genai.agent.AgentTool)`.

| Parameters |
|---|---|
| `enabled: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html = true` | Whether to enable AppFunctions discovery and execution. Defaults to true. |

| Returns |
|---|---|
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | This builder |

### setInstructions

```
@CanIgnoreReturnValue
fun setInstructions(instructions: String): Agent.Builder
```

Sets the system instructions for the agent. Defaults to an empty string.

| Parameters |
|---|---|
| `instructions: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | System prompt guiding agent behavior and personality |

| Returns |
|---|---|
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | This builder |

### setMaxTurns

```
@CanIgnoreReturnValue
fun setMaxTurns(maxTurns: Int): Agent.Builder
```

Sets the maximum execution steps allowed per turn before forced termination. Defaults to 10.

| Parameters |
|---|---|
| `maxTurns: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | Maximum turns allowed. Must be greater than 0 |

| Returns |
|---|---|
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | This builder |

### setName

```
@CanIgnoreReturnValue
fun setName(name: String): Agent.Builder
```

Sets the name of the agent. Defaults to "Assistant".

| Parameters |
|---|---|
| `name: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | Identifier name for the agent |

| Returns |
|---|---|
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/agent/Agent.Builder` | This builder |