Table of Contents

Class TriggersClient

Namespace
GenerativeAI.Clients
Assembly
GenerativeAI.dll

A client for the Triggers API (/triggers): run an agent interaction on a cron schedule, pause/resume it, run it on demand and inspect its executions. Follows python-genai's client.triggers (experimental).

public class TriggersClient : AgentApiClientBase
Inheritance
TriggersClient
Inherited Members
Extension Methods

Constructors

TriggersClient(IPlatformAdapter, HttpClient?, ILogger?)

Initializes a new instance of the TriggersClient class.

public TriggersClient(IPlatformAdapter platform, HttpClient? httpClient = null, ILogger? logger = null)

Parameters

platform IPlatformAdapter

The platform adapter (Google AI or Vertex AI).

httpClient HttpClient

Optional HTTP client.

logger ILogger

Optional logger.

Methods

CreateAsync(CreateTriggerRequest, CancellationToken)

Creates a trigger (POST /triggers). Like python-genai, an interaction input given as a list of content blocks is sent as a single user_input step.

public Task<Trigger> CreateAsync(CreateTriggerRequest request, CancellationToken cancellationToken = default)

Parameters

request CreateTriggerRequest

The request (interaction, schedule and time zone are required).

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Trigger>

The created trigger.

DeleteAsync(string, CancellationToken)

Deletes a trigger (DELETE /triggers/{id}).

public Task DeleteAsync(string id, CancellationToken cancellationToken = default)

Parameters

id string

The trigger ID.

cancellationToken CancellationToken

A cancellation token.

Returns

Task

A task that completes when the trigger has been deleted.

GetAsync(string, CancellationToken)

Gets a trigger (GET /triggers/{id}).

public Task<Trigger> GetAsync(string id, CancellationToken cancellationToken = default)

Parameters

id string

The trigger ID (a triggers/ prefix is accepted).

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Trigger>

The trigger.

ListAllAsync(string?, int?, CancellationToken)

Lists all triggers, following page tokens.

public IAsyncEnumerable<Trigger> ListAllAsync(string? filter = null, int? pageSize = null, CancellationToken cancellationToken = default)

Parameters

filter string

Optional filter expression.

pageSize int?

The page size.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<Trigger>

The triggers.

ListAllExecutionsAsync(string, int?, CancellationToken)

Lists all executions of a trigger, following page tokens.

public IAsyncEnumerable<TriggerExecution> ListAllExecutionsAsync(string triggerId, int? pageSize = null, CancellationToken cancellationToken = default)

Parameters

triggerId string

The trigger ID.

pageSize int?

The page size.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<TriggerExecution>

The executions.

ListAsync(string?, int?, string?, CancellationToken)

Lists one page of triggers (GET /triggers).

public Task<ListTriggersResponse> ListAsync(string? filter = null, int? pageSize = null, string? pageToken = null, CancellationToken cancellationToken = default)

Parameters

filter string

Optional filter expression (sent as filter).

pageSize int?

The maximum number of triggers per page.

pageToken string

The page token of a previous call.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<ListTriggersResponse>

The page.

ListExecutionsAsync(string, int?, string?, CancellationToken)

Lists one page of the executions of a trigger (GET /triggers/{id}/executions).

public Task<ListTriggerExecutionsResponse> ListExecutionsAsync(string triggerId, int? pageSize = null, string? pageToken = null, CancellationToken cancellationToken = default)

Parameters

triggerId string

The trigger ID.

pageSize int?

The maximum number of executions per page.

pageToken string

The page token of a previous call.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<ListTriggerExecutionsResponse>

The page.

PauseAsync(string, CancellationToken)

Pauses a trigger (sets its status to Paused).

public Task<Trigger> PauseAsync(string id, CancellationToken cancellationToken = default)

Parameters

id string

The trigger ID.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Trigger>

The updated trigger.

ResumeAsync(string, CancellationToken)

Resumes a trigger (sets its status to Active).

public Task<Trigger> ResumeAsync(string id, CancellationToken cancellationToken = default)

Parameters

id string

The trigger ID.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Trigger>

The updated trigger.

RunAsync(string, CancellationToken)

Runs a trigger now (POST /triggers/{id}/executions).

public Task<TriggerExecution> RunAsync(string triggerId, CancellationToken cancellationToken = default)

Parameters

triggerId string

The trigger ID.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<TriggerExecution>

The started execution.

UpdateAsync(string, UpdateTriggerRequest, CancellationToken)

Updates a trigger (PATCH /triggers/{id}), e.g. to rename, pause or resume it.

public Task<Trigger> UpdateAsync(string id, UpdateTriggerRequest update, CancellationToken cancellationToken = default)

Parameters

id string

The trigger ID.

update UpdateTriggerRequest

The fields to update.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Trigger>

The updated trigger.

WaitForExecutionAsync(string, string, TimeSpan?, TimeSpan?, CancellationToken)

Polls the executions of a trigger until the execution executionId is no longer InProgress (the API has no endpoint to get a single execution).

public Task<TriggerExecution> WaitForExecutionAsync(string triggerId, string executionId, TimeSpan? pollInterval = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

triggerId string

The trigger ID.

executionId string

The execution ID (e.g. returned by RunAsync(string, CancellationToken)).

pollInterval TimeSpan?

Delay between polls (default 10 seconds).

timeout TimeSpan?

Optional overall timeout; a TimeoutException is thrown when exceeded.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<TriggerExecution>

The finished execution.