Skip to content

Latest commit

 

History

History
233 lines (155 loc) · 21.2 KB

File metadata and controls

233 lines (155 loc) · 21.2 KB

Client.Agents

Overview

Available Operations

retrieve

Returns details of an agent created in the Agent Builder.

Example Usage

from glean.api_client import Glean
import os


with Glean(
    api_token=os.getenv("GLEAN_API_TOKEN", ""),
) as glean:

    res = glean.client.agents.retrieve(agent_id="<id>")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
agent_id str ✔️ The ID of the agent.
locale Optional[str] 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.
timezone_offset Optional[int] The offset of the client's timezone in minutes from UTC. e.g. PDT is -420 because it's 7 hours behind UTC.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.Agent

Errors

Error Type Status Code Content Type
errors.ErrorResponse 404 application/json
errors.GleanError 4XX, 5XX */*

retrieve_schemas

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

from glean.api_client import Glean
import os


with Glean(
    api_token=os.getenv("GLEAN_API_TOKEN", ""),
) as glean:

    res = glean.client.agents.retrieve_schemas(agent_id="<id>")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
agent_id str ✔️ The ID of the agent.
locale Optional[str] 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.
timezone_offset Optional[int] The offset of the client's timezone in minutes from UTC. e.g. PDT is -420 because it's 7 hours behind UTC.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.AgentSchemas

Errors

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

list

Search for agents by agent name.

Example Usage

from glean.api_client import Glean
import os


with Glean(
    api_token=os.getenv("GLEAN_API_TOKEN", ""),
) as glean:

    res = glean.client.agents.list(name="HR Policy Agent")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
name Optional[str] Filters on the name of the agent. The keyword search is case-insensitive. If search string is ommited or empty, acts as no filter. HR Policy Agent
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.SearchAgentsResponse

Errors

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

run_stream

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

from glean.api_client import Glean
import os


with Glean(
    api_token=os.getenv("GLEAN_API_TOKEN", ""),
) as glean:

    res = glean.client.agents.run_stream(agent_id="<id>", messages=[
        {
            "role": "USER",
        },
    ])

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
agent_id str ✔️ The ID of the agent to run.
input Dict[str, Any] The input to the agent. Required when the agent uses an input form trigger.
messages List[models.Message] The messages to pass an input to the agent.
metadata Dict[str, Any] The metadata to pass to the agent.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

str

Errors

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

from glean.api_client import Glean
import os


with Glean(
    api_token=os.getenv("GLEAN_API_TOKEN", ""),
) as glean:

    res = glean.client.agents.run(agent_id="<id>", messages=[
        {
            "role": "USER",
        },
    ])

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
agent_id str ✔️ The ID of the agent to run.
input Dict[str, Any] The input to the agent. Required when the agent uses an input form trigger.
messages List[models.Message] The messages to pass an input to the agent.
metadata Dict[str, Any] The metadata to pass to the agent.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.AgentRunWaitResponse

Errors

Error Type Status Code Content Type
errors.GleanError 4XX, 5XX */*