archastro.platform.v1.resources.agent_routines
1# Copyright (c) 2026 ArchAstro Inc. All Rights Reserved. 2# This file is auto-generated by @archastro/sdk-generator. Do not edit. 3# Content hash: 90784a3896e9 4 5from __future__ import annotations 6 7import builtins 8from typing import Any, Required, TypedDict 9 10from ...runtime.http_client import HttpClient, SyncHttpClient 11from ...types.common import ( 12 AgentRoutine, 13 AgentRoutineListResponse, 14 AgentRoutineRun, 15 AgentRoutineRunListResponse, 16 RoutinePreset, 17) 18 19 20class AgentRoutineUpdateInputAclAddItem(TypedDict, total=False): 21 actions: Required[list[str]] 22 'Array of action strings the principal is permitted to perform, e.g. `["read", "write"]`. Must contain at least one entry.' 23 principal: str | None 24 'The identifier of the principal. A string ID for `"user"`, `"team"`, `"org"`, and `"agent"` types; one of `"admin"`, `"member"`, or `"viewer"` for `"org_role"`; omit entirely when `principal_type` is `"everyone"`.' 25 principal_type: Required[str] 26 'The kind of principal receiving the grant. One of `"user"`, `"team"`, `"org"`, `"org_role"`, `"agent"`, or `"everyone"`.' 27 28 29class AgentRoutineUpdateInputAclGrantsItem(TypedDict, total=False): 30 actions: Required[list[str]] 31 'Array of action strings the principal is permitted to perform, e.g. `["read", "write"]`. Must contain at least one entry.' 32 principal: str | None 33 'The identifier of the principal. A string ID for `"user"`, `"team"`, `"org"`, and `"agent"` types; one of `"admin"`, `"member"`, or `"viewer"` for `"org_role"`; omit entirely when `principal_type` is `"everyone"`.' 34 principal_type: Required[str] 35 'The kind of principal receiving the grant. One of `"user"`, `"team"`, `"org"`, `"org_role"`, `"agent"`, or `"everyone"`.' 36 37 38class AgentRoutineUpdateInputAclRemoveItem(TypedDict, total=False): 39 principal: str | None 40 'The identifier of the principal to remove. A string ID for `"user"`, `"team"`, `"org"`, and `"agent"` types; one of `"admin"`, `"member"`, or `"viewer"` for `"org_role"`. Omit when `principal_type` is `"everyone"`.' 41 principal_type: Required[str] 42 'The kind of principal to remove. One of `"user"`, `"team"`, `"org"`, `"org_role"`, `"agent"`, or `"everyone"`.' 43 44 45class AgentRoutineUpdateInputAcl(TypedDict, total=False): 46 add: list[AgentRoutineUpdateInputAclAddItem] | None 47 "Patch mode: grants to add or merge into the existing list. Cannot be combined with `grants`." 48 grants: list[AgentRoutineUpdateInputAclGrantsItem] | None 49 "Replace mode: the complete new list of grants that replaces all existing entries. Send an empty array (`[]`) to clear all grants. Cannot be combined with `add` or `remove`." 50 remove: list[AgentRoutineUpdateInputAclRemoveItem] | None 51 "Patch mode: principals whose grants should be removed from the existing list. Cannot be combined with `grants`." 52 53 54class AgentRoutineUpdateInputPresetConfigLlm(TypedDict, total=False): 55 model: str | None 56 'Model identifier to use for this routine or step, e.g. `"claude-sonnet-4-5"`. When omitted, the agent\'s default model is used.' 57 58 59class AgentRoutineUpdateInputPresetConfig(TypedDict, total=False): 60 instructions: str | None 61 "Custom task or behavior instructions for the preset (max 10,000 chars)." 62 llm: AgentRoutineUpdateInputPresetConfigLlm | None 63 "LLM invocation settings (e.g. a `model` override for this routine/step)." 64 session_mode: str | None 65 "Session mode: `stateless` (default, new session per trigger) or `session` (find-or-create a persistent session scoped by `session_scope`)." 66 session_scope: str | None 67 "When `session_mode` is `session`, controls session scoping: `per_user` (default), `per_key`, `per_org`, or `global`." 68 structured_message_template_ids: list[str] | None 69 "IDs of structured message templates that constrain the agent's responses to predefined structured formats." 70 71 72class AgentRoutineUpdateInputStepsItemPresetConfigLlm(TypedDict, total=False): 73 model: str | None 74 'Model identifier to use for this routine or step, e.g. `"claude-sonnet-4-5"`. When omitted, the agent\'s default model is used.' 75 76 77class AgentRoutineUpdateInputStepsItemPresetConfig(TypedDict, total=False): 78 instructions: str | None 79 "Custom task or behavior instructions for the preset (max 10,000 chars)." 80 llm: AgentRoutineUpdateInputStepsItemPresetConfigLlm | None 81 "LLM invocation settings (e.g. a `model` override for this routine/step)." 82 session_mode: str | None 83 "Session mode: `stateless` (default, new session per trigger) or `session` (find-or-create a persistent session scoped by `session_scope`)." 84 session_scope: str | None 85 "When `session_mode` is `session`, controls session scoping: `per_user` (default), `per_key`, `per_org`, or `global`." 86 structured_message_template_ids: list[str] | None 87 "IDs of structured message templates that constrain the agent's responses to predefined structured formats." 88 89 90class AgentRoutineUpdateInputStepsItem(TypedDict, total=False): 91 config: str | None 92 'ID of a saved config to use as the handler body. Required when `handler_type` is `"workflow_graph"`; also accepted for `"script"` as an alternative to an inline `script` value.' 93 handler_type: Required[str] 94 'Execution handler for this step. One of `"preset"`, `"script"`, or `"workflow_graph"`.' 95 inputs: dict[str, Any] | None 96 "Optional key-value map binding outputs from prior steps to this step's input variables." 97 name: str | None 98 "Optional label for this step. Must be unique within the chain when provided." 99 on_error: str | None 100 'Error handling policy for this step. One of `"halt"` (default), `"continue"`, or `"retry"`.' 101 output_key: str | None 102 "Key under which this step's result is stored and addressable by downstream steps. Defaults to `name` when omitted." 103 preset_config: AgentRoutineUpdateInputStepsItemPresetConfig | None 104 "Configuration overrides for the preset, using the same shape as the routine-level `preset_config`. You may include an `llm` key to override the agent's default model for this step. `null` if not provided." 105 preset_name: str | None 106 'Name of the preset to invoke. Required when `handler_type` is `"preset"`.' 107 script: str | None 108 'Inline script source code to execute. Used when `handler_type` is `"script"` and no `config` is provided.' 109 110 111class AgentRoutineUpdateInput(TypedDict, total=False): 112 "Update a routine" 113 114 acl: AgentRoutineUpdateInputAcl | None 115 "Updated access control list. Replaces the existing ACL entirely." 116 config: str | None 117 'Workflow config ID (`cfg_...`). Used when `handler_type` is `"workflow_graph"`.' 118 description: str | None 119 "New human-readable description of what this routine does." 120 event_config: dict[str, Any] | None 121 'Mapping of event types to trigger configuration. Each key is an event type string; each value is an object with a `"filters"` map and an optional `"dedupe_key_path"` (a JSON path used to deduplicate events, e.g. `"$.thread.id"`).' 122 event_type: str | None 123 "Event type that triggers this routine. Deprecated use `event_config` instead." 124 handler_type: str | None 125 'New execution model. One of `"workflow_graph"`, `"script"`, `"preset"`, or `"chain"`.' 126 lookup_key: str | None 127 "New stable, unique key for deterministic lookup. Must be unique within the app." 128 metadata: dict[str, Any] | None 129 "Updated arbitrary key-value metadata. Replaces the existing metadata entirely." 130 name: str | None 131 "New human-readable display name for the routine." 132 preset_config: AgentRoutineUpdateInputPresetConfig | None 133 "Updated configuration passed to the preset at runtime." 134 preset_name: str | None 135 'Name of the registered preset to use. Used when `handler_type` is `"preset"`.' 136 schedule: str | None 137 'New cron expression for time-triggered routines (e.g. `"0 9 * * 1"`). Must not be more frequent than once per hour.' 138 script: str | None 139 'New inline script source. Used when `handler_type` is `"script"`.' 140 steps: list[AgentRoutineUpdateInputStepsItem] | None 141 'Updated ordered list of steps for a chain handler. Required when `handler_type` is `"chain"`; must be omitted or empty otherwise. Replaces the entire existing step list send the full desired list, not a partial diff.' 142 template: str | None 143 "AgentRoutineTemplate config ID (`cfg_...`) or lookup key. When provided, the routine's configuration is re-resolved from the template before applying other param overrides. The routine's `status`, `lookup_key`, and agent attachment are always preserved." 144 trigger_context: str | None 145 'Updated trigger context. One of `"chat_session"` or `"event"`.' 146 147 148class AgentRoutineInvokeInput(TypedDict, total=False): 149 "Invoke a routine" 150 151 idempotency_key: str | None 152 "Unique key used to deduplicate invocations. Resubmitting the same key returns 409 if a completed run already exists." 153 message: Required[str] 154 "The user message to send to the agent for this invocation." 155 metadata: dict[str, Any] | None 156 "Arbitrary key-value metadata attached to this invocation. Not interpreted by the platform." 157 session_key: str | None 158 'Arbitrary key used to identify and resume a session when `session_scope` is `"per_key"`. Required in that mode.' 159 thread_id: str | None 160 "Thread ID (`thr_...`) to post the preset output into. Omit to skip thread posting." 161 user: str | None 162 "User ID to associate with the session. For S2S and developer callers only; authenticated client callers always use their own identity." 163 164 165class AsyncAgentRoutineRunResource: 166 def __init__(self, http: HttpClient): 167 self._http = http 168 169 async def get(self, run: str) -> AgentRoutineRun: 170 """ 171 Retrieve a routine run 172 Returns a single routine run by its ID. The run includes status, payload, 173 result, duration, and any structured response produced by the routine's agent. 174 The authenticated principal must have access to the app that owns the run. 175 When your API key is scoped to an app, the run must belong to that app or 176 a 403 is returned. 177 178 Args: 179 run: Routine run ID (`arr_...`) to retrieve. 180 181 Returns: 182 The requested routine run. 183 """ 184 return await self._http.request( 185 f"/api/v1/agent_routines/runs/{run}", 186 response_type=AgentRoutineRun, 187 ) 188 189 190class AsyncAgentRoutineResource: 191 def __init__(self, http: HttpClient): 192 self._http = http 193 self.agent_routine_runs = AsyncAgentRoutineRunResource(http) 194 195 async def list( 196 self, *, agent: str | None = None, event_type: str | None = None 197 ) -> AgentRoutineListResponse: 198 """ 199 List routines 200 Returns all routines within the authenticated app scope. Optionally filter by 201 agent or event type. When `agent` is omitted, all routines accessible to the 202 caller are returned regardless of which agent they belong to. 203 If `agent` is provided but does not exist or is not accessible, the endpoint 204 returns 404 rather than an empty list. Results are not paginated; all matching 205 routines are returned in a single response. Requires app scope. 206 207 Args: 208 agent: Agent ID (`agt_...`) to filter routines by. Omit to return routines across all agents. 209 event_type: Event type string to filter by (e.g. `"agentroutine.invoked"`). Omit to return routines for all event types. 210 211 Returns: 212 Object containing a `data` array of matching routines. 213 """ 214 query: dict[str, object] = {} 215 if agent is not None: 216 query["agent"] = agent 217 if event_type is not None: 218 query["event_type"] = event_type 219 return await self._http.request( 220 "/api/v1/agent_routines", 221 query=query, 222 response_type=AgentRoutineListResponse, 223 ) 224 225 async def presets(self) -> builtins.list[RoutinePreset]: 226 """ 227 List routine presets 228 Returns all registered routine presets available to the authenticated app, 229 including each preset's name, display metadata, and accepted configuration 230 schema. Use this endpoint to discover which presets can be referenced when 231 creating or updating a routine with `handler_type: "preset"`. 232 The list reflects presets registered at server start time and does not change 233 at runtime. Requires app scope. 234 235 Returns: 236 Array of available routine preset objects. 237 """ 238 return await self._http.request( 239 "/api/v1/agent_routines/presets", 240 response_type=list[RoutinePreset], 241 ) 242 243 async def delete(self, routine: str) -> None: 244 """ 245 Delete a routine 246 Permanently deletes the specified routine. This action is irreversible the 247 routine and its configuration are removed immediately. Any in-flight event 248 processing initiated by this routine before deletion may still complete. 249 Requires app scope. Returns 204 No Content on success. 250 251 Args: 252 routine: Routine ID (`arn_...`) of the routine to delete. 253 254 Returns: 255 Empty response on successful deletion (HTTP 204 No Content). 256 """ 257 await self._http.request(f"/api/v1/agent_routines/{routine}", method="DELETE") 258 259 async def get(self, routine: str) -> AgentRoutine: 260 """ 261 Retrieve a routine 262 Returns the full routine record for the given routine ID. Use this endpoint to 263 inspect a routine's current configuration, handler type, event config, schedule, 264 and lifecycle status. 265 Requires app scope. Returns 404 if the routine does not exist or is not 266 accessible to the caller. 267 268 Args: 269 routine: Routine ID (`arn_...`) of the routine to retrieve. 270 271 Returns: 272 The requested routine. 273 """ 274 return await self._http.request( 275 f"/api/v1/agent_routines/{routine}", 276 response_type=AgentRoutine, 277 ) 278 279 async def update(self, routine: str, input: AgentRoutineUpdateInput) -> AgentRoutine: 280 """ 281 Update a routine 282 Updates one or more fields of the specified routine. Only the fields you 283 include are changed; omitted fields retain their current values. To change the 284 execution model, supply a new `handler_type` along with its required handler 285 body field (`config`, `script`, or `preset_name`). 286 When `template` is supplied, the routine's configuration is re-resolved from 287 the template before applying any additional field overrides. The routine's 288 `status`, `lookup_key`, and agent attachment are always preserved regardless 289 of template content. Updating `steps` replaces the entire step list send 290 the full desired list, not a partial diff. Requires app scope. 291 292 Args: 293 routine: Routine ID (`arn_...`) of the routine to update. 294 input: Request body. 295 input.acl: Updated access control list. Replaces the existing ACL entirely. 296 input.config: Workflow config ID (`cfg_...`). Used when `handler_type` is `"workflow_graph"`. 297 input.description: New human-readable description of what this routine does. 298 input.event_config: Mapping of event types to trigger configuration. Each key is an event type string; each value is an object with a `"filters"` map and an optional `"dedupe_key_path"` (a JSON path used to deduplicate events, e.g. `"$.thread.id"`). 299 input.event_type: Event type that triggers this routine. Deprecated use `event_config` instead. 300 input.handler_type: New execution model. One of `"workflow_graph"`, `"script"`, `"preset"`, or `"chain"`. 301 input.lookup_key: New stable, unique key for deterministic lookup. Must be unique within the app. 302 input.metadata: Updated arbitrary key-value metadata. Replaces the existing metadata entirely. 303 input.name: New human-readable display name for the routine. 304 input.preset_config: Updated configuration passed to the preset at runtime. 305 input.preset_name: Name of the registered preset to use. Used when `handler_type` is `"preset"`. 306 input.schedule: New cron expression for time-triggered routines (e.g. `"0 9 * * 1"`). Must not be more frequent than once per hour. 307 input.script: New inline script source. Used when `handler_type` is `"script"`. 308 input.steps: Updated ordered list of steps for a chain handler. Required when `handler_type` is `"chain"`; must be omitted or empty otherwise. Replaces the entire existing step list send the full desired list, not a partial diff. 309 input.template: AgentRoutineTemplate config ID (`cfg_...`) or lookup key. When provided, the routine's configuration is re-resolved from the template before applying other param overrides. The routine's `status`, `lookup_key`, and agent attachment are always preserved. 310 input.trigger_context: Updated trigger context. One of `"chat_session"` or `"event"`. 311 312 Returns: 313 The updated routine. 314 """ 315 return await self._http.request( 316 f"/api/v1/agent_routines/{routine}", 317 method="PATCH", 318 body=input, 319 response_type=AgentRoutine, 320 ) 321 322 async def activate(self, routine: str) -> AgentRoutine: 323 """ 324 Activate a routine 325 Sets the routine's status to `"active"`, enabling it to process events or run 326 on its configured schedule. Only routines that have a workflow config attached 327 can be activated; attempting to activate a routine with no config returns 422. 328 Scheduled routines must be configured to run no more frequently than once per 329 hour. Activation fails with 422 if the cron schedule is more frequent than 330 that limit. Requires app scope. 331 332 Args: 333 routine: Routine ID (`arn_...`) of the routine to activate. 334 335 Returns: 336 The updated routine with `status` set to `"active"`. 337 """ 338 return await self._http.request( 339 f"/api/v1/agent_routines/{routine}/activate", 340 method="POST", 341 response_type=AgentRoutine, 342 ) 343 344 async def invoke(self, routine: str, input: AgentRoutineInvokeInput) -> AgentRoutineRun: 345 """ 346 Invoke a routine 347 Triggers an on-demand invocation of the specified routine, dispatching an 348 asynchronous agent run and returning a run record immediately. The routine must 349 be active and must have `event_type` set to `"agentroutine.invoked"`. 350 The routine's `preset_config.session_mode` determines session behavior: each 351 call may create a new session (`"stateless"`) or reuse an existing one 352 (`"session"`). When `session_scope` is `"per_user"`, the `user` param is 353 required for S2S and developer callers; authenticated client callers always 354 use their own identity. When `session_scope` is `"per_key"`, `session_key` 355 is required. 356 Supply `idempotency_key` to safely retry invocations if a completed run 357 already exists for that key a 409 Conflict is returned rather than creating 358 a duplicate run. Entitlement for LLM calls is checked at request time; 359 customers on plans that do not include this feature receive 402. 360 361 Args: 362 routine: Routine ID (`arn_...`) or `lookup_key` of the routine to invoke. 363 input: Request body. 364 input.idempotency_key: Unique key used to deduplicate invocations. Resubmitting the same key returns 409 if a completed run already exists. 365 input.message: The user message to send to the agent for this invocation. 366 input.metadata: Arbitrary key-value metadata attached to this invocation. Not interpreted by the platform. 367 input.session_key: Arbitrary key used to identify and resume a session when `session_scope` is `"per_key"`. Required in that mode. 368 input.thread_id: Thread ID (`thr_...`) to post the preset output into. Omit to skip thread posting. 369 input.user: User ID to associate with the session. For S2S and developer callers only; authenticated client callers always use their own identity. 370 371 Returns: 372 The agent routine run created by this invocation. 373 """ 374 return await self._http.request( 375 f"/api/v1/agent_routines/{routine}/invoke", 376 method="POST", 377 body=input, 378 response_type=AgentRoutineRun, 379 ) 380 381 async def pause(self, routine: str) -> AgentRoutine: 382 """ 383 Pause a routine 384 Sets the routine's status to `"paused"`, suspending event processing and 385 scheduled execution without deleting the routine or its configuration. A 386 paused routine can be resumed at any time by calling the activate endpoint. 387 Requires app scope. 388 389 Args: 390 routine: Routine ID (`arn_...`) of the routine to pause. 391 392 Returns: 393 The updated routine with `status` set to `"paused"`. 394 """ 395 return await self._http.request( 396 f"/api/v1/agent_routines/{routine}/pause", 397 method="POST", 398 response_type=AgentRoutine, 399 ) 400 401 async def runs( 402 self, 403 routine: str, 404 *, 405 status: str | None = None, 406 limit: int | None = None, 407 before_cursor: str | None = None, 408 after_cursor: str | None = None, 409 ) -> AgentRoutineRunListResponse: 410 """ 411 List runs for a routine 412 Returns a cursor-paginated list of runs for the specified routine, ordered 413 from most recent to oldest by default. Use `before_cursor` and `after_cursor` 414 to page through results in either direction. 415 You can filter runs by status to monitor a specific lifecycle phase. The 416 authenticated principal must have access to the routine's parent app. When 417 your API key is scoped to an app, only runs belonging to that app are 418 returned. 419 420 Args: 421 routine: Routine ID (`rtn_...`) whose runs you want to list. 422 status: Filter runs by status. One of `"pending"`, `"running"`, `"completed"`, `"failed"`, or `"skipped"`. Omit to return runs in all statuses. 423 limit: Maximum number of runs to return per page. Defaults to 50; maximum is 100. 424 before_cursor: Opaque cursor from a previous response's `before_cursor` field. Returns the page of runs older than this cursor. 425 after_cursor: Opaque cursor from a previous response's `after_cursor` field. Returns the page of runs newer than this cursor. 426 427 Returns: 428 Paginated list of routine runs. 429 """ 430 query: dict[str, object] = {} 431 if status is not None: 432 query["status"] = status 433 if limit is not None: 434 query["limit"] = limit 435 if before_cursor is not None: 436 query["before_cursor"] = before_cursor 437 if after_cursor is not None: 438 query["after_cursor"] = after_cursor 439 return await self._http.request( 440 f"/api/v1/agent_routines/{routine}/runs", 441 query=query, 442 response_type=AgentRoutineRunListResponse, 443 ) 444 445 446class AgentRoutineRunResource: 447 def __init__(self, http: SyncHttpClient): 448 self._http = http 449 450 def get(self, run: str) -> AgentRoutineRun: 451 """ 452 Retrieve a routine run 453 Returns a single routine run by its ID. The run includes status, payload, 454 result, duration, and any structured response produced by the routine's agent. 455 The authenticated principal must have access to the app that owns the run. 456 When your API key is scoped to an app, the run must belong to that app or 457 a 403 is returned. 458 459 Args: 460 run: Routine run ID (`arr_...`) to retrieve. 461 462 Returns: 463 The requested routine run. 464 """ 465 return self._http.request( 466 f"/api/v1/agent_routines/runs/{run}", 467 response_type=AgentRoutineRun, 468 ) 469 470 471class AgentRoutineResource: 472 def __init__(self, http: SyncHttpClient): 473 self._http = http 474 self.agent_routine_runs = AgentRoutineRunResource(http) 475 476 def list( 477 self, *, agent: str | None = None, event_type: str | None = None 478 ) -> AgentRoutineListResponse: 479 """ 480 List routines 481 Returns all routines within the authenticated app scope. Optionally filter by 482 agent or event type. When `agent` is omitted, all routines accessible to the 483 caller are returned regardless of which agent they belong to. 484 If `agent` is provided but does not exist or is not accessible, the endpoint 485 returns 404 rather than an empty list. Results are not paginated; all matching 486 routines are returned in a single response. Requires app scope. 487 488 Args: 489 agent: Agent ID (`agt_...`) to filter routines by. Omit to return routines across all agents. 490 event_type: Event type string to filter by (e.g. `"agentroutine.invoked"`). Omit to return routines for all event types. 491 492 Returns: 493 Object containing a `data` array of matching routines. 494 """ 495 query: dict[str, object] = {} 496 if agent is not None: 497 query["agent"] = agent 498 if event_type is not None: 499 query["event_type"] = event_type 500 return self._http.request( 501 "/api/v1/agent_routines", 502 query=query, 503 response_type=AgentRoutineListResponse, 504 ) 505 506 def presets(self) -> builtins.list[RoutinePreset]: 507 """ 508 List routine presets 509 Returns all registered routine presets available to the authenticated app, 510 including each preset's name, display metadata, and accepted configuration 511 schema. Use this endpoint to discover which presets can be referenced when 512 creating or updating a routine with `handler_type: "preset"`. 513 The list reflects presets registered at server start time and does not change 514 at runtime. Requires app scope. 515 516 Returns: 517 Array of available routine preset objects. 518 """ 519 return self._http.request( 520 "/api/v1/agent_routines/presets", 521 response_type=list[RoutinePreset], 522 ) 523 524 def delete(self, routine: str) -> None: 525 """ 526 Delete a routine 527 Permanently deletes the specified routine. This action is irreversible the 528 routine and its configuration are removed immediately. Any in-flight event 529 processing initiated by this routine before deletion may still complete. 530 Requires app scope. Returns 204 No Content on success. 531 532 Args: 533 routine: Routine ID (`arn_...`) of the routine to delete. 534 535 Returns: 536 Empty response on successful deletion (HTTP 204 No Content). 537 """ 538 self._http.request(f"/api/v1/agent_routines/{routine}", method="DELETE") 539 540 def get(self, routine: str) -> AgentRoutine: 541 """ 542 Retrieve a routine 543 Returns the full routine record for the given routine ID. Use this endpoint to 544 inspect a routine's current configuration, handler type, event config, schedule, 545 and lifecycle status. 546 Requires app scope. Returns 404 if the routine does not exist or is not 547 accessible to the caller. 548 549 Args: 550 routine: Routine ID (`arn_...`) of the routine to retrieve. 551 552 Returns: 553 The requested routine. 554 """ 555 return self._http.request(f"/api/v1/agent_routines/{routine}", response_type=AgentRoutine) 556 557 def update(self, routine: str, input: AgentRoutineUpdateInput) -> AgentRoutine: 558 """ 559 Update a routine 560 Updates one or more fields of the specified routine. Only the fields you 561 include are changed; omitted fields retain their current values. To change the 562 execution model, supply a new `handler_type` along with its required handler 563 body field (`config`, `script`, or `preset_name`). 564 When `template` is supplied, the routine's configuration is re-resolved from 565 the template before applying any additional field overrides. The routine's 566 `status`, `lookup_key`, and agent attachment are always preserved regardless 567 of template content. Updating `steps` replaces the entire step list send 568 the full desired list, not a partial diff. Requires app scope. 569 570 Args: 571 routine: Routine ID (`arn_...`) of the routine to update. 572 input: Request body. 573 input.acl: Updated access control list. Replaces the existing ACL entirely. 574 input.config: Workflow config ID (`cfg_...`). Used when `handler_type` is `"workflow_graph"`. 575 input.description: New human-readable description of what this routine does. 576 input.event_config: Mapping of event types to trigger configuration. Each key is an event type string; each value is an object with a `"filters"` map and an optional `"dedupe_key_path"` (a JSON path used to deduplicate events, e.g. `"$.thread.id"`). 577 input.event_type: Event type that triggers this routine. Deprecated use `event_config` instead. 578 input.handler_type: New execution model. One of `"workflow_graph"`, `"script"`, `"preset"`, or `"chain"`. 579 input.lookup_key: New stable, unique key for deterministic lookup. Must be unique within the app. 580 input.metadata: Updated arbitrary key-value metadata. Replaces the existing metadata entirely. 581 input.name: New human-readable display name for the routine. 582 input.preset_config: Updated configuration passed to the preset at runtime. 583 input.preset_name: Name of the registered preset to use. Used when `handler_type` is `"preset"`. 584 input.schedule: New cron expression for time-triggered routines (e.g. `"0 9 * * 1"`). Must not be more frequent than once per hour. 585 input.script: New inline script source. Used when `handler_type` is `"script"`. 586 input.steps: Updated ordered list of steps for a chain handler. Required when `handler_type` is `"chain"`; must be omitted or empty otherwise. Replaces the entire existing step list send the full desired list, not a partial diff. 587 input.template: AgentRoutineTemplate config ID (`cfg_...`) or lookup key. When provided, the routine's configuration is re-resolved from the template before applying other param overrides. The routine's `status`, `lookup_key`, and agent attachment are always preserved. 588 input.trigger_context: Updated trigger context. One of `"chat_session"` or `"event"`. 589 590 Returns: 591 The updated routine. 592 """ 593 return self._http.request( 594 f"/api/v1/agent_routines/{routine}", 595 method="PATCH", 596 body=input, 597 response_type=AgentRoutine, 598 ) 599 600 def activate(self, routine: str) -> AgentRoutine: 601 """ 602 Activate a routine 603 Sets the routine's status to `"active"`, enabling it to process events or run 604 on its configured schedule. Only routines that have a workflow config attached 605 can be activated; attempting to activate a routine with no config returns 422. 606 Scheduled routines must be configured to run no more frequently than once per 607 hour. Activation fails with 422 if the cron schedule is more frequent than 608 that limit. Requires app scope. 609 610 Args: 611 routine: Routine ID (`arn_...`) of the routine to activate. 612 613 Returns: 614 The updated routine with `status` set to `"active"`. 615 """ 616 return self._http.request( 617 f"/api/v1/agent_routines/{routine}/activate", 618 method="POST", 619 response_type=AgentRoutine, 620 ) 621 622 def invoke(self, routine: str, input: AgentRoutineInvokeInput) -> AgentRoutineRun: 623 """ 624 Invoke a routine 625 Triggers an on-demand invocation of the specified routine, dispatching an 626 asynchronous agent run and returning a run record immediately. The routine must 627 be active and must have `event_type` set to `"agentroutine.invoked"`. 628 The routine's `preset_config.session_mode` determines session behavior: each 629 call may create a new session (`"stateless"`) or reuse an existing one 630 (`"session"`). When `session_scope` is `"per_user"`, the `user` param is 631 required for S2S and developer callers; authenticated client callers always 632 use their own identity. When `session_scope` is `"per_key"`, `session_key` 633 is required. 634 Supply `idempotency_key` to safely retry invocations if a completed run 635 already exists for that key a 409 Conflict is returned rather than creating 636 a duplicate run. Entitlement for LLM calls is checked at request time; 637 customers on plans that do not include this feature receive 402. 638 639 Args: 640 routine: Routine ID (`arn_...`) or `lookup_key` of the routine to invoke. 641 input: Request body. 642 input.idempotency_key: Unique key used to deduplicate invocations. Resubmitting the same key returns 409 if a completed run already exists. 643 input.message: The user message to send to the agent for this invocation. 644 input.metadata: Arbitrary key-value metadata attached to this invocation. Not interpreted by the platform. 645 input.session_key: Arbitrary key used to identify and resume a session when `session_scope` is `"per_key"`. Required in that mode. 646 input.thread_id: Thread ID (`thr_...`) to post the preset output into. Omit to skip thread posting. 647 input.user: User ID to associate with the session. For S2S and developer callers only; authenticated client callers always use their own identity. 648 649 Returns: 650 The agent routine run created by this invocation. 651 """ 652 return self._http.request( 653 f"/api/v1/agent_routines/{routine}/invoke", 654 method="POST", 655 body=input, 656 response_type=AgentRoutineRun, 657 ) 658 659 def pause(self, routine: str) -> AgentRoutine: 660 """ 661 Pause a routine 662 Sets the routine's status to `"paused"`, suspending event processing and 663 scheduled execution without deleting the routine or its configuration. A 664 paused routine can be resumed at any time by calling the activate endpoint. 665 Requires app scope. 666 667 Args: 668 routine: Routine ID (`arn_...`) of the routine to pause. 669 670 Returns: 671 The updated routine with `status` set to `"paused"`. 672 """ 673 return self._http.request( 674 f"/api/v1/agent_routines/{routine}/pause", 675 method="POST", 676 response_type=AgentRoutine, 677 ) 678 679 def runs( 680 self, 681 routine: str, 682 *, 683 status: str | None = None, 684 limit: int | None = None, 685 before_cursor: str | None = None, 686 after_cursor: str | None = None, 687 ) -> AgentRoutineRunListResponse: 688 """ 689 List runs for a routine 690 Returns a cursor-paginated list of runs for the specified routine, ordered 691 from most recent to oldest by default. Use `before_cursor` and `after_cursor` 692 to page through results in either direction. 693 You can filter runs by status to monitor a specific lifecycle phase. The 694 authenticated principal must have access to the routine's parent app. When 695 your API key is scoped to an app, only runs belonging to that app are 696 returned. 697 698 Args: 699 routine: Routine ID (`rtn_...`) whose runs you want to list. 700 status: Filter runs by status. One of `"pending"`, `"running"`, `"completed"`, `"failed"`, or `"skipped"`. Omit to return runs in all statuses. 701 limit: Maximum number of runs to return per page. Defaults to 50; maximum is 100. 702 before_cursor: Opaque cursor from a previous response's `before_cursor` field. Returns the page of runs older than this cursor. 703 after_cursor: Opaque cursor from a previous response's `after_cursor` field. Returns the page of runs newer than this cursor. 704 705 Returns: 706 Paginated list of routine runs. 707 """ 708 query: dict[str, object] = {} 709 if status is not None: 710 query["status"] = status 711 if limit is not None: 712 query["limit"] = limit 713 if before_cursor is not None: 714 query["before_cursor"] = before_cursor 715 if after_cursor is not None: 716 query["after_cursor"] = after_cursor 717 return self._http.request( 718 f"/api/v1/agent_routines/{routine}/runs", 719 query=query, 720 response_type=AgentRoutineRunListResponse, 721 )
21class AgentRoutineUpdateInputAclAddItem(TypedDict, total=False): 22 actions: Required[list[str]] 23 'Array of action strings the principal is permitted to perform, e.g. `["read", "write"]`. Must contain at least one entry.' 24 principal: str | None 25 'The identifier of the principal. A string ID for `"user"`, `"team"`, `"org"`, and `"agent"` types; one of `"admin"`, `"member"`, or `"viewer"` for `"org_role"`; omit entirely when `principal_type` is `"everyone"`.' 26 principal_type: Required[str] 27 'The kind of principal receiving the grant. One of `"user"`, `"team"`, `"org"`, `"org_role"`, `"agent"`, or `"everyone"`.'
Array of action strings the principal is permitted to perform, e.g. ["read", "write"]. Must contain at least one entry.
The identifier of the principal. A string ID for "user", "team", "org", and "agent" types; one of "admin", "member", or "viewer" for "org_role"; omit entirely when principal_type is "everyone".
30class AgentRoutineUpdateInputAclGrantsItem(TypedDict, total=False): 31 actions: Required[list[str]] 32 'Array of action strings the principal is permitted to perform, e.g. `["read", "write"]`. Must contain at least one entry.' 33 principal: str | None 34 'The identifier of the principal. A string ID for `"user"`, `"team"`, `"org"`, and `"agent"` types; one of `"admin"`, `"member"`, or `"viewer"` for `"org_role"`; omit entirely when `principal_type` is `"everyone"`.' 35 principal_type: Required[str] 36 'The kind of principal receiving the grant. One of `"user"`, `"team"`, `"org"`, `"org_role"`, `"agent"`, or `"everyone"`.'
Array of action strings the principal is permitted to perform, e.g. ["read", "write"]. Must contain at least one entry.
The identifier of the principal. A string ID for "user", "team", "org", and "agent" types; one of "admin", "member", or "viewer" for "org_role"; omit entirely when principal_type is "everyone".
39class AgentRoutineUpdateInputAclRemoveItem(TypedDict, total=False): 40 principal: str | None 41 'The identifier of the principal to remove. A string ID for `"user"`, `"team"`, `"org"`, and `"agent"` types; one of `"admin"`, `"member"`, or `"viewer"` for `"org_role"`. Omit when `principal_type` is `"everyone"`.' 42 principal_type: Required[str] 43 'The kind of principal to remove. One of `"user"`, `"team"`, `"org"`, `"org_role"`, `"agent"`, or `"everyone"`.'
The identifier of the principal to remove. A string ID for "user", "team", "org", and "agent" types; one of "admin", "member", or "viewer" for "org_role". Omit when principal_type is "everyone".
46class AgentRoutineUpdateInputAcl(TypedDict, total=False): 47 add: list[AgentRoutineUpdateInputAclAddItem] | None 48 "Patch mode: grants to add or merge into the existing list. Cannot be combined with `grants`." 49 grants: list[AgentRoutineUpdateInputAclGrantsItem] | None 50 "Replace mode: the complete new list of grants that replaces all existing entries. Send an empty array (`[]`) to clear all grants. Cannot be combined with `add` or `remove`." 51 remove: list[AgentRoutineUpdateInputAclRemoveItem] | None 52 "Patch mode: principals whose grants should be removed from the existing list. Cannot be combined with `grants`."
Patch mode: grants to add or merge into the existing list. Cannot be combined with grants.
Patch mode: principals whose grants should be removed from the existing list. Cannot be combined with grants.
60class AgentRoutineUpdateInputPresetConfig(TypedDict, total=False): 61 instructions: str | None 62 "Custom task or behavior instructions for the preset (max 10,000 chars)." 63 llm: AgentRoutineUpdateInputPresetConfigLlm | None 64 "LLM invocation settings (e.g. a `model` override for this routine/step)." 65 session_mode: str | None 66 "Session mode: `stateless` (default, new session per trigger) or `session` (find-or-create a persistent session scoped by `session_scope`)." 67 session_scope: str | None 68 "When `session_mode` is `session`, controls session scoping: `per_user` (default), `per_key`, `per_org`, or `global`." 69 structured_message_template_ids: list[str] | None 70 "IDs of structured message templates that constrain the agent's responses to predefined structured formats."
LLM invocation settings (e.g. a model override for this routine/step).
Session mode: stateless (default, new session per trigger) or session (find-or-create a persistent session scoped by session_scope).
When session_mode is session, controls session scoping: per_user (default), per_key, per_org, or global.
78class AgentRoutineUpdateInputStepsItemPresetConfig(TypedDict, total=False): 79 instructions: str | None 80 "Custom task or behavior instructions for the preset (max 10,000 chars)." 81 llm: AgentRoutineUpdateInputStepsItemPresetConfigLlm | None 82 "LLM invocation settings (e.g. a `model` override for this routine/step)." 83 session_mode: str | None 84 "Session mode: `stateless` (default, new session per trigger) or `session` (find-or-create a persistent session scoped by `session_scope`)." 85 session_scope: str | None 86 "When `session_mode` is `session`, controls session scoping: `per_user` (default), `per_key`, `per_org`, or `global`." 87 structured_message_template_ids: list[str] | None 88 "IDs of structured message templates that constrain the agent's responses to predefined structured formats."
LLM invocation settings (e.g. a model override for this routine/step).
Session mode: stateless (default, new session per trigger) or session (find-or-create a persistent session scoped by session_scope).
When session_mode is session, controls session scoping: per_user (default), per_key, per_org, or global.
91class AgentRoutineUpdateInputStepsItem(TypedDict, total=False): 92 config: str | None 93 'ID of a saved config to use as the handler body. Required when `handler_type` is `"workflow_graph"`; also accepted for `"script"` as an alternative to an inline `script` value.' 94 handler_type: Required[str] 95 'Execution handler for this step. One of `"preset"`, `"script"`, or `"workflow_graph"`.' 96 inputs: dict[str, Any] | None 97 "Optional key-value map binding outputs from prior steps to this step's input variables." 98 name: str | None 99 "Optional label for this step. Must be unique within the chain when provided." 100 on_error: str | None 101 'Error handling policy for this step. One of `"halt"` (default), `"continue"`, or `"retry"`.' 102 output_key: str | None 103 "Key under which this step's result is stored and addressable by downstream steps. Defaults to `name` when omitted." 104 preset_config: AgentRoutineUpdateInputStepsItemPresetConfig | None 105 "Configuration overrides for the preset, using the same shape as the routine-level `preset_config`. You may include an `llm` key to override the agent's default model for this step. `null` if not provided." 106 preset_name: str | None 107 'Name of the preset to invoke. Required when `handler_type` is `"preset"`.' 108 script: str | None 109 'Inline script source code to execute. Used when `handler_type` is `"script"` and no `config` is provided.'
ID of a saved config to use as the handler body. Required when handler_type is "workflow_graph"; also accepted for "script" as an alternative to an inline script value.
Execution handler for this step. One of "preset", "script", or "workflow_graph".
Optional key-value map binding outputs from prior steps to this step's input variables.
Error handling policy for this step. One of "halt" (default), "continue", or "retry".
Key under which this step's result is stored and addressable by downstream steps. Defaults to name when omitted.
Configuration overrides for the preset, using the same shape as the routine-level preset_config. You may include an llm key to override the agent's default model for this step. null if not provided.
Inline script source code to execute. Used when handler_type is "script" and no config is provided.
112class AgentRoutineUpdateInput(TypedDict, total=False): 113 "Update a routine" 114 115 acl: AgentRoutineUpdateInputAcl | None 116 "Updated access control list. Replaces the existing ACL entirely." 117 config: str | None 118 'Workflow config ID (`cfg_...`). Used when `handler_type` is `"workflow_graph"`.' 119 description: str | None 120 "New human-readable description of what this routine does." 121 event_config: dict[str, Any] | None 122 'Mapping of event types to trigger configuration. Each key is an event type string; each value is an object with a `"filters"` map and an optional `"dedupe_key_path"` (a JSON path used to deduplicate events, e.g. `"$.thread.id"`).' 123 event_type: str | None 124 "Event type that triggers this routine. Deprecated use `event_config` instead." 125 handler_type: str | None 126 'New execution model. One of `"workflow_graph"`, `"script"`, `"preset"`, or `"chain"`.' 127 lookup_key: str | None 128 "New stable, unique key for deterministic lookup. Must be unique within the app." 129 metadata: dict[str, Any] | None 130 "Updated arbitrary key-value metadata. Replaces the existing metadata entirely." 131 name: str | None 132 "New human-readable display name for the routine." 133 preset_config: AgentRoutineUpdateInputPresetConfig | None 134 "Updated configuration passed to the preset at runtime." 135 preset_name: str | None 136 'Name of the registered preset to use. Used when `handler_type` is `"preset"`.' 137 schedule: str | None 138 'New cron expression for time-triggered routines (e.g. `"0 9 * * 1"`). Must not be more frequent than once per hour.' 139 script: str | None 140 'New inline script source. Used when `handler_type` is `"script"`.' 141 steps: list[AgentRoutineUpdateInputStepsItem] | None 142 'Updated ordered list of steps for a chain handler. Required when `handler_type` is `"chain"`; must be omitted or empty otherwise. Replaces the entire existing step list send the full desired list, not a partial diff.' 143 template: str | None 144 "AgentRoutineTemplate config ID (`cfg_...`) or lookup key. When provided, the routine's configuration is re-resolved from the template before applying other param overrides. The routine's `status`, `lookup_key`, and agent attachment are always preserved." 145 trigger_context: str | None 146 'Updated trigger context. One of `"chat_session"` or `"event"`.'
Update a routine
Updated access control list. Replaces the existing ACL entirely.
Mapping of event types to trigger configuration. Each key is an event type string; each value is an object with a "filters" map and an optional "dedupe_key_path" (a JSON path used to deduplicate events, e.g. "$.thread.id").
New execution model. One of "workflow_graph", "script", "preset", or "chain".
New stable, unique key for deterministic lookup. Must be unique within the app.
Updated arbitrary key-value metadata. Replaces the existing metadata entirely.
Updated configuration passed to the preset at runtime.
New cron expression for time-triggered routines (e.g. "0 9 * * 1"). Must not be more frequent than once per hour.
Updated ordered list of steps for a chain handler. Required when handler_type is "chain"; must be omitted or empty otherwise. Replaces the entire existing step list send the full desired list, not a partial diff.
AgentRoutineTemplate config ID (cfg_...) or lookup key. When provided, the routine's configuration is re-resolved from the template before applying other param overrides. The routine's status, lookup_key, and agent attachment are always preserved.
149class AgentRoutineInvokeInput(TypedDict, total=False): 150 "Invoke a routine" 151 152 idempotency_key: str | None 153 "Unique key used to deduplicate invocations. Resubmitting the same key returns 409 if a completed run already exists." 154 message: Required[str] 155 "The user message to send to the agent for this invocation." 156 metadata: dict[str, Any] | None 157 "Arbitrary key-value metadata attached to this invocation. Not interpreted by the platform." 158 session_key: str | None 159 'Arbitrary key used to identify and resume a session when `session_scope` is `"per_key"`. Required in that mode.' 160 thread_id: str | None 161 "Thread ID (`thr_...`) to post the preset output into. Omit to skip thread posting." 162 user: str | None 163 "User ID to associate with the session. For S2S and developer callers only; authenticated client callers always use their own identity."
Invoke a routine
Unique key used to deduplicate invocations. Resubmitting the same key returns 409 if a completed run already exists.
Arbitrary key-value metadata attached to this invocation. Not interpreted by the platform.
Arbitrary key used to identify and resume a session when session_scope is "per_key". Required in that mode.
166class AsyncAgentRoutineRunResource: 167 def __init__(self, http: HttpClient): 168 self._http = http 169 170 async def get(self, run: str) -> AgentRoutineRun: 171 """ 172 Retrieve a routine run 173 Returns a single routine run by its ID. The run includes status, payload, 174 result, duration, and any structured response produced by the routine's agent. 175 The authenticated principal must have access to the app that owns the run. 176 When your API key is scoped to an app, the run must belong to that app or 177 a 403 is returned. 178 179 Args: 180 run: Routine run ID (`arr_...`) to retrieve. 181 182 Returns: 183 The requested routine run. 184 """ 185 return await self._http.request( 186 f"/api/v1/agent_routines/runs/{run}", 187 response_type=AgentRoutineRun, 188 )
170 async def get(self, run: str) -> AgentRoutineRun: 171 """ 172 Retrieve a routine run 173 Returns a single routine run by its ID. The run includes status, payload, 174 result, duration, and any structured response produced by the routine's agent. 175 The authenticated principal must have access to the app that owns the run. 176 When your API key is scoped to an app, the run must belong to that app or 177 a 403 is returned. 178 179 Args: 180 run: Routine run ID (`arr_...`) to retrieve. 181 182 Returns: 183 The requested routine run. 184 """ 185 return await self._http.request( 186 f"/api/v1/agent_routines/runs/{run}", 187 response_type=AgentRoutineRun, 188 )
Retrieve a routine run Returns a single routine run by its ID. The run includes status, payload, result, duration, and any structured response produced by the routine's agent. The authenticated principal must have access to the app that owns the run. When your API key is scoped to an app, the run must belong to that app or a 403 is returned.
Arguments:
- run: Routine run ID (
arr_...) to retrieve.
Returns:
The requested routine run.
191class AsyncAgentRoutineResource: 192 def __init__(self, http: HttpClient): 193 self._http = http 194 self.agent_routine_runs = AsyncAgentRoutineRunResource(http) 195 196 async def list( 197 self, *, agent: str | None = None, event_type: str | None = None 198 ) -> AgentRoutineListResponse: 199 """ 200 List routines 201 Returns all routines within the authenticated app scope. Optionally filter by 202 agent or event type. When `agent` is omitted, all routines accessible to the 203 caller are returned regardless of which agent they belong to. 204 If `agent` is provided but does not exist or is not accessible, the endpoint 205 returns 404 rather than an empty list. Results are not paginated; all matching 206 routines are returned in a single response. Requires app scope. 207 208 Args: 209 agent: Agent ID (`agt_...`) to filter routines by. Omit to return routines across all agents. 210 event_type: Event type string to filter by (e.g. `"agentroutine.invoked"`). Omit to return routines for all event types. 211 212 Returns: 213 Object containing a `data` array of matching routines. 214 """ 215 query: dict[str, object] = {} 216 if agent is not None: 217 query["agent"] = agent 218 if event_type is not None: 219 query["event_type"] = event_type 220 return await self._http.request( 221 "/api/v1/agent_routines", 222 query=query, 223 response_type=AgentRoutineListResponse, 224 ) 225 226 async def presets(self) -> builtins.list[RoutinePreset]: 227 """ 228 List routine presets 229 Returns all registered routine presets available to the authenticated app, 230 including each preset's name, display metadata, and accepted configuration 231 schema. Use this endpoint to discover which presets can be referenced when 232 creating or updating a routine with `handler_type: "preset"`. 233 The list reflects presets registered at server start time and does not change 234 at runtime. Requires app scope. 235 236 Returns: 237 Array of available routine preset objects. 238 """ 239 return await self._http.request( 240 "/api/v1/agent_routines/presets", 241 response_type=list[RoutinePreset], 242 ) 243 244 async def delete(self, routine: str) -> None: 245 """ 246 Delete a routine 247 Permanently deletes the specified routine. This action is irreversible the 248 routine and its configuration are removed immediately. Any in-flight event 249 processing initiated by this routine before deletion may still complete. 250 Requires app scope. Returns 204 No Content on success. 251 252 Args: 253 routine: Routine ID (`arn_...`) of the routine to delete. 254 255 Returns: 256 Empty response on successful deletion (HTTP 204 No Content). 257 """ 258 await self._http.request(f"/api/v1/agent_routines/{routine}", method="DELETE") 259 260 async def get(self, routine: str) -> AgentRoutine: 261 """ 262 Retrieve a routine 263 Returns the full routine record for the given routine ID. Use this endpoint to 264 inspect a routine's current configuration, handler type, event config, schedule, 265 and lifecycle status. 266 Requires app scope. Returns 404 if the routine does not exist or is not 267 accessible to the caller. 268 269 Args: 270 routine: Routine ID (`arn_...`) of the routine to retrieve. 271 272 Returns: 273 The requested routine. 274 """ 275 return await self._http.request( 276 f"/api/v1/agent_routines/{routine}", 277 response_type=AgentRoutine, 278 ) 279 280 async def update(self, routine: str, input: AgentRoutineUpdateInput) -> AgentRoutine: 281 """ 282 Update a routine 283 Updates one or more fields of the specified routine. Only the fields you 284 include are changed; omitted fields retain their current values. To change the 285 execution model, supply a new `handler_type` along with its required handler 286 body field (`config`, `script`, or `preset_name`). 287 When `template` is supplied, the routine's configuration is re-resolved from 288 the template before applying any additional field overrides. The routine's 289 `status`, `lookup_key`, and agent attachment are always preserved regardless 290 of template content. Updating `steps` replaces the entire step list send 291 the full desired list, not a partial diff. Requires app scope. 292 293 Args: 294 routine: Routine ID (`arn_...`) of the routine to update. 295 input: Request body. 296 input.acl: Updated access control list. Replaces the existing ACL entirely. 297 input.config: Workflow config ID (`cfg_...`). Used when `handler_type` is `"workflow_graph"`. 298 input.description: New human-readable description of what this routine does. 299 input.event_config: Mapping of event types to trigger configuration. Each key is an event type string; each value is an object with a `"filters"` map and an optional `"dedupe_key_path"` (a JSON path used to deduplicate events, e.g. `"$.thread.id"`). 300 input.event_type: Event type that triggers this routine. Deprecated use `event_config` instead. 301 input.handler_type: New execution model. One of `"workflow_graph"`, `"script"`, `"preset"`, or `"chain"`. 302 input.lookup_key: New stable, unique key for deterministic lookup. Must be unique within the app. 303 input.metadata: Updated arbitrary key-value metadata. Replaces the existing metadata entirely. 304 input.name: New human-readable display name for the routine. 305 input.preset_config: Updated configuration passed to the preset at runtime. 306 input.preset_name: Name of the registered preset to use. Used when `handler_type` is `"preset"`. 307 input.schedule: New cron expression for time-triggered routines (e.g. `"0 9 * * 1"`). Must not be more frequent than once per hour. 308 input.script: New inline script source. Used when `handler_type` is `"script"`. 309 input.steps: Updated ordered list of steps for a chain handler. Required when `handler_type` is `"chain"`; must be omitted or empty otherwise. Replaces the entire existing step list send the full desired list, not a partial diff. 310 input.template: AgentRoutineTemplate config ID (`cfg_...`) or lookup key. When provided, the routine's configuration is re-resolved from the template before applying other param overrides. The routine's `status`, `lookup_key`, and agent attachment are always preserved. 311 input.trigger_context: Updated trigger context. One of `"chat_session"` or `"event"`. 312 313 Returns: 314 The updated routine. 315 """ 316 return await self._http.request( 317 f"/api/v1/agent_routines/{routine}", 318 method="PATCH", 319 body=input, 320 response_type=AgentRoutine, 321 ) 322 323 async def activate(self, routine: str) -> AgentRoutine: 324 """ 325 Activate a routine 326 Sets the routine's status to `"active"`, enabling it to process events or run 327 on its configured schedule. Only routines that have a workflow config attached 328 can be activated; attempting to activate a routine with no config returns 422. 329 Scheduled routines must be configured to run no more frequently than once per 330 hour. Activation fails with 422 if the cron schedule is more frequent than 331 that limit. Requires app scope. 332 333 Args: 334 routine: Routine ID (`arn_...`) of the routine to activate. 335 336 Returns: 337 The updated routine with `status` set to `"active"`. 338 """ 339 return await self._http.request( 340 f"/api/v1/agent_routines/{routine}/activate", 341 method="POST", 342 response_type=AgentRoutine, 343 ) 344 345 async def invoke(self, routine: str, input: AgentRoutineInvokeInput) -> AgentRoutineRun: 346 """ 347 Invoke a routine 348 Triggers an on-demand invocation of the specified routine, dispatching an 349 asynchronous agent run and returning a run record immediately. The routine must 350 be active and must have `event_type` set to `"agentroutine.invoked"`. 351 The routine's `preset_config.session_mode` determines session behavior: each 352 call may create a new session (`"stateless"`) or reuse an existing one 353 (`"session"`). When `session_scope` is `"per_user"`, the `user` param is 354 required for S2S and developer callers; authenticated client callers always 355 use their own identity. When `session_scope` is `"per_key"`, `session_key` 356 is required. 357 Supply `idempotency_key` to safely retry invocations if a completed run 358 already exists for that key a 409 Conflict is returned rather than creating 359 a duplicate run. Entitlement for LLM calls is checked at request time; 360 customers on plans that do not include this feature receive 402. 361 362 Args: 363 routine: Routine ID (`arn_...`) or `lookup_key` of the routine to invoke. 364 input: Request body. 365 input.idempotency_key: Unique key used to deduplicate invocations. Resubmitting the same key returns 409 if a completed run already exists. 366 input.message: The user message to send to the agent for this invocation. 367 input.metadata: Arbitrary key-value metadata attached to this invocation. Not interpreted by the platform. 368 input.session_key: Arbitrary key used to identify and resume a session when `session_scope` is `"per_key"`. Required in that mode. 369 input.thread_id: Thread ID (`thr_...`) to post the preset output into. Omit to skip thread posting. 370 input.user: User ID to associate with the session. For S2S and developer callers only; authenticated client callers always use their own identity. 371 372 Returns: 373 The agent routine run created by this invocation. 374 """ 375 return await self._http.request( 376 f"/api/v1/agent_routines/{routine}/invoke", 377 method="POST", 378 body=input, 379 response_type=AgentRoutineRun, 380 ) 381 382 async def pause(self, routine: str) -> AgentRoutine: 383 """ 384 Pause a routine 385 Sets the routine's status to `"paused"`, suspending event processing and 386 scheduled execution without deleting the routine or its configuration. A 387 paused routine can be resumed at any time by calling the activate endpoint. 388 Requires app scope. 389 390 Args: 391 routine: Routine ID (`arn_...`) of the routine to pause. 392 393 Returns: 394 The updated routine with `status` set to `"paused"`. 395 """ 396 return await self._http.request( 397 f"/api/v1/agent_routines/{routine}/pause", 398 method="POST", 399 response_type=AgentRoutine, 400 ) 401 402 async def runs( 403 self, 404 routine: str, 405 *, 406 status: str | None = None, 407 limit: int | None = None, 408 before_cursor: str | None = None, 409 after_cursor: str | None = None, 410 ) -> AgentRoutineRunListResponse: 411 """ 412 List runs for a routine 413 Returns a cursor-paginated list of runs for the specified routine, ordered 414 from most recent to oldest by default. Use `before_cursor` and `after_cursor` 415 to page through results in either direction. 416 You can filter runs by status to monitor a specific lifecycle phase. The 417 authenticated principal must have access to the routine's parent app. When 418 your API key is scoped to an app, only runs belonging to that app are 419 returned. 420 421 Args: 422 routine: Routine ID (`rtn_...`) whose runs you want to list. 423 status: Filter runs by status. One of `"pending"`, `"running"`, `"completed"`, `"failed"`, or `"skipped"`. Omit to return runs in all statuses. 424 limit: Maximum number of runs to return per page. Defaults to 50; maximum is 100. 425 before_cursor: Opaque cursor from a previous response's `before_cursor` field. Returns the page of runs older than this cursor. 426 after_cursor: Opaque cursor from a previous response's `after_cursor` field. Returns the page of runs newer than this cursor. 427 428 Returns: 429 Paginated list of routine runs. 430 """ 431 query: dict[str, object] = {} 432 if status is not None: 433 query["status"] = status 434 if limit is not None: 435 query["limit"] = limit 436 if before_cursor is not None: 437 query["before_cursor"] = before_cursor 438 if after_cursor is not None: 439 query["after_cursor"] = after_cursor 440 return await self._http.request( 441 f"/api/v1/agent_routines/{routine}/runs", 442 query=query, 443 response_type=AgentRoutineRunListResponse, 444 )
196 async def list( 197 self, *, agent: str | None = None, event_type: str | None = None 198 ) -> AgentRoutineListResponse: 199 """ 200 List routines 201 Returns all routines within the authenticated app scope. Optionally filter by 202 agent or event type. When `agent` is omitted, all routines accessible to the 203 caller are returned regardless of which agent they belong to. 204 If `agent` is provided but does not exist or is not accessible, the endpoint 205 returns 404 rather than an empty list. Results are not paginated; all matching 206 routines are returned in a single response. Requires app scope. 207 208 Args: 209 agent: Agent ID (`agt_...`) to filter routines by. Omit to return routines across all agents. 210 event_type: Event type string to filter by (e.g. `"agentroutine.invoked"`). Omit to return routines for all event types. 211 212 Returns: 213 Object containing a `data` array of matching routines. 214 """ 215 query: dict[str, object] = {} 216 if agent is not None: 217 query["agent"] = agent 218 if event_type is not None: 219 query["event_type"] = event_type 220 return await self._http.request( 221 "/api/v1/agent_routines", 222 query=query, 223 response_type=AgentRoutineListResponse, 224 )
List routines
Returns all routines within the authenticated app scope. Optionally filter by
agent or event type. When agent is omitted, all routines accessible to the
caller are returned regardless of which agent they belong to.
If agent is provided but does not exist or is not accessible, the endpoint
returns 404 rather than an empty list. Results are not paginated; all matching
routines are returned in a single response. Requires app scope.
Arguments:
- agent: Agent ID (
agt_...) to filter routines by. Omit to return routines across all agents. - event_type: Event type string to filter by (e.g.
"agentroutine.invoked"). Omit to return routines for all event types.
Returns:
Object containing a
dataarray of matching routines.
226 async def presets(self) -> builtins.list[RoutinePreset]: 227 """ 228 List routine presets 229 Returns all registered routine presets available to the authenticated app, 230 including each preset's name, display metadata, and accepted configuration 231 schema. Use this endpoint to discover which presets can be referenced when 232 creating or updating a routine with `handler_type: "preset"`. 233 The list reflects presets registered at server start time and does not change 234 at runtime. Requires app scope. 235 236 Returns: 237 Array of available routine preset objects. 238 """ 239 return await self._http.request( 240 "/api/v1/agent_routines/presets", 241 response_type=list[RoutinePreset], 242 )
List routine presets
Returns all registered routine presets available to the authenticated app,
including each preset's name, display metadata, and accepted configuration
schema. Use this endpoint to discover which presets can be referenced when
creating or updating a routine with handler_type: "preset".
The list reflects presets registered at server start time and does not change
at runtime. Requires app scope.
Returns:
Array of available routine preset objects.
244 async def delete(self, routine: str) -> None: 245 """ 246 Delete a routine 247 Permanently deletes the specified routine. This action is irreversible the 248 routine and its configuration are removed immediately. Any in-flight event 249 processing initiated by this routine before deletion may still complete. 250 Requires app scope. Returns 204 No Content on success. 251 252 Args: 253 routine: Routine ID (`arn_...`) of the routine to delete. 254 255 Returns: 256 Empty response on successful deletion (HTTP 204 No Content). 257 """ 258 await self._http.request(f"/api/v1/agent_routines/{routine}", method="DELETE")
Delete a routine Permanently deletes the specified routine. This action is irreversible the routine and its configuration are removed immediately. Any in-flight event processing initiated by this routine before deletion may still complete. Requires app scope. Returns 204 No Content on success.
Arguments:
- routine: Routine ID (
arn_...) of the routine to delete.
Returns:
Empty response on successful deletion (HTTP 204 No Content).
260 async def get(self, routine: str) -> AgentRoutine: 261 """ 262 Retrieve a routine 263 Returns the full routine record for the given routine ID. Use this endpoint to 264 inspect a routine's current configuration, handler type, event config, schedule, 265 and lifecycle status. 266 Requires app scope. Returns 404 if the routine does not exist or is not 267 accessible to the caller. 268 269 Args: 270 routine: Routine ID (`arn_...`) of the routine to retrieve. 271 272 Returns: 273 The requested routine. 274 """ 275 return await self._http.request( 276 f"/api/v1/agent_routines/{routine}", 277 response_type=AgentRoutine, 278 )
Retrieve a routine Returns the full routine record for the given routine ID. Use this endpoint to inspect a routine's current configuration, handler type, event config, schedule, and lifecycle status. Requires app scope. Returns 404 if the routine does not exist or is not accessible to the caller.
Arguments:
- routine: Routine ID (
arn_...) of the routine to retrieve.
Returns:
The requested routine.
280 async def update(self, routine: str, input: AgentRoutineUpdateInput) -> AgentRoutine: 281 """ 282 Update a routine 283 Updates one or more fields of the specified routine. Only the fields you 284 include are changed; omitted fields retain their current values. To change the 285 execution model, supply a new `handler_type` along with its required handler 286 body field (`config`, `script`, or `preset_name`). 287 When `template` is supplied, the routine's configuration is re-resolved from 288 the template before applying any additional field overrides. The routine's 289 `status`, `lookup_key`, and agent attachment are always preserved regardless 290 of template content. Updating `steps` replaces the entire step list send 291 the full desired list, not a partial diff. Requires app scope. 292 293 Args: 294 routine: Routine ID (`arn_...`) of the routine to update. 295 input: Request body. 296 input.acl: Updated access control list. Replaces the existing ACL entirely. 297 input.config: Workflow config ID (`cfg_...`). Used when `handler_type` is `"workflow_graph"`. 298 input.description: New human-readable description of what this routine does. 299 input.event_config: Mapping of event types to trigger configuration. Each key is an event type string; each value is an object with a `"filters"` map and an optional `"dedupe_key_path"` (a JSON path used to deduplicate events, e.g. `"$.thread.id"`). 300 input.event_type: Event type that triggers this routine. Deprecated use `event_config` instead. 301 input.handler_type: New execution model. One of `"workflow_graph"`, `"script"`, `"preset"`, or `"chain"`. 302 input.lookup_key: New stable, unique key for deterministic lookup. Must be unique within the app. 303 input.metadata: Updated arbitrary key-value metadata. Replaces the existing metadata entirely. 304 input.name: New human-readable display name for the routine. 305 input.preset_config: Updated configuration passed to the preset at runtime. 306 input.preset_name: Name of the registered preset to use. Used when `handler_type` is `"preset"`. 307 input.schedule: New cron expression for time-triggered routines (e.g. `"0 9 * * 1"`). Must not be more frequent than once per hour. 308 input.script: New inline script source. Used when `handler_type` is `"script"`. 309 input.steps: Updated ordered list of steps for a chain handler. Required when `handler_type` is `"chain"`; must be omitted or empty otherwise. Replaces the entire existing step list send the full desired list, not a partial diff. 310 input.template: AgentRoutineTemplate config ID (`cfg_...`) or lookup key. When provided, the routine's configuration is re-resolved from the template before applying other param overrides. The routine's `status`, `lookup_key`, and agent attachment are always preserved. 311 input.trigger_context: Updated trigger context. One of `"chat_session"` or `"event"`. 312 313 Returns: 314 The updated routine. 315 """ 316 return await self._http.request( 317 f"/api/v1/agent_routines/{routine}", 318 method="PATCH", 319 body=input, 320 response_type=AgentRoutine, 321 )
Update a routine
Updates one or more fields of the specified routine. Only the fields you
include are changed; omitted fields retain their current values. To change the
execution model, supply a new handler_type along with its required handler
body field (config, script, or preset_name).
When template is supplied, the routine's configuration is re-resolved from
the template before applying any additional field overrides. The routine's
status, lookup_key, and agent attachment are always preserved regardless
of template content. Updating steps replaces the entire step list send
the full desired list, not a partial diff. Requires app scope.
Arguments:
- routine: Routine ID (
arn_...) of the routine to update. - input: Request body.
- input.acl: Updated access control list. Replaces the existing ACL entirely.
- input.config: Workflow config ID (
cfg_...). Used whenhandler_typeis"workflow_graph". - input.description: New human-readable description of what this routine does.
- input.event_config: Mapping of event types to trigger configuration. Each key is an event type string; each value is an object with a
"filters"map and an optional"dedupe_key_path"(a JSON path used to deduplicate events, e.g."$.thread.id"). - input.event_type: Event type that triggers this routine. Deprecated use
event_configinstead. - input.handler_type: New execution model. One of
"workflow_graph","script","preset", or"chain". - input.lookup_key: New stable, unique key for deterministic lookup. Must be unique within the app.
- input.metadata: Updated arbitrary key-value metadata. Replaces the existing metadata entirely.
- input.name: New human-readable display name for the routine.
- input.preset_config: Updated configuration passed to the preset at runtime.
- input.preset_name: Name of the registered preset to use. Used when
handler_typeis"preset". - input.schedule: New cron expression for time-triggered routines (e.g.
"0 9 * * 1"). Must not be more frequent than once per hour. - input.script: New inline script source. Used when
handler_typeis"script". - input.steps: Updated ordered list of steps for a chain handler. Required when
handler_typeis"chain"; must be omitted or empty otherwise. Replaces the entire existing step list send the full desired list, not a partial diff. - input.template: AgentRoutineTemplate config ID (
cfg_...) or lookup key. When provided, the routine's configuration is re-resolved from the template before applying other param overrides. The routine'sstatus,lookup_key, and agent attachment are always preserved. - input.trigger_context: Updated trigger context. One of
"chat_session"or"event".
Returns:
The updated routine.
323 async def activate(self, routine: str) -> AgentRoutine: 324 """ 325 Activate a routine 326 Sets the routine's status to `"active"`, enabling it to process events or run 327 on its configured schedule. Only routines that have a workflow config attached 328 can be activated; attempting to activate a routine with no config returns 422. 329 Scheduled routines must be configured to run no more frequently than once per 330 hour. Activation fails with 422 if the cron schedule is more frequent than 331 that limit. Requires app scope. 332 333 Args: 334 routine: Routine ID (`arn_...`) of the routine to activate. 335 336 Returns: 337 The updated routine with `status` set to `"active"`. 338 """ 339 return await self._http.request( 340 f"/api/v1/agent_routines/{routine}/activate", 341 method="POST", 342 response_type=AgentRoutine, 343 )
Activate a routine
Sets the routine's status to "active", enabling it to process events or run
on its configured schedule. Only routines that have a workflow config attached
can be activated; attempting to activate a routine with no config returns 422.
Scheduled routines must be configured to run no more frequently than once per
hour. Activation fails with 422 if the cron schedule is more frequent than
that limit. Requires app scope.
Arguments:
- routine: Routine ID (
arn_...) of the routine to activate.
Returns:
The updated routine with
statusset to"active".
345 async def invoke(self, routine: str, input: AgentRoutineInvokeInput) -> AgentRoutineRun: 346 """ 347 Invoke a routine 348 Triggers an on-demand invocation of the specified routine, dispatching an 349 asynchronous agent run and returning a run record immediately. The routine must 350 be active and must have `event_type` set to `"agentroutine.invoked"`. 351 The routine's `preset_config.session_mode` determines session behavior: each 352 call may create a new session (`"stateless"`) or reuse an existing one 353 (`"session"`). When `session_scope` is `"per_user"`, the `user` param is 354 required for S2S and developer callers; authenticated client callers always 355 use their own identity. When `session_scope` is `"per_key"`, `session_key` 356 is required. 357 Supply `idempotency_key` to safely retry invocations if a completed run 358 already exists for that key a 409 Conflict is returned rather than creating 359 a duplicate run. Entitlement for LLM calls is checked at request time; 360 customers on plans that do not include this feature receive 402. 361 362 Args: 363 routine: Routine ID (`arn_...`) or `lookup_key` of the routine to invoke. 364 input: Request body. 365 input.idempotency_key: Unique key used to deduplicate invocations. Resubmitting the same key returns 409 if a completed run already exists. 366 input.message: The user message to send to the agent for this invocation. 367 input.metadata: Arbitrary key-value metadata attached to this invocation. Not interpreted by the platform. 368 input.session_key: Arbitrary key used to identify and resume a session when `session_scope` is `"per_key"`. Required in that mode. 369 input.thread_id: Thread ID (`thr_...`) to post the preset output into. Omit to skip thread posting. 370 input.user: User ID to associate with the session. For S2S and developer callers only; authenticated client callers always use their own identity. 371 372 Returns: 373 The agent routine run created by this invocation. 374 """ 375 return await self._http.request( 376 f"/api/v1/agent_routines/{routine}/invoke", 377 method="POST", 378 body=input, 379 response_type=AgentRoutineRun, 380 )
Invoke a routine
Triggers an on-demand invocation of the specified routine, dispatching an
asynchronous agent run and returning a run record immediately. The routine must
be active and must have event_type set to "agentroutine.invoked".
The routine's preset_config.session_mode determines session behavior: each
call may create a new session ("stateless") or reuse an existing one
("session"). When session_scope is "per_user", the user param is
required for S2S and developer callers; authenticated client callers always
use their own identity. When session_scope is "per_key", session_key
is required.
Supply idempotency_key to safely retry invocations if a completed run
already exists for that key a 409 Conflict is returned rather than creating
a duplicate run. Entitlement for LLM calls is checked at request time;
customers on plans that do not include this feature receive 402.
Arguments:
- routine: Routine ID (
arn_...) orlookup_keyof the routine to invoke. - input: Request body.
- input.idempotency_key: Unique key used to deduplicate invocations. Resubmitting the same key returns 409 if a completed run already exists.
- input.message: The user message to send to the agent for this invocation.
- input.metadata: Arbitrary key-value metadata attached to this invocation. Not interpreted by the platform.
- input.session_key: Arbitrary key used to identify and resume a session when
session_scopeis"per_key". Required in that mode. - input.thread_id: Thread ID (
thr_...) to post the preset output into. Omit to skip thread posting. - input.user: User ID to associate with the session. For S2S and developer callers only; authenticated client callers always use their own identity.
Returns:
The agent routine run created by this invocation.
382 async def pause(self, routine: str) -> AgentRoutine: 383 """ 384 Pause a routine 385 Sets the routine's status to `"paused"`, suspending event processing and 386 scheduled execution without deleting the routine or its configuration. A 387 paused routine can be resumed at any time by calling the activate endpoint. 388 Requires app scope. 389 390 Args: 391 routine: Routine ID (`arn_...`) of the routine to pause. 392 393 Returns: 394 The updated routine with `status` set to `"paused"`. 395 """ 396 return await self._http.request( 397 f"/api/v1/agent_routines/{routine}/pause", 398 method="POST", 399 response_type=AgentRoutine, 400 )
Pause a routine
Sets the routine's status to "paused", suspending event processing and
scheduled execution without deleting the routine or its configuration. A
paused routine can be resumed at any time by calling the activate endpoint.
Requires app scope.
Arguments:
- routine: Routine ID (
arn_...) of the routine to pause.
Returns:
The updated routine with
statusset to"paused".
402 async def runs( 403 self, 404 routine: str, 405 *, 406 status: str | None = None, 407 limit: int | None = None, 408 before_cursor: str | None = None, 409 after_cursor: str | None = None, 410 ) -> AgentRoutineRunListResponse: 411 """ 412 List runs for a routine 413 Returns a cursor-paginated list of runs for the specified routine, ordered 414 from most recent to oldest by default. Use `before_cursor` and `after_cursor` 415 to page through results in either direction. 416 You can filter runs by status to monitor a specific lifecycle phase. The 417 authenticated principal must have access to the routine's parent app. When 418 your API key is scoped to an app, only runs belonging to that app are 419 returned. 420 421 Args: 422 routine: Routine ID (`rtn_...`) whose runs you want to list. 423 status: Filter runs by status. One of `"pending"`, `"running"`, `"completed"`, `"failed"`, or `"skipped"`. Omit to return runs in all statuses. 424 limit: Maximum number of runs to return per page. Defaults to 50; maximum is 100. 425 before_cursor: Opaque cursor from a previous response's `before_cursor` field. Returns the page of runs older than this cursor. 426 after_cursor: Opaque cursor from a previous response's `after_cursor` field. Returns the page of runs newer than this cursor. 427 428 Returns: 429 Paginated list of routine runs. 430 """ 431 query: dict[str, object] = {} 432 if status is not None: 433 query["status"] = status 434 if limit is not None: 435 query["limit"] = limit 436 if before_cursor is not None: 437 query["before_cursor"] = before_cursor 438 if after_cursor is not None: 439 query["after_cursor"] = after_cursor 440 return await self._http.request( 441 f"/api/v1/agent_routines/{routine}/runs", 442 query=query, 443 response_type=AgentRoutineRunListResponse, 444 )
List runs for a routine
Returns a cursor-paginated list of runs for the specified routine, ordered
from most recent to oldest by default. Use before_cursor and after_cursor
to page through results in either direction.
You can filter runs by status to monitor a specific lifecycle phase. The
authenticated principal must have access to the routine's parent app. When
your API key is scoped to an app, only runs belonging to that app are
returned.
Arguments:
- routine: Routine ID (
rtn_...) whose runs you want to list. - status: Filter runs by status. One of
"pending","running","completed","failed", or"skipped". Omit to return runs in all statuses. - limit: Maximum number of runs to return per page. Defaults to 50; maximum is 100.
- before_cursor: Opaque cursor from a previous response's
before_cursorfield. Returns the page of runs older than this cursor. - after_cursor: Opaque cursor from a previous response's
after_cursorfield. Returns the page of runs newer than this cursor.
Returns:
Paginated list of routine runs.
447class AgentRoutineRunResource: 448 def __init__(self, http: SyncHttpClient): 449 self._http = http 450 451 def get(self, run: str) -> AgentRoutineRun: 452 """ 453 Retrieve a routine run 454 Returns a single routine run by its ID. The run includes status, payload, 455 result, duration, and any structured response produced by the routine's agent. 456 The authenticated principal must have access to the app that owns the run. 457 When your API key is scoped to an app, the run must belong to that app or 458 a 403 is returned. 459 460 Args: 461 run: Routine run ID (`arr_...`) to retrieve. 462 463 Returns: 464 The requested routine run. 465 """ 466 return self._http.request( 467 f"/api/v1/agent_routines/runs/{run}", 468 response_type=AgentRoutineRun, 469 )
451 def get(self, run: str) -> AgentRoutineRun: 452 """ 453 Retrieve a routine run 454 Returns a single routine run by its ID. The run includes status, payload, 455 result, duration, and any structured response produced by the routine's agent. 456 The authenticated principal must have access to the app that owns the run. 457 When your API key is scoped to an app, the run must belong to that app or 458 a 403 is returned. 459 460 Args: 461 run: Routine run ID (`arr_...`) to retrieve. 462 463 Returns: 464 The requested routine run. 465 """ 466 return self._http.request( 467 f"/api/v1/agent_routines/runs/{run}", 468 response_type=AgentRoutineRun, 469 )
Retrieve a routine run Returns a single routine run by its ID. The run includes status, payload, result, duration, and any structured response produced by the routine's agent. The authenticated principal must have access to the app that owns the run. When your API key is scoped to an app, the run must belong to that app or a 403 is returned.
Arguments:
- run: Routine run ID (
arr_...) to retrieve.
Returns:
The requested routine run.
472class AgentRoutineResource: 473 def __init__(self, http: SyncHttpClient): 474 self._http = http 475 self.agent_routine_runs = AgentRoutineRunResource(http) 476 477 def list( 478 self, *, agent: str | None = None, event_type: str | None = None 479 ) -> AgentRoutineListResponse: 480 """ 481 List routines 482 Returns all routines within the authenticated app scope. Optionally filter by 483 agent or event type. When `agent` is omitted, all routines accessible to the 484 caller are returned regardless of which agent they belong to. 485 If `agent` is provided but does not exist or is not accessible, the endpoint 486 returns 404 rather than an empty list. Results are not paginated; all matching 487 routines are returned in a single response. Requires app scope. 488 489 Args: 490 agent: Agent ID (`agt_...`) to filter routines by. Omit to return routines across all agents. 491 event_type: Event type string to filter by (e.g. `"agentroutine.invoked"`). Omit to return routines for all event types. 492 493 Returns: 494 Object containing a `data` array of matching routines. 495 """ 496 query: dict[str, object] = {} 497 if agent is not None: 498 query["agent"] = agent 499 if event_type is not None: 500 query["event_type"] = event_type 501 return self._http.request( 502 "/api/v1/agent_routines", 503 query=query, 504 response_type=AgentRoutineListResponse, 505 ) 506 507 def presets(self) -> builtins.list[RoutinePreset]: 508 """ 509 List routine presets 510 Returns all registered routine presets available to the authenticated app, 511 including each preset's name, display metadata, and accepted configuration 512 schema. Use this endpoint to discover which presets can be referenced when 513 creating or updating a routine with `handler_type: "preset"`. 514 The list reflects presets registered at server start time and does not change 515 at runtime. Requires app scope. 516 517 Returns: 518 Array of available routine preset objects. 519 """ 520 return self._http.request( 521 "/api/v1/agent_routines/presets", 522 response_type=list[RoutinePreset], 523 ) 524 525 def delete(self, routine: str) -> None: 526 """ 527 Delete a routine 528 Permanently deletes the specified routine. This action is irreversible the 529 routine and its configuration are removed immediately. Any in-flight event 530 processing initiated by this routine before deletion may still complete. 531 Requires app scope. Returns 204 No Content on success. 532 533 Args: 534 routine: Routine ID (`arn_...`) of the routine to delete. 535 536 Returns: 537 Empty response on successful deletion (HTTP 204 No Content). 538 """ 539 self._http.request(f"/api/v1/agent_routines/{routine}", method="DELETE") 540 541 def get(self, routine: str) -> AgentRoutine: 542 """ 543 Retrieve a routine 544 Returns the full routine record for the given routine ID. Use this endpoint to 545 inspect a routine's current configuration, handler type, event config, schedule, 546 and lifecycle status. 547 Requires app scope. Returns 404 if the routine does not exist or is not 548 accessible to the caller. 549 550 Args: 551 routine: Routine ID (`arn_...`) of the routine to retrieve. 552 553 Returns: 554 The requested routine. 555 """ 556 return self._http.request(f"/api/v1/agent_routines/{routine}", response_type=AgentRoutine) 557 558 def update(self, routine: str, input: AgentRoutineUpdateInput) -> AgentRoutine: 559 """ 560 Update a routine 561 Updates one or more fields of the specified routine. Only the fields you 562 include are changed; omitted fields retain their current values. To change the 563 execution model, supply a new `handler_type` along with its required handler 564 body field (`config`, `script`, or `preset_name`). 565 When `template` is supplied, the routine's configuration is re-resolved from 566 the template before applying any additional field overrides. The routine's 567 `status`, `lookup_key`, and agent attachment are always preserved regardless 568 of template content. Updating `steps` replaces the entire step list send 569 the full desired list, not a partial diff. Requires app scope. 570 571 Args: 572 routine: Routine ID (`arn_...`) of the routine to update. 573 input: Request body. 574 input.acl: Updated access control list. Replaces the existing ACL entirely. 575 input.config: Workflow config ID (`cfg_...`). Used when `handler_type` is `"workflow_graph"`. 576 input.description: New human-readable description of what this routine does. 577 input.event_config: Mapping of event types to trigger configuration. Each key is an event type string; each value is an object with a `"filters"` map and an optional `"dedupe_key_path"` (a JSON path used to deduplicate events, e.g. `"$.thread.id"`). 578 input.event_type: Event type that triggers this routine. Deprecated use `event_config` instead. 579 input.handler_type: New execution model. One of `"workflow_graph"`, `"script"`, `"preset"`, or `"chain"`. 580 input.lookup_key: New stable, unique key for deterministic lookup. Must be unique within the app. 581 input.metadata: Updated arbitrary key-value metadata. Replaces the existing metadata entirely. 582 input.name: New human-readable display name for the routine. 583 input.preset_config: Updated configuration passed to the preset at runtime. 584 input.preset_name: Name of the registered preset to use. Used when `handler_type` is `"preset"`. 585 input.schedule: New cron expression for time-triggered routines (e.g. `"0 9 * * 1"`). Must not be more frequent than once per hour. 586 input.script: New inline script source. Used when `handler_type` is `"script"`. 587 input.steps: Updated ordered list of steps for a chain handler. Required when `handler_type` is `"chain"`; must be omitted or empty otherwise. Replaces the entire existing step list send the full desired list, not a partial diff. 588 input.template: AgentRoutineTemplate config ID (`cfg_...`) or lookup key. When provided, the routine's configuration is re-resolved from the template before applying other param overrides. The routine's `status`, `lookup_key`, and agent attachment are always preserved. 589 input.trigger_context: Updated trigger context. One of `"chat_session"` or `"event"`. 590 591 Returns: 592 The updated routine. 593 """ 594 return self._http.request( 595 f"/api/v1/agent_routines/{routine}", 596 method="PATCH", 597 body=input, 598 response_type=AgentRoutine, 599 ) 600 601 def activate(self, routine: str) -> AgentRoutine: 602 """ 603 Activate a routine 604 Sets the routine's status to `"active"`, enabling it to process events or run 605 on its configured schedule. Only routines that have a workflow config attached 606 can be activated; attempting to activate a routine with no config returns 422. 607 Scheduled routines must be configured to run no more frequently than once per 608 hour. Activation fails with 422 if the cron schedule is more frequent than 609 that limit. Requires app scope. 610 611 Args: 612 routine: Routine ID (`arn_...`) of the routine to activate. 613 614 Returns: 615 The updated routine with `status` set to `"active"`. 616 """ 617 return self._http.request( 618 f"/api/v1/agent_routines/{routine}/activate", 619 method="POST", 620 response_type=AgentRoutine, 621 ) 622 623 def invoke(self, routine: str, input: AgentRoutineInvokeInput) -> AgentRoutineRun: 624 """ 625 Invoke a routine 626 Triggers an on-demand invocation of the specified routine, dispatching an 627 asynchronous agent run and returning a run record immediately. The routine must 628 be active and must have `event_type` set to `"agentroutine.invoked"`. 629 The routine's `preset_config.session_mode` determines session behavior: each 630 call may create a new session (`"stateless"`) or reuse an existing one 631 (`"session"`). When `session_scope` is `"per_user"`, the `user` param is 632 required for S2S and developer callers; authenticated client callers always 633 use their own identity. When `session_scope` is `"per_key"`, `session_key` 634 is required. 635 Supply `idempotency_key` to safely retry invocations if a completed run 636 already exists for that key a 409 Conflict is returned rather than creating 637 a duplicate run. Entitlement for LLM calls is checked at request time; 638 customers on plans that do not include this feature receive 402. 639 640 Args: 641 routine: Routine ID (`arn_...`) or `lookup_key` of the routine to invoke. 642 input: Request body. 643 input.idempotency_key: Unique key used to deduplicate invocations. Resubmitting the same key returns 409 if a completed run already exists. 644 input.message: The user message to send to the agent for this invocation. 645 input.metadata: Arbitrary key-value metadata attached to this invocation. Not interpreted by the platform. 646 input.session_key: Arbitrary key used to identify and resume a session when `session_scope` is `"per_key"`. Required in that mode. 647 input.thread_id: Thread ID (`thr_...`) to post the preset output into. Omit to skip thread posting. 648 input.user: User ID to associate with the session. For S2S and developer callers only; authenticated client callers always use their own identity. 649 650 Returns: 651 The agent routine run created by this invocation. 652 """ 653 return self._http.request( 654 f"/api/v1/agent_routines/{routine}/invoke", 655 method="POST", 656 body=input, 657 response_type=AgentRoutineRun, 658 ) 659 660 def pause(self, routine: str) -> AgentRoutine: 661 """ 662 Pause a routine 663 Sets the routine's status to `"paused"`, suspending event processing and 664 scheduled execution without deleting the routine or its configuration. A 665 paused routine can be resumed at any time by calling the activate endpoint. 666 Requires app scope. 667 668 Args: 669 routine: Routine ID (`arn_...`) of the routine to pause. 670 671 Returns: 672 The updated routine with `status` set to `"paused"`. 673 """ 674 return self._http.request( 675 f"/api/v1/agent_routines/{routine}/pause", 676 method="POST", 677 response_type=AgentRoutine, 678 ) 679 680 def runs( 681 self, 682 routine: str, 683 *, 684 status: str | None = None, 685 limit: int | None = None, 686 before_cursor: str | None = None, 687 after_cursor: str | None = None, 688 ) -> AgentRoutineRunListResponse: 689 """ 690 List runs for a routine 691 Returns a cursor-paginated list of runs for the specified routine, ordered 692 from most recent to oldest by default. Use `before_cursor` and `after_cursor` 693 to page through results in either direction. 694 You can filter runs by status to monitor a specific lifecycle phase. The 695 authenticated principal must have access to the routine's parent app. When 696 your API key is scoped to an app, only runs belonging to that app are 697 returned. 698 699 Args: 700 routine: Routine ID (`rtn_...`) whose runs you want to list. 701 status: Filter runs by status. One of `"pending"`, `"running"`, `"completed"`, `"failed"`, or `"skipped"`. Omit to return runs in all statuses. 702 limit: Maximum number of runs to return per page. Defaults to 50; maximum is 100. 703 before_cursor: Opaque cursor from a previous response's `before_cursor` field. Returns the page of runs older than this cursor. 704 after_cursor: Opaque cursor from a previous response's `after_cursor` field. Returns the page of runs newer than this cursor. 705 706 Returns: 707 Paginated list of routine runs. 708 """ 709 query: dict[str, object] = {} 710 if status is not None: 711 query["status"] = status 712 if limit is not None: 713 query["limit"] = limit 714 if before_cursor is not None: 715 query["before_cursor"] = before_cursor 716 if after_cursor is not None: 717 query["after_cursor"] = after_cursor 718 return self._http.request( 719 f"/api/v1/agent_routines/{routine}/runs", 720 query=query, 721 response_type=AgentRoutineRunListResponse, 722 )
477 def list( 478 self, *, agent: str | None = None, event_type: str | None = None 479 ) -> AgentRoutineListResponse: 480 """ 481 List routines 482 Returns all routines within the authenticated app scope. Optionally filter by 483 agent or event type. When `agent` is omitted, all routines accessible to the 484 caller are returned regardless of which agent they belong to. 485 If `agent` is provided but does not exist or is not accessible, the endpoint 486 returns 404 rather than an empty list. Results are not paginated; all matching 487 routines are returned in a single response. Requires app scope. 488 489 Args: 490 agent: Agent ID (`agt_...`) to filter routines by. Omit to return routines across all agents. 491 event_type: Event type string to filter by (e.g. `"agentroutine.invoked"`). Omit to return routines for all event types. 492 493 Returns: 494 Object containing a `data` array of matching routines. 495 """ 496 query: dict[str, object] = {} 497 if agent is not None: 498 query["agent"] = agent 499 if event_type is not None: 500 query["event_type"] = event_type 501 return self._http.request( 502 "/api/v1/agent_routines", 503 query=query, 504 response_type=AgentRoutineListResponse, 505 )
List routines
Returns all routines within the authenticated app scope. Optionally filter by
agent or event type. When agent is omitted, all routines accessible to the
caller are returned regardless of which agent they belong to.
If agent is provided but does not exist or is not accessible, the endpoint
returns 404 rather than an empty list. Results are not paginated; all matching
routines are returned in a single response. Requires app scope.
Arguments:
- agent: Agent ID (
agt_...) to filter routines by. Omit to return routines across all agents. - event_type: Event type string to filter by (e.g.
"agentroutine.invoked"). Omit to return routines for all event types.
Returns:
Object containing a
dataarray of matching routines.
507 def presets(self) -> builtins.list[RoutinePreset]: 508 """ 509 List routine presets 510 Returns all registered routine presets available to the authenticated app, 511 including each preset's name, display metadata, and accepted configuration 512 schema. Use this endpoint to discover which presets can be referenced when 513 creating or updating a routine with `handler_type: "preset"`. 514 The list reflects presets registered at server start time and does not change 515 at runtime. Requires app scope. 516 517 Returns: 518 Array of available routine preset objects. 519 """ 520 return self._http.request( 521 "/api/v1/agent_routines/presets", 522 response_type=list[RoutinePreset], 523 )
List routine presets
Returns all registered routine presets available to the authenticated app,
including each preset's name, display metadata, and accepted configuration
schema. Use this endpoint to discover which presets can be referenced when
creating or updating a routine with handler_type: "preset".
The list reflects presets registered at server start time and does not change
at runtime. Requires app scope.
Returns:
Array of available routine preset objects.
525 def delete(self, routine: str) -> None: 526 """ 527 Delete a routine 528 Permanently deletes the specified routine. This action is irreversible the 529 routine and its configuration are removed immediately. Any in-flight event 530 processing initiated by this routine before deletion may still complete. 531 Requires app scope. Returns 204 No Content on success. 532 533 Args: 534 routine: Routine ID (`arn_...`) of the routine to delete. 535 536 Returns: 537 Empty response on successful deletion (HTTP 204 No Content). 538 """ 539 self._http.request(f"/api/v1/agent_routines/{routine}", method="DELETE")
Delete a routine Permanently deletes the specified routine. This action is irreversible the routine and its configuration are removed immediately. Any in-flight event processing initiated by this routine before deletion may still complete. Requires app scope. Returns 204 No Content on success.
Arguments:
- routine: Routine ID (
arn_...) of the routine to delete.
Returns:
Empty response on successful deletion (HTTP 204 No Content).
541 def get(self, routine: str) -> AgentRoutine: 542 """ 543 Retrieve a routine 544 Returns the full routine record for the given routine ID. Use this endpoint to 545 inspect a routine's current configuration, handler type, event config, schedule, 546 and lifecycle status. 547 Requires app scope. Returns 404 if the routine does not exist or is not 548 accessible to the caller. 549 550 Args: 551 routine: Routine ID (`arn_...`) of the routine to retrieve. 552 553 Returns: 554 The requested routine. 555 """ 556 return self._http.request(f"/api/v1/agent_routines/{routine}", response_type=AgentRoutine)
Retrieve a routine Returns the full routine record for the given routine ID. Use this endpoint to inspect a routine's current configuration, handler type, event config, schedule, and lifecycle status. Requires app scope. Returns 404 if the routine does not exist or is not accessible to the caller.
Arguments:
- routine: Routine ID (
arn_...) of the routine to retrieve.
Returns:
The requested routine.
558 def update(self, routine: str, input: AgentRoutineUpdateInput) -> AgentRoutine: 559 """ 560 Update a routine 561 Updates one or more fields of the specified routine. Only the fields you 562 include are changed; omitted fields retain their current values. To change the 563 execution model, supply a new `handler_type` along with its required handler 564 body field (`config`, `script`, or `preset_name`). 565 When `template` is supplied, the routine's configuration is re-resolved from 566 the template before applying any additional field overrides. The routine's 567 `status`, `lookup_key`, and agent attachment are always preserved regardless 568 of template content. Updating `steps` replaces the entire step list send 569 the full desired list, not a partial diff. Requires app scope. 570 571 Args: 572 routine: Routine ID (`arn_...`) of the routine to update. 573 input: Request body. 574 input.acl: Updated access control list. Replaces the existing ACL entirely. 575 input.config: Workflow config ID (`cfg_...`). Used when `handler_type` is `"workflow_graph"`. 576 input.description: New human-readable description of what this routine does. 577 input.event_config: Mapping of event types to trigger configuration. Each key is an event type string; each value is an object with a `"filters"` map and an optional `"dedupe_key_path"` (a JSON path used to deduplicate events, e.g. `"$.thread.id"`). 578 input.event_type: Event type that triggers this routine. Deprecated use `event_config` instead. 579 input.handler_type: New execution model. One of `"workflow_graph"`, `"script"`, `"preset"`, or `"chain"`. 580 input.lookup_key: New stable, unique key for deterministic lookup. Must be unique within the app. 581 input.metadata: Updated arbitrary key-value metadata. Replaces the existing metadata entirely. 582 input.name: New human-readable display name for the routine. 583 input.preset_config: Updated configuration passed to the preset at runtime. 584 input.preset_name: Name of the registered preset to use. Used when `handler_type` is `"preset"`. 585 input.schedule: New cron expression for time-triggered routines (e.g. `"0 9 * * 1"`). Must not be more frequent than once per hour. 586 input.script: New inline script source. Used when `handler_type` is `"script"`. 587 input.steps: Updated ordered list of steps for a chain handler. Required when `handler_type` is `"chain"`; must be omitted or empty otherwise. Replaces the entire existing step list send the full desired list, not a partial diff. 588 input.template: AgentRoutineTemplate config ID (`cfg_...`) or lookup key. When provided, the routine's configuration is re-resolved from the template before applying other param overrides. The routine's `status`, `lookup_key`, and agent attachment are always preserved. 589 input.trigger_context: Updated trigger context. One of `"chat_session"` or `"event"`. 590 591 Returns: 592 The updated routine. 593 """ 594 return self._http.request( 595 f"/api/v1/agent_routines/{routine}", 596 method="PATCH", 597 body=input, 598 response_type=AgentRoutine, 599 )
Update a routine
Updates one or more fields of the specified routine. Only the fields you
include are changed; omitted fields retain their current values. To change the
execution model, supply a new handler_type along with its required handler
body field (config, script, or preset_name).
When template is supplied, the routine's configuration is re-resolved from
the template before applying any additional field overrides. The routine's
status, lookup_key, and agent attachment are always preserved regardless
of template content. Updating steps replaces the entire step list send
the full desired list, not a partial diff. Requires app scope.
Arguments:
- routine: Routine ID (
arn_...) of the routine to update. - input: Request body.
- input.acl: Updated access control list. Replaces the existing ACL entirely.
- input.config: Workflow config ID (
cfg_...). Used whenhandler_typeis"workflow_graph". - input.description: New human-readable description of what this routine does.
- input.event_config: Mapping of event types to trigger configuration. Each key is an event type string; each value is an object with a
"filters"map and an optional"dedupe_key_path"(a JSON path used to deduplicate events, e.g."$.thread.id"). - input.event_type: Event type that triggers this routine. Deprecated use
event_configinstead. - input.handler_type: New execution model. One of
"workflow_graph","script","preset", or"chain". - input.lookup_key: New stable, unique key for deterministic lookup. Must be unique within the app.
- input.metadata: Updated arbitrary key-value metadata. Replaces the existing metadata entirely.
- input.name: New human-readable display name for the routine.
- input.preset_config: Updated configuration passed to the preset at runtime.
- input.preset_name: Name of the registered preset to use. Used when
handler_typeis"preset". - input.schedule: New cron expression for time-triggered routines (e.g.
"0 9 * * 1"). Must not be more frequent than once per hour. - input.script: New inline script source. Used when
handler_typeis"script". - input.steps: Updated ordered list of steps for a chain handler. Required when
handler_typeis"chain"; must be omitted or empty otherwise. Replaces the entire existing step list send the full desired list, not a partial diff. - input.template: AgentRoutineTemplate config ID (
cfg_...) or lookup key. When provided, the routine's configuration is re-resolved from the template before applying other param overrides. The routine'sstatus,lookup_key, and agent attachment are always preserved. - input.trigger_context: Updated trigger context. One of
"chat_session"or"event".
Returns:
The updated routine.
601 def activate(self, routine: str) -> AgentRoutine: 602 """ 603 Activate a routine 604 Sets the routine's status to `"active"`, enabling it to process events or run 605 on its configured schedule. Only routines that have a workflow config attached 606 can be activated; attempting to activate a routine with no config returns 422. 607 Scheduled routines must be configured to run no more frequently than once per 608 hour. Activation fails with 422 if the cron schedule is more frequent than 609 that limit. Requires app scope. 610 611 Args: 612 routine: Routine ID (`arn_...`) of the routine to activate. 613 614 Returns: 615 The updated routine with `status` set to `"active"`. 616 """ 617 return self._http.request( 618 f"/api/v1/agent_routines/{routine}/activate", 619 method="POST", 620 response_type=AgentRoutine, 621 )
Activate a routine
Sets the routine's status to "active", enabling it to process events or run
on its configured schedule. Only routines that have a workflow config attached
can be activated; attempting to activate a routine with no config returns 422.
Scheduled routines must be configured to run no more frequently than once per
hour. Activation fails with 422 if the cron schedule is more frequent than
that limit. Requires app scope.
Arguments:
- routine: Routine ID (
arn_...) of the routine to activate.
Returns:
The updated routine with
statusset to"active".
623 def invoke(self, routine: str, input: AgentRoutineInvokeInput) -> AgentRoutineRun: 624 """ 625 Invoke a routine 626 Triggers an on-demand invocation of the specified routine, dispatching an 627 asynchronous agent run and returning a run record immediately. The routine must 628 be active and must have `event_type` set to `"agentroutine.invoked"`. 629 The routine's `preset_config.session_mode` determines session behavior: each 630 call may create a new session (`"stateless"`) or reuse an existing one 631 (`"session"`). When `session_scope` is `"per_user"`, the `user` param is 632 required for S2S and developer callers; authenticated client callers always 633 use their own identity. When `session_scope` is `"per_key"`, `session_key` 634 is required. 635 Supply `idempotency_key` to safely retry invocations if a completed run 636 already exists for that key a 409 Conflict is returned rather than creating 637 a duplicate run. Entitlement for LLM calls is checked at request time; 638 customers on plans that do not include this feature receive 402. 639 640 Args: 641 routine: Routine ID (`arn_...`) or `lookup_key` of the routine to invoke. 642 input: Request body. 643 input.idempotency_key: Unique key used to deduplicate invocations. Resubmitting the same key returns 409 if a completed run already exists. 644 input.message: The user message to send to the agent for this invocation. 645 input.metadata: Arbitrary key-value metadata attached to this invocation. Not interpreted by the platform. 646 input.session_key: Arbitrary key used to identify and resume a session when `session_scope` is `"per_key"`. Required in that mode. 647 input.thread_id: Thread ID (`thr_...`) to post the preset output into. Omit to skip thread posting. 648 input.user: User ID to associate with the session. For S2S and developer callers only; authenticated client callers always use their own identity. 649 650 Returns: 651 The agent routine run created by this invocation. 652 """ 653 return self._http.request( 654 f"/api/v1/agent_routines/{routine}/invoke", 655 method="POST", 656 body=input, 657 response_type=AgentRoutineRun, 658 )
Invoke a routine
Triggers an on-demand invocation of the specified routine, dispatching an
asynchronous agent run and returning a run record immediately. The routine must
be active and must have event_type set to "agentroutine.invoked".
The routine's preset_config.session_mode determines session behavior: each
call may create a new session ("stateless") or reuse an existing one
("session"). When session_scope is "per_user", the user param is
required for S2S and developer callers; authenticated client callers always
use their own identity. When session_scope is "per_key", session_key
is required.
Supply idempotency_key to safely retry invocations if a completed run
already exists for that key a 409 Conflict is returned rather than creating
a duplicate run. Entitlement for LLM calls is checked at request time;
customers on plans that do not include this feature receive 402.
Arguments:
- routine: Routine ID (
arn_...) orlookup_keyof the routine to invoke. - input: Request body.
- input.idempotency_key: Unique key used to deduplicate invocations. Resubmitting the same key returns 409 if a completed run already exists.
- input.message: The user message to send to the agent for this invocation.
- input.metadata: Arbitrary key-value metadata attached to this invocation. Not interpreted by the platform.
- input.session_key: Arbitrary key used to identify and resume a session when
session_scopeis"per_key". Required in that mode. - input.thread_id: Thread ID (
thr_...) to post the preset output into. Omit to skip thread posting. - input.user: User ID to associate with the session. For S2S and developer callers only; authenticated client callers always use their own identity.
Returns:
The agent routine run created by this invocation.
660 def pause(self, routine: str) -> AgentRoutine: 661 """ 662 Pause a routine 663 Sets the routine's status to `"paused"`, suspending event processing and 664 scheduled execution without deleting the routine or its configuration. A 665 paused routine can be resumed at any time by calling the activate endpoint. 666 Requires app scope. 667 668 Args: 669 routine: Routine ID (`arn_...`) of the routine to pause. 670 671 Returns: 672 The updated routine with `status` set to `"paused"`. 673 """ 674 return self._http.request( 675 f"/api/v1/agent_routines/{routine}/pause", 676 method="POST", 677 response_type=AgentRoutine, 678 )
Pause a routine
Sets the routine's status to "paused", suspending event processing and
scheduled execution without deleting the routine or its configuration. A
paused routine can be resumed at any time by calling the activate endpoint.
Requires app scope.
Arguments:
- routine: Routine ID (
arn_...) of the routine to pause.
Returns:
The updated routine with
statusset to"paused".
680 def runs( 681 self, 682 routine: str, 683 *, 684 status: str | None = None, 685 limit: int | None = None, 686 before_cursor: str | None = None, 687 after_cursor: str | None = None, 688 ) -> AgentRoutineRunListResponse: 689 """ 690 List runs for a routine 691 Returns a cursor-paginated list of runs for the specified routine, ordered 692 from most recent to oldest by default. Use `before_cursor` and `after_cursor` 693 to page through results in either direction. 694 You can filter runs by status to monitor a specific lifecycle phase. The 695 authenticated principal must have access to the routine's parent app. When 696 your API key is scoped to an app, only runs belonging to that app are 697 returned. 698 699 Args: 700 routine: Routine ID (`rtn_...`) whose runs you want to list. 701 status: Filter runs by status. One of `"pending"`, `"running"`, `"completed"`, `"failed"`, or `"skipped"`. Omit to return runs in all statuses. 702 limit: Maximum number of runs to return per page. Defaults to 50; maximum is 100. 703 before_cursor: Opaque cursor from a previous response's `before_cursor` field. Returns the page of runs older than this cursor. 704 after_cursor: Opaque cursor from a previous response's `after_cursor` field. Returns the page of runs newer than this cursor. 705 706 Returns: 707 Paginated list of routine runs. 708 """ 709 query: dict[str, object] = {} 710 if status is not None: 711 query["status"] = status 712 if limit is not None: 713 query["limit"] = limit 714 if before_cursor is not None: 715 query["before_cursor"] = before_cursor 716 if after_cursor is not None: 717 query["after_cursor"] = after_cursor 718 return self._http.request( 719 f"/api/v1/agent_routines/{routine}/runs", 720 query=query, 721 response_type=AgentRoutineRunListResponse, 722 )
List runs for a routine
Returns a cursor-paginated list of runs for the specified routine, ordered
from most recent to oldest by default. Use before_cursor and after_cursor
to page through results in either direction.
You can filter runs by status to monitor a specific lifecycle phase. The
authenticated principal must have access to the routine's parent app. When
your API key is scoped to an app, only runs belonging to that app are
returned.
Arguments:
- routine: Routine ID (
rtn_...) whose runs you want to list. - status: Filter runs by status. One of
"pending","running","completed","failed", or"skipped". Omit to return runs in all statuses. - limit: Maximum number of runs to return per page. Defaults to 50; maximum is 100.
- before_cursor: Opaque cursor from a previous response's
before_cursorfield. Returns the page of runs older than this cursor. - after_cursor: Opaque cursor from a previous response's
after_cursorfield. Returns the page of runs newer than this cursor.
Returns:
Paginated list of routine runs.