> For the complete documentation index, see [llms.txt](https://docs.indicio.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.indicio.tech/developer/mobile-solutions/mobile-sdk/agent.md).

# Agent

## Wallet Config

To create an Agent you need to first create a wallet config object to tell the Agent how to initialize your wallet.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
val walletConfig: WalletConfig = WalletConfig(
    uri = "sqlite://pathWhereYouWantDataStored/local.db",
    // options are raw(raw random key), kdf:argon2i(Encrypted Key), none(testing only)
    keyMethod = "raw", 
    // Should be randomly generated or derived from a pin or password, must be able to be repeatedly accessed
    passkey = "TheActualKeyThatUnlocksTheWallet", 
    id = "Unique id for this wallet"
)
```

{% endtab %}

{% tab title="Swift" %}

```swift
let walletConfig = WalletConfig(
    uri: "sqlite://pathWhereYouWantDataStored/local.db",
    keyMethod: "raw",
    passkey: "TheActualKeyThatUnlocksTheWallet",
    id: "Unique id for this wallet"
)
```

{% endtab %}
{% endtabs %}

## Mediation Config

Next create a mediation config to pass to our Agent. The reconnection interval in the below section has two values that indicate the min and max amount of time in a back off strategy on which to try and contact the mediator.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
val mediationConfig: MediationConfig = MediationConfig(   
    mediatorInvitationUrl = "Mediation connection url for the default mediator you want to use",
    // Optional parameter to indicate how often, in milliseconds,the Agent should try to reconnect to the mediator
    baseMediatorReconnectionIntervalMS = 500,
    // Optional parameter to indicate the max amount of time between attempts to contact the mediator
    maximumMediatorReconnectionIntervalMS: Int = 10000
)
```

{% endtab %}

{% tab title="Swift" %}

```swift
let mediationConfig = MediationConfig(
    mediatorInvitationUrl: "Mediation connection URL for the default mediator you want to use",
    // Optional parameter to indicate how often, in milliseconds, the Agent should try to reconnect to the mediator
    baseMediatorReconnectionIntervalMS: 500, 
    // Optional parameter to indicate the max amount of time between attempts to contact the mediator
    maximumMediatorReconnectionIntervalMS: 10000 
)
```

{% endtab %}
{% endtabs %}

## Pool Config

The pool config is used to indicate what networks/ledgers the Agent can read from. Not all ledgers contain all schemas or credential definitions and some are more volatile than others. The standard way to declare a pool config is shown in the examples below and again the React Native portion of this document.

The first value used to create a pool config is the `genesisUrl`. This is a url point to the genesis file in a raw string format. This file is used to establish connection and provide data about the network/ledger.

The second value used to create a pool config is the `isProduction` boolean flag. This indicates to the agent whether to treat the network/ledger as a production environment or not.

The last value needed to create a pool config is the `indyNamespace`. This string value is the name by which the network/ledger is known and is prepended to schemas and credential definitions to identify what network/ledger they are on. Misspelling this value or having an incorrect variation will cause errors when reading from the ledger.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
    val indicioDemoNet = IndyVDRPoolConfig.fromUrl(
        genesisUrl = "https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_demonet_genesis",
        isProduction = false,
        indyNamespace = "indicio-demo-net"
    )
```

{% endtab %}

{% tab title="Swift" %}

```swift
    let indicioDemoNet = IndyVDRPoolConfig.companion.fromUrl(
        genesisUrl = "https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_demonet_genesis",
        isProduction = false,
        indyNamespace = "indicio-demo-net"
    )
```

{% endtab %}
{% endtabs %}

## Configuring an Agent

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
val agent: Agent = Agent(
    walletConfig = walletConfig,
    mediationConfig = mediationConfig,
    pools = ListOf(
        indicioDemoNet
    ),
    pickupBatchSize = 10, // max number of message that can be picked up at once from the mediator
    defaultConnectionLabel = "Proven SDK", // The label the Agent will use in didComm communication
    enableLogging = false,
    autoAcceptConnections = true, 
    autoAcceptCredentials = false,
    customLogger = null // (message: String)->Unit Callback to use for logging instead of `println()`
)
```

{% endtab %}

{% tab title="Swift" %}

```swift
let agent = Agent(
    walletConfig: walletConfig,
    mediationConfig: mediationConfig,
    pools: [
        indicioDemoNet
    ],
    pickupBatchSize: 10, // max number of message that can be picked up at once from the mediator
    defaultConnectionLabel: "Proven SDK", // The label the Agent will use in didComm communication
    enableLogging: false,
    autoAcceptConnections: true, 
    autoAcceptCredentials: false,
    customLogger: nil // (message: String)->Void Callback to use for logging instead of `println()`
)

// Start agent (KMPNativeCoroutines)
try await asyncFunction(for: agent.start(startUpTimeout: 10000))

// Start agent (Completion handler)
agent.start(startUpTimeout: 10000){error in
    if(error != nil){
        // Handle error
    }
    // Code to be called when agent started
}

// Start agent (Without KMPNativeCoroutines)
let error: ProvenError? = await agent.start(startUpTimeout: 10000)
if(error != nil){
    // Handle error
}
```

{% endtab %}
{% endtabs %}

Once the Agent is created and configured you will have to call `agent.start()` before you can use the agent for anything. When the app is closing `agent.stop()` should be called to safely shut the agent down between sessions.

If you want to remove the Agent or reset the wallet you can call `agent.delete()` to remove all data the agent has saved.

## React Native

Creating an Agent follows similar steps as Kotlin and Swift but has some additional steps specific to React Native.

Similar to Kotlin and Swift some config object must be created to customize the Agent. Additionally for creating a pool config from a url pointing to genesis files you must pass the `ProvenReactNative` object imported from the `@proven-mobile/react-native` package.

```typescript
import RNFS from 'react-native-fs';
import ProvenReactNative, {
    provenEventsFactory,
} from '@proven-mobile/react-native';
import {
    Agent,
    IndyPoolConfig,
    type MediationConfig,
    type WalletConfig
} from '@proven-mobile/core';

const walletConfig: WalletConfig = {
    uri: `sqlite://${RNFS.DocumentDirectoryPath}/local.db`,
    keyMethod: 'raw',
    passkey: 'CwNJroKHTSSj3XvE7ZAnuKiTn2C4QkFvxEqfm5rzhNrb',
    id: 'ReactNativeTest',
    profile: 'test',
};

const mediationConfig: MediationConfig = {
    mediatorInvitationUrl:
    'url invite to the mediator you want to use',
    baseMediatorReconnectionIntervalMS: 50,
    maximumMediatorReconnectionIntervalMS: 10000,
};

const poolConfig: IndyVDRPoolConfig = await IndyPoolConfig.fromURL(
    ProvenReactNative,
    'https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_demonet_genesis',
    false,
    'indicio-demo-net',
);
```

The actual Agent is created by passing the created config objects along with some other options. Again the `ProvenReactNative` object must be included in the Agent constructor along with the `provenEventsFactory` that facilitates getting events from the Agent to the React Native level.

```typescript
import ProvenReactNative, {
    provenEventsFactory,
} from '@proven-mobile/react-native';

const agent = new Agent(
    ProvenReactNative,
    provenEventsFactory,
    walletConfig,
    mediationConfig,
    [poolConfig],
    'RN',
    10,
    true,
    true,
    true,
    console.info // (message: string)->Void Callback to use for logging, defaults to console.log
);
```

Once the Agent has been constructed you can start the Agent with the following code. The React Native code allows the use of the Javascript Promise syntax for async operations:

```typescript
await agent.start();
```

Similarly, the `agent.stop()` and `agent.delete()` functions exist on the agent object along with access to all other modules and their respective functions mirroring the Kotlin and Swift implementations.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.indicio.tech/developer/mobile-solutions/mobile-sdk/agent.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.
