Skip to content

Latest commit

 

History

History
287 lines (201 loc) · 18 KB

File metadata and controls

287 lines (201 loc) · 18 KB

Client.Agents

Overview

Available Operations

  • retrieve - Retrieve an agent
  • retrieveSchemas - List an agent's schemas
  • list - Search agents
  • runStream - Create an agent run and stream the response
  • run - Create an agent run and wait for the response

retrieve

Returns details of an agent created in the Agent Builder.

Example Usage

package hello.world;

import com.glean.api_client.glean_api_client.Glean;
import com.glean.api_client.glean_api_client.models.operations.GetAgentResponse;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws Exception {

        Glean sdk = Glean.builder()
                .apiToken(System.getenv().getOrDefault("GLEAN_API_TOKEN", ""))
            .build();

        GetAgentResponse res = sdk.client().agents().retrieve()
                .agentId("<id>")
                .call();

        if (res.agent().isPresent()) {
            // handle response
        }
    }
}

Parameters

Parameter Type Required Description
locale Optional<String> The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en.
timezoneOffset Optional<Long> The offset of the client's timezone in minutes from UTC. e.g. PDT is -420 because it's 7 hours behind UTC.
agentId String ✔️ The ID of the agent.

Response

GetAgentResponse

Errors

Error Type Status Code Content Type
models/errors/APIException 4XX, 5XX */*

retrieveSchemas

Return agent's input and output schemas. You can use these schemas to detect changes to an agent's input or output structure.

Example Usage

package hello.world;

import com.glean.api_client.glean_api_client.Glean;
import com.glean.api_client.glean_api_client.models.operations.GetAgentSchemasResponse;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws Exception {

        Glean sdk = Glean.builder()
                .apiToken(System.getenv().getOrDefault("GLEAN_API_TOKEN", ""))
            .build();

        GetAgentSchemasResponse res = sdk.client().agents().retrieveSchemas()
                .agentId("<id>")
                .call();

        if (res.agentSchemas().isPresent()) {
            // handle response
        }
    }
}

Parameters

Parameter Type Required Description
locale Optional<String> The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en.
timezoneOffset Optional<Long> The offset of the client's timezone in minutes from UTC. e.g. PDT is -420 because it's 7 hours behind UTC.
agentId String ✔️ The ID of the agent.

Response

GetAgentSchemasResponse

Errors

Error Type Status Code Content Type
models/errors/APIException 4XX, 5XX */*

list

Search for agents by agent name.

Example Usage

package hello.world;

import com.glean.api_client.glean_api_client.Glean;
import com.glean.api_client.glean_api_client.models.components.SearchAgentsRequest;
import com.glean.api_client.glean_api_client.models.operations.SearchAgentsResponse;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws Exception {

        Glean sdk = Glean.builder()
                .apiToken(System.getenv().getOrDefault("GLEAN_API_TOKEN", ""))
            .build();

        SearchAgentsRequest req = SearchAgentsRequest.builder()
                .name("HR Policy Agent")
                .build();

        SearchAgentsResponse res = sdk.client().agents().list()
                .request(req)
                .call();

        if (res.searchAgentsResponse().isPresent()) {
            // handle response
        }
    }
}

Parameters

Parameter Type Required Description
request SearchAgentsRequest ✔️ The request object to use for the request.

Response

SearchAgentsResponse

Errors

Error Type Status Code Content Type
models/errors/APIException 4XX, 5XX */*

runStream

Executes an agent run and returns the result as a stream of server-sent events (SSE). Note: If the agent uses an input form trigger, all form fields (including optional fields) must be included in the input object.

Example Usage

package hello.world;

import com.glean.api_client.glean_api_client.Glean;
import com.glean.api_client.glean_api_client.models.components.AgentRunCreate;
import com.glean.api_client.glean_api_client.models.components.Message;
import com.glean.api_client.glean_api_client.models.operations.CreateAndStreamRunResponse;
import java.lang.Exception;
import java.util.List;

public class Application {

    public static void main(String[] args) throws Exception {

        Glean sdk = Glean.builder()
                .apiToken(System.getenv().getOrDefault("GLEAN_API_TOKEN", ""))
            .build();

        AgentRunCreate req = AgentRunCreate.builder()
                .agentId("<id>")
                .messages(List.of(
                    Message.builder()
                        .role("USER")
                        .build()))
                .build();

        CreateAndStreamRunResponse res = sdk.client().agents().runStream()
                .request(req)
                .call();

        if (res.res().isPresent()) {
            // handle response
        }
    }
}

Parameters

Parameter Type Required Description
request AgentRunCreate ✔️ The request object to use for the request.

Response

CreateAndStreamRunResponse

Errors

Error Type Status Code Content Type
models/errors/APIException 4XX, 5XX */*

run

Executes an agent run and returns the final response. Note: If the agent uses an input form trigger, all form fields (including optional fields) must be included in the input object.

Example Usage

package hello.world;

import com.glean.api_client.glean_api_client.Glean;
import com.glean.api_client.glean_api_client.models.components.AgentRunCreate;
import com.glean.api_client.glean_api_client.models.components.Message;
import com.glean.api_client.glean_api_client.models.operations.CreateAndWaitRunResponse;
import java.lang.Exception;
import java.util.List;

public class Application {

    public static void main(String[] args) throws Exception {

        Glean sdk = Glean.builder()
                .apiToken(System.getenv().getOrDefault("GLEAN_API_TOKEN", ""))
            .build();

        AgentRunCreate req = AgentRunCreate.builder()
                .agentId("<id>")
                .messages(List.of(
                    Message.builder()
                        .role("USER")
                        .build()))
                .build();

        CreateAndWaitRunResponse res = sdk.client().agents().run()
                .request(req)
                .call();

        if (res.agentRunWaitResponse().isPresent()) {
            // handle response
        }
    }
}

Parameters

Parameter Type Required Description
request AgentRunCreate ✔️ The request object to use for the request.

Response

CreateAndWaitRunResponse

Errors

Error Type Status Code Content Type
models/errors/APIException 4XX, 5XX */*