v1
latestOpenAPI 3.0.02026-08-04891301.4 MBCreate a routine
Creates a new routine and attaches it to the specified agent. Routines define how an agent responds to events or a cron schedule; the handler_type controls which execution model is used.
The routine is created in "draft" status by default. To start processing events immediately, either pass status: "active" or call the activate endpoint after creation. Scheduled routines must run no more frequently than once per hour. Requires app scope.
post/api/v1/agents/{agent}/agent_routines
Path parameters
agentstring required
Agent ID (agt_...) that this routine will be attached to.
Request body
Example request
{
"acl": {
"add": [
{
"actions": [
"read",
"write"
],
"principal": "string",
"principal_type": "user"
}
],
"grants": [
{
"actions": [
"read",
"write"
],
"principal": "string",
"principal_type": "user"
}
],
"remove": [
{
"principal": "string",
"principal_type": "user"
}
]
},
"config": "string",
"description": "An example description.",
"event_config": {},
"event_type": "string",
"handler_type": "string",
"lookup_key": "string",
"metadata": {
"key": "value"
},
"name": "Example Name",
"preset_config": {
"instructions": "You are a helpful assistant. Answer questions concisely and cite sources when possible.",
"llm": {
"model": "claude-sonnet-4-5"
},
"session_mode": "stateless",
"session_scope": "per_user",
"structured_message_template_ids": [
"string"
]
},
"preset_name": "Example Name",
"schedule": "string",
"script": "string",
"status": "string",
"steps": [
{
"config": "string",
"handler_type": "preset",
"inputs": {},
"name": "Example Name",
"on_error": "halt",
"output_key": "string",
"preset_config": {
"instructions": "You are a helpful assistant. Answer questions concisely and cite sources when possible.",
"llm": {
"model": "claude-sonnet-4-5"
},
"session_mode": "stateless",
"session_scope": "per_user",
"structured_message_template_ids": [
"string"
]
},
"preset_name": "Example Name",
"script": "string"
}
],
"trigger_context": "string"
}Response
Successful response
Example response
{
"acl": {
"add": [
{
"actions": [
"read",
"write"
],
"principal": "string",
"principal_type": "user"
}
],
"grants": [
{
"actions": [
"read",
"write"
],
"principal": "string",
"principal_type": "user"
}
],
"remove": [
{
"principal": "string",
"principal_type": "user"
}
]
},
"agent": "agi_0aBcDeFgHiJkLmNoPqRsTu",
"app": "dap_0aBcDeFgHiJkLmNoPqRsTu",
"config": "cfg_0aBcDeFgHiJkLmNoPqRsTu",
"created_at": "2024-01-01T00:00:00Z",
"description": "An example description.",
"event_config": {},
"event_type": "agentroutine.invoked",
"handler_type": "script",
"id": "arn_0aBcDeFgHiJkLmNoPqRsTu",
"last_applied_template_config": "cfg_0aBcDeFgHiJkLmNoPqRsTu",
"lookup_key": "daily-digest",
"metadata": {
"key": "value"
},
"name": "Example Name",
"preset_config": {
"instructions": "You are a helpful assistant. Answer questions concisely and cite sources when possible.",
"llm": {
"model": "claude-sonnet-4-5"
},
"session_mode": "stateless",
"session_scope": "per_user",
"structured_message_template_ids": [
"string"
]
},
"preset_name": "Example Name",
"schedule": "string",
"script": "string",
"status": "active",
"steps": [
{}
],
"trigger_context": "event",
"updated_at": "2024-01-01T00:00:00Z"
}