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
platformIPlatformAdapterThe platform adapter (Google AI or Vertex AI).
httpClientHttpClientOptional HTTP client.
loggerILoggerOptional 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
requestCreateTriggerRequestThe request (interaction, schedule and time zone are required).
cancellationTokenCancellationTokenA cancellation token.
Returns
DeleteAsync(string, CancellationToken)
Deletes a trigger (DELETE /triggers/{id}).
public Task DeleteAsync(string id, CancellationToken cancellationToken = default)
Parameters
idstringThe trigger ID.
cancellationTokenCancellationTokenA 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
idstringThe trigger ID (a
triggers/prefix is accepted).cancellationTokenCancellationTokenA cancellation token.
Returns
ListAllAsync(string?, int?, CancellationToken)
Lists all triggers, following page tokens.
public IAsyncEnumerable<Trigger> ListAllAsync(string? filter = null, int? pageSize = null, CancellationToken cancellationToken = default)
Parameters
filterstringOptional filter expression.
pageSizeint?The page size.
cancellationTokenCancellationTokenA 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
triggerIdstringThe trigger ID.
pageSizeint?The page size.
cancellationTokenCancellationTokenA 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
filterstringOptional filter expression (sent as
filter).pageSizeint?The maximum number of triggers per page.
pageTokenstringThe page token of a previous call.
cancellationTokenCancellationTokenA 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
triggerIdstringThe trigger ID.
pageSizeint?The maximum number of executions per page.
pageTokenstringThe page token of a previous call.
cancellationTokenCancellationTokenA 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
idstringThe trigger ID.
cancellationTokenCancellationTokenA cancellation token.
Returns
ResumeAsync(string, CancellationToken)
Resumes a trigger (sets its status to Active).
public Task<Trigger> ResumeAsync(string id, CancellationToken cancellationToken = default)
Parameters
idstringThe trigger ID.
cancellationTokenCancellationTokenA cancellation token.
Returns
RunAsync(string, CancellationToken)
Runs a trigger now (POST /triggers/{id}/executions).
public Task<TriggerExecution> RunAsync(string triggerId, CancellationToken cancellationToken = default)
Parameters
triggerIdstringThe trigger ID.
cancellationTokenCancellationTokenA 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
idstringThe trigger ID.
updateUpdateTriggerRequestThe fields to update.
cancellationTokenCancellationTokenA cancellation token.
Returns
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
triggerIdstringThe trigger ID.
executionIdstringThe execution ID (e.g. returned by RunAsync(string, CancellationToken)).
pollIntervalTimeSpan?Delay between polls (default 10 seconds).
timeoutTimeSpan?Optional overall timeout; a TimeoutException is thrown when exceeded.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<TriggerExecution>
The finished execution.