Quick Start

Quick Start

Environment Requirements

DependencyVersion
JDK17+
Maven3.6+
Netty4.1.116.Final (bundled with SDK)

Build Dependencies

xml
<dependency>
    <groupId>com.agibot.aiem</groupId>
    <artifactId>linksoul-agentsdk</artifactId>
    <version>1.4.0-SNAPSHOT</version>
</dependency>

Gradle (Groovy build.gradle)

groovy
implementation 'com.agibot.aiem:linksoul-agentsdk:1.4.0-SNAPSHOT'

Third-party dependencies when integrating the bare jar

If you cannot resolve transitive dependencies via Maven / Gradle, add the libraries below by hand:

DependencyVersionPurpose
org.slf4j:slf4j-api2.0.16Logging facade
ch.qos.logback:logback-classic1.5.13Logging implementation
org.projectlombok:lombok1.18.36Annotation processor
com.alibaba.fastjson2:fastjson22.0.53JSON encode/decode
org.apache.commons:commons-lang33.14.0Utility classes
io.jsonwebtoken:jjwt-api0.11.5JWT API
io.jsonwebtoken:jjwt-impl0.11.5JWT runtime
io.jsonwebtoken:jjwt-jackson0.11.5JWT JSON serialization
io.netty:netty-all4.1.116.FinalWebSocket client

Equivalent pom.xml / build.gradle snippets:

xml
<dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>2.0.16</version></dependency>
<dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.36</version></dependency>
<dependency><groupId>ch.qos.logback</groupId><artifactId>logback-classic</artifactId><version>1.5.13</version></dependency>
<dependency><groupId>com.alibaba.fastjson2</groupId><artifactId>fastjson2</artifactId><version>2.0.53</version></dependency>
<dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.14.0</version></dependency>
<dependency><groupId>io.jsonwebtoken</groupId><artifactId>jjwt-api</artifactId><version>0.11.5</version></dependency>
<dependency><groupId>io.jsonwebtoken</groupId><artifactId>jjwt-impl</artifactId><version>0.11.5</version></dependency>
<dependency><groupId>io.jsonwebtoken</groupId><artifactId>jjwt-jackson</artifactId><version>0.11.5</version></dependency>
<dependency><groupId>io.netty</groupId><artifactId>netty-all</artifactId><version>4.1.116.Final</version></dependency>
groovy
implementation 'org.slf4j:slf4j-api:2.0.16'
implementation 'org.projectlombok:lombok:1.18.36'
implementation 'ch.qos.logback:logback-classic:1.5.13'
implementation 'com.alibaba.fastjson2:fastjson2:2.0.53'
implementation 'org.apache.commons:commons-lang3:3.14.0'
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.5'
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5'
implementation 'io.netty:netty-all:4.1.116.Final'

Note: keep appKey and appSecret private — they are used for the HMAC-SHA256 gateway signature. Never check them into source code or logs.

Complete Integration Example

The walkthrough below uses the classic Asr2Llm mode (text in → LLM text out). Other passive callbacks integrate the same way — only the register* call and the onRequest signature change (see Passive Examples).

java
import com.agibot.aiem.sdk.*;
import com.agibot.aiem.sdk.passive.*;

public class QuickStart {
    public static void main(String[] args) {

        String url = "wss://open.agibot.com/api/V1/open-portal/app/wss/agent-sdk";
        String appId = "your_appId";
        String appKey = "your_appKey";
        String appSecret = "your_appSecret";

        // Step 1: Create SDK instance (singleton - same appId always returns the same instance)
        AgentSdk agentSdk = AgentSdk.create(url, appId, appKey, appSecret);

        // Step 2: Register auth callback (monitor connection state)
        agentSdk.registerAuth((appId1, code, msg) -> {
            if (code == 0) {
                System.out.println("Connection authenticated successfully");
            } else {
                System.err.println("Authentication failed: code=" + code + ", msg=" + msg);
            }
        });

        // Step 3: Register the Asr2Llm callback (robot already did ASR; SDK only runs 语义理解/LLM)
        agentSdk.registerAsr2Llm(new Asr2LlmCallback(agentSdk) {

            @Override
            public void onRobotOnline(String agentId, AgentMeta agentMeta) {
                // Robot comes online, retrieve metadata (wakeup word, city, etc.)
                System.out.println("Robot online: " + agentId);
                System.out.println("Wakeup word: " + agentMeta.getWakeupWord());
            }

            @Override
            public void onRobotOffline(String agentId) {
                // Robot goes offline, clean up related resources
                System.out.println("Robot offline: " + agentId);
            }

            /**
             * @param text     ASR-recognised text from upstream (usually the final ASR)
             * @param param    extension parameters
             * @param response reply object — feed back LLM / skill / interrupt results
             */
            @Override
            public void onRequest(String agentId, String eventId, String text,
                                  AgentParam param, Asr2LlmResponse response) {

                // Run 语义理解 + knowledge lookup + LLM summarisation on `text`
                String itemId = "itemId_000001";

                // Barge-in for valid commands (skip on rejected utterances)
                response.onInterrupt(eventId, "chat", null);

                // Optional skill dispatch
                AgentParam skillParam = AgentParam.create().setInteger("step", 3);
                response.onSkill(eventId, itemId, "movement", "move_forward", skillParam);

                // LLM streaming output
                response.onLlmItemDelta(eventId, itemId, "The weather is nice today, ");
                response.onLlmItemDelta(eventId, itemId, "a great day to go outside.");
                response.onLlmItemDone(eventId, itemId);
                response.onLlmDone(eventId);

                // Error handling (uncomment when needed)
                // response.onError(eventId, 1010, "LLM call failed");
            }
        });

        // Step 4: Initialize (establish WebSocket connection with auto-reconnect)
        agentSdk.initialize();
    }
}

Core Concepts Quick Reference

ConceptDescription
appId / appKey / appSecretObtained from the LinkSoul open platform after creating an application; appKey + appSecret are used for HMAC-SHA256 gateway signing
Passive InteractionRobot initiates request -> SDK processes -> Returns result via Response
Active InteractionSDK initiates a task flow toward the robot (registerTaskFlow)
agentIdThe agent ID configured on the LinkSoul platform (e.g., AGENT_0000001). The robot binds to that agent on-device; once it comes online the SDK delivers it via onRobotOnline(agentId, ...). It is not a hardware/instance identifier
eventIdUnique identifier for one conversation round
itemIdIdentifier for multiple intents/response segments within the same conversation
flagLifecycle flag used by Audio2* / AudioVideo2* / AsrVideo2* callbacks
AgentParamExtension parameters (key-value structure, supports chained calls)
AgentMetaRobot metadata (wakeup word, city, robot name, etc.)

Integration Flow Diagram

text
create() -> registerAuth() -> register*Callback() -> initialize()
                                                        |
                                                        v
                                                  WebSocket Connection
                                                        |
                                              +---------+---------+
                                              v                   v
                                        onAuthState()       onRobotOnline()
                                        (auth result)       (robot online)
                                                                  |
                                                                  v
                                                            onRequest()
                                                          (process audio/text)
                                                                  |
                                                                  v
                                                          response.on*()
                                                          (return results)

Next Steps