Skip to content

Latest commit

 

History

History
298 lines (225 loc) · 22.1 KB

File metadata and controls

298 lines (225 loc) · 22.1 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 main

import(
	"context"
	"os"
	apiclientgo "github.com/gleanwork/api-client-go"
	"log"
)

func main() {
    ctx := context.Background()

    s := apiclientgo.New(
        apiclientgo.WithSecurity(os.Getenv("GLEAN_API_TOKEN")),
    )

    res, err := s.Client.Agents.Retrieve(ctx, "<id>", nil, nil)
    if err != nil {
        log.Fatal(err)
    }
    if res.Agent != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
agentID string ✔️ The ID of the agent.
locale *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 *int64 The offset of the client's timezone in minutes from UTC. e.g. PDT is -420 because it's 7 hours behind UTC.
opts []operations.Option The options for this request.

Response

*operations.GetAgentResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorResponse 404 application/json
apierrors.APIError 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 main

import(
	"context"
	"os"
	apiclientgo "github.com/gleanwork/api-client-go"
	"log"
)

func main() {
    ctx := context.Background()

    s := apiclientgo.New(
        apiclientgo.WithSecurity(os.Getenv("GLEAN_API_TOKEN")),
    )

    res, err := s.Client.Agents.RetrieveSchemas(ctx, "<id>", nil, nil)
    if err != nil {
        log.Fatal(err)
    }
    if res.AgentSchemas != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
agentID string ✔️ The ID of the agent.
locale *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 *int64 The offset of the client's timezone in minutes from UTC. e.g. PDT is -420 because it's 7 hours behind UTC.
opts []operations.Option The options for this request.

Response

*operations.GetAgentSchemasResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorResponse 404, 422 application/json
apierrors.APIError 4XX, 5XX */*

List

Search for agents by agent name.

Example Usage

package main

import(
	"context"
	"os"
	apiclientgo "github.com/gleanwork/api-client-go"
	"github.com/gleanwork/api-client-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := apiclientgo.New(
        apiclientgo.WithSecurity(os.Getenv("GLEAN_API_TOKEN")),
    )

    res, err := s.Client.Agents.List(ctx, components.SearchAgentsRequest{
        Name: apiclientgo.Pointer("HR Policy Agent"),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.SearchAgentsResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request components.SearchAgentsRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.SearchAgentsResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorResponse 404, 422 application/json
apierrors.APIError 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 main

import(
	"context"
	"os"
	apiclientgo "github.com/gleanwork/api-client-go"
	"github.com/gleanwork/api-client-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := apiclientgo.New(
        apiclientgo.WithSecurity(os.Getenv("GLEAN_API_TOKEN")),
    )

    res, err := s.Client.Agents.RunStream(ctx, components.AgentRunCreate{
        AgentID: "<id>",
        Messages: []components.Message{
            components.Message{
                Role: apiclientgo.Pointer("USER"),
            },
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.Res != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request components.AgentRunCreate ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.CreateAndStreamRunResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorResponse 404, 409, 422 application/json
apierrors.APIError 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 main

import(
	"context"
	"os"
	apiclientgo "github.com/gleanwork/api-client-go"
	"github.com/gleanwork/api-client-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := apiclientgo.New(
        apiclientgo.WithSecurity(os.Getenv("GLEAN_API_TOKEN")),
    )

    res, err := s.Client.Agents.Run(ctx, components.AgentRunCreate{
        AgentID: "<id>",
        Messages: []components.Message{
            components.Message{
                Role: apiclientgo.Pointer("USER"),
            },
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.AgentRunWaitResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request components.AgentRunCreate ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.CreateAndWaitRunResponse, error

Errors

Error Type Status Code Content Type
apierrors.APIError 4XX, 5XX */*