openloops 0.1.38 → 0.1.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -2
- package/dist/services/agentic-jobs/entities/agentic-job-run.entity.d.ts +42 -0
- package/dist/services/agentic-jobs/entities/agentic-job-run.entity.js +103 -0
- package/dist/services/agentic-jobs/entities/agentic-job-run.entity.mjs +80 -0
- package/dist/services/agentic-jobs/entities/agentic-job.entity.d.ts +39 -0
- package/dist/services/agentic-jobs/entities/agentic-job.entity.js +113 -0
- package/dist/services/agentic-jobs/entities/agentic-job.entity.mjs +90 -0
- package/dist/services/agentic-jobs/entities/index.d.ts +3 -0
- package/dist/services/agentic-jobs/entities/index.js +26 -0
- package/dist/services/agentic-jobs/entities/index.mjs +3 -0
- package/dist/services/agentic-jobs/entities/recurrence.d.ts +18 -0
- package/dist/services/agentic-jobs/entities/recurrence.js +84 -0
- package/dist/services/agentic-jobs/entities/recurrence.mjs +59 -0
- package/dist/services/agentic-jobs/index.d.ts +4 -0
- package/dist/services/agentic-jobs/index.js +28 -0
- package/dist/services/agentic-jobs/index.mjs +4 -0
- package/dist/services/agentic-jobs/module.d.ts +31 -0
- package/dist/services/agentic-jobs/module.js +132 -0
- package/dist/services/agentic-jobs/module.mjs +95 -0
- package/dist/services/agentic-jobs/repositories/agentic-job-run.repository.d.ts +11 -0
- package/dist/services/agentic-jobs/repositories/agentic-job-run.repository.js +71 -0
- package/dist/services/agentic-jobs/repositories/agentic-job-run.repository.mjs +42 -0
- package/dist/services/agentic-jobs/repositories/agentic-job.repository.d.ts +27 -0
- package/dist/services/agentic-jobs/repositories/agentic-job.repository.js +127 -0
- package/dist/services/agentic-jobs/repositories/agentic-job.repository.mjs +98 -0
- package/dist/services/agentic-jobs/repositories/index.d.ts +2 -0
- package/dist/services/agentic-jobs/repositories/index.js +24 -0
- package/dist/services/agentic-jobs/repositories/index.mjs +2 -0
- package/dist/services/agentic-jobs/runner/agentic-job-runner.d.ts +48 -0
- package/dist/services/agentic-jobs/runner/agentic-job-runner.js +181 -0
- package/dist/services/agentic-jobs/runner/agentic-job-runner.mjs +157 -0
- package/dist/services/agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.d.ts +15 -0
- package/dist/services/agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.js +58 -0
- package/dist/services/agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.mjs +29 -0
- package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.d.ts +29 -0
- package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.js +110 -0
- package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.mjs +81 -0
- package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.d.ts +14 -0
- package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.js +73 -0
- package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.mjs +44 -0
- package/dist/services/agentic-jobs/use-cases/delete-agentic-job.use-case.d.ts +15 -0
- package/dist/services/agentic-jobs/use-cases/delete-agentic-job.use-case.js +65 -0
- package/dist/services/agentic-jobs/use-cases/delete-agentic-job.use-case.mjs +36 -0
- package/dist/services/agentic-jobs/use-cases/finish-agentic-job-run.use-case.d.ts +19 -0
- package/dist/services/agentic-jobs/use-cases/finish-agentic-job-run.use-case.js +75 -0
- package/dist/services/agentic-jobs/use-cases/finish-agentic-job-run.use-case.mjs +46 -0
- package/dist/services/agentic-jobs/use-cases/get-agentic-job-by-id.use-case.d.ts +14 -0
- package/dist/services/agentic-jobs/use-cases/get-agentic-job-by-id.use-case.js +55 -0
- package/dist/services/agentic-jobs/use-cases/get-agentic-job-by-id.use-case.mjs +26 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.d.ts +16 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.js +57 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.mjs +28 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.d.ts +16 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.js +57 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.mjs +28 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.d.ts +15 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.js +57 -0
- package/dist/services/agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.mjs +28 -0
- package/dist/services/agentic-jobs/use-cases/preview-agentic-job-runs.use-case.d.ts +15 -0
- package/dist/services/agentic-jobs/use-cases/preview-agentic-job-runs.use-case.js +52 -0
- package/dist/services/agentic-jobs/use-cases/preview-agentic-job-runs.use-case.mjs +23 -0
- package/dist/services/agentic-jobs/use-cases/renew-agentic-job-lease.use-case.d.ts +18 -0
- package/dist/services/agentic-jobs/use-cases/renew-agentic-job-lease.use-case.js +58 -0
- package/dist/services/agentic-jobs/use-cases/renew-agentic-job-lease.use-case.mjs +29 -0
- package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.d.ts +21 -0
- package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.js +67 -0
- package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.mjs +38 -0
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-run.use-case.d.ts +20 -0
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-run.use-case.js +86 -0
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-run.use-case.mjs +56 -0
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-runs.use-case.d.ts +19 -0
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-runs.use-case.js +68 -0
- package/dist/services/agentic-jobs/use-cases/sync-agentic-job-runs.use-case.mjs +39 -0
- package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.d.ts +15 -0
- package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.js +83 -0
- package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.mjs +54 -0
- package/dist/services/agentic-jobs/utils/job-fields.d.ts +14 -0
- package/dist/services/agentic-jobs/utils/job-fields.js +61 -0
- package/dist/services/agentic-jobs/utils/job-fields.mjs +37 -0
- package/dist/services/agentic-jobs/utils/next-run.d.ts +4 -0
- package/dist/services/agentic-jobs/utils/next-run.js +62 -0
- package/dist/services/agentic-jobs/utils/next-run.mjs +37 -0
- package/dist/services/agentic-jobs/utils/open-run.d.ts +12 -0
- package/dist/services/agentic-jobs/utils/open-run.js +47 -0
- package/dist/services/agentic-jobs/utils/open-run.mjs +24 -0
- package/dist/services/agentic-jobs/utils/settings.d.ts +2 -0
- package/dist/services/agentic-jobs/utils/settings.js +34 -0
- package/dist/services/agentic-jobs/utils/settings.mjs +10 -0
- package/docs/README.md +46 -0
- package/docs/agent.md +201 -0
- package/docs/agentic-jobs.md +207 -0
- package/docs/authentication.md +40 -0
- package/docs/chats.md +88 -0
- package/docs/configuration.md +69 -0
- package/docs/guardrails.md +71 -0
- package/docs/harness.md +81 -0
- package/docs/integration-guide.md +138 -0
- package/docs/llms.txt +35 -0
- package/docs/loops.md +147 -0
- package/docs/mcp-servers.md +148 -0
- package/docs/skills.md +104 -0
- package/docs/tools.md +90 -0
- package/docs/usage.md +86 -0
- package/docs/users.md +85 -0
- package/examples/agentic-jobs/create-agentic-job.ts +24 -0
- package/examples/agentic-jobs/list-agentic-job-runs.ts +28 -0
- package/examples/agentic-jobs/list-agentic-jobs.ts +25 -0
- package/examples/agentic-jobs/preview-agentic-job-runs.ts +16 -0
- package/examples/agentic-jobs/run-agentic-job-now.ts +19 -0
- package/examples/agentic-jobs/run-agentic-job-worker.ts +29 -0
- package/examples/agentic-jobs/update-agentic-job.ts +36 -0
- package/examples/authentication/login.ts +17 -0
- package/examples/chats/delete-chat.ts +32 -0
- package/examples/chats/get-chat-by-id.ts +32 -0
- package/examples/chats/list-autonomous-chats.ts +23 -0
- package/examples/chats/list-chats.ts +20 -0
- package/examples/guardrails/custom-guard.ts +11 -0
- package/examples/loops/custom-loop.ts +50 -0
- package/examples/mcps/create-mcp.ts +24 -0
- package/examples/mcps/decide-mcp.ts +40 -0
- package/examples/mcps/delete-mcp.ts +32 -0
- package/examples/mcps/get-mcp-by-id.ts +17 -0
- package/examples/mcps/list-all-mcps.ts +14 -0
- package/examples/mcps/list-user-mcps.ts +23 -0
- package/examples/mcps/update-mcp.ts +23 -0
- package/examples/mcps/verify-mcp.ts +17 -0
- package/examples/run-agent/interrupt-agent.ts +16 -0
- package/examples/run-agent/run-agent-autonomous.ts +34 -0
- package/examples/run-agent/run-agent-strict-mode.ts +30 -0
- package/examples/run-agent/run-agent-with-confirmation.ts +49 -0
- package/examples/run-agent/run-agent-with-guards.ts +33 -0
- package/examples/run-agent/run-agent-with-hooks.ts +55 -0
- package/examples/run-agent/run-agent-with-identity.ts +36 -0
- package/examples/run-agent/run-agent-with-model.ts +33 -0
- package/examples/run-agent/run-agent-with-tools.ts +31 -0
- package/examples/tools/basic-tool.ts +35 -0
- package/examples/tools/destructive-tool.ts +34 -0
- package/examples/tools/web-search-tool.ts +37 -0
- package/examples/usage/get-chat-usage.ts +22 -0
- package/examples/usage/get-message-usage.ts +22 -0
- package/examples/usage/get-usage-stats-by-range.ts +23 -0
- package/examples/usage/get-usage-stats.ts +18 -0
- package/examples/users/create-user.ts +19 -0
- package/examples/users/delete-user.ts +36 -0
- package/examples/users/get-user-by-id.ts +18 -0
- package/examples/users/list-users.ts +18 -0
- package/examples/users/update-user.ts +22 -0
- package/package.json +9 -2
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Agentic jobs
|
|
2
|
+
|
|
3
|
+
An agentic job is a task that your agent runs by itself, on a schedule, without anyone in the chat. You describe what it must do and when, and `openloops` runs it in [autonomous mode](agent.md#autonomous-mode), in a new chat each time, and keeps a history of every run.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import {
|
|
7
|
+
createAgenticJob,
|
|
8
|
+
updateAgenticJob,
|
|
9
|
+
getAgenticJobById,
|
|
10
|
+
listAgenticJobsByUser,
|
|
11
|
+
deleteAgenticJob,
|
|
12
|
+
previewAgenticJobRuns,
|
|
13
|
+
listAgenticJobRunsByJob,
|
|
14
|
+
listAgenticJobRunsByUser,
|
|
15
|
+
createAgenticJobRunner,
|
|
16
|
+
} from 'openloops/agentic-jobs'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
There are two parts. The use cases create and manage jobs and read their history, and are called from your API. The runner is a worker that you start in your backend and that executes what is due.
|
|
20
|
+
|
|
21
|
+
## Creating a job
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
const result = await createAgenticJob({
|
|
25
|
+
payload: {
|
|
26
|
+
name: 'Morning report',
|
|
27
|
+
instructions: 'Summarize my open tickets and send the summary to my email',
|
|
28
|
+
recurrence: { type: 'weekly', days: [1, 2, 3, 4, 5], time: '08:00' },
|
|
29
|
+
timezone: 'America/Lima',
|
|
30
|
+
modelProvider: 'anthropic',
|
|
31
|
+
modelName: 'claude-haiku-5-5',
|
|
32
|
+
},
|
|
33
|
+
currentUser,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
result.data.nextRunAt
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
| Field | Required | What it is |
|
|
40
|
+
| --- | --- | --- |
|
|
41
|
+
| `name` | yes | A name to recognize the job. |
|
|
42
|
+
| `instructions` | yes | What the agent must do. It is sent to the agent as the message of the user, so write it as you would write it in a chat. If the task needs to notify someone, say so here and give the agent a tool for it. |
|
|
43
|
+
| `recurrence` | yes | When it runs. See below. |
|
|
44
|
+
| `timezone` | yes | An IANA timezone. The local time of the recurrence and the days are those of this timezone, and daylight saving time is respected. |
|
|
45
|
+
| `enabled` | no | `true` by default. A job that is off never runs, and can be turned on again. |
|
|
46
|
+
| `modelProvider`, `modelName` | no | The model of the job, both or none. Without them the default model is used. |
|
|
47
|
+
|
|
48
|
+
`nextRunAt` is calculated when the job is created and it is what you show to the user. The fields that the system manages (`nextRunAt`, `lastRunAt`, `lastRunStatus`, `lockedBy`, `lockedUntil`, `activeRunId`) are ignored if they come in the payload.
|
|
49
|
+
|
|
50
|
+
### Recurrence
|
|
51
|
+
|
|
52
|
+
The recurrence is stored as a structured value, so a screen can offer simple choices and nobody has to write a cron expression. The time is the local time of the timezone of the job, in 24 hours.
|
|
53
|
+
|
|
54
|
+
| Type | Fields | Example |
|
|
55
|
+
| --- | --- | --- |
|
|
56
|
+
| `daily` | `time` | `{ type: 'daily', time: '08:00' }` |
|
|
57
|
+
| `weekly` | `days` (1 is Monday, 7 is Sunday), `time` | `{ type: 'weekly', days: [1, 2, 3, 4, 5], time: '09:30' }` is Monday to Friday |
|
|
58
|
+
| `monthly` | `day` (1 to 31 or `'last'`), `time` | `{ type: 'monthly', day: 15, time: '12:00' }` |
|
|
59
|
+
| `once` | `at` (`YYYY-MM-DDTHH:mm`, local time) | `{ type: 'once', at: '2026-12-25T10:00' }` |
|
|
60
|
+
|
|
61
|
+
- A monthly job on day 29, 30 or 31 is skipped in the months that do not have that day. Use `'last'` for the last day of every month.
|
|
62
|
+
- A time that does not exist on a day because of daylight saving time runs at the first valid moment of that day, and a time that happens twice runs once.
|
|
63
|
+
- A job of type `once` runs a single time and then has no next run.
|
|
64
|
+
|
|
65
|
+
### Previewing
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
const { data } = await previewAgenticJobRuns({
|
|
69
|
+
recurrence: { type: 'weekly', days: [1, 5], time: '08:00' },
|
|
70
|
+
timezone: 'America/Lima',
|
|
71
|
+
count: 5,
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
data.runs
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
It returns the next dates (at most 20) without saving anything, so a screen can show "it will run on Monday at 8:00, on Friday at 8:00...".
|
|
78
|
+
|
|
79
|
+
## Managing jobs
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
await updateAgenticJob({ id, payload: { enabled: false }, currentUser })
|
|
83
|
+
|
|
84
|
+
await updateAgenticJob({ id, payload: { enabled: true }, currentUser })
|
|
85
|
+
|
|
86
|
+
const job = await getAgenticJobById({ id, currentUser })
|
|
87
|
+
|
|
88
|
+
const jobs = await listAgenticJobsByUser({ options: { page: 1, limit: 10 }, currentUser })
|
|
89
|
+
|
|
90
|
+
await deleteAgenticJob({ id, currentUser })
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
- **Turning a job off** is how the user pauses it for a while. It has no next run until it is turned on again. Turning it on counts the next run from that moment, it does not catch up with what was missed.
|
|
94
|
+
- **Changing the recurrence, the timezone or turning it on** calculates `nextRunAt` again from now.
|
|
95
|
+
- **A run that is in progress is not interrupted** by turning the job off or by deleting it.
|
|
96
|
+
- **`__v`** in the payload works as in the other use cases: if the job changed since it was read, the update fails with a `VersionConflictError`.
|
|
97
|
+
- **Deleting** is a soft delete. An admin can delete for good with `hardDelete: true`.
|
|
98
|
+
- **The system never turns a job off by itself.** A job that fails keeps trying on every occurrence, so watch the history.
|
|
99
|
+
|
|
100
|
+
## The history
|
|
101
|
+
|
|
102
|
+
Every execution is a run.
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
const byJob = await listAgenticJobRunsByJob({ jobId, options: { page: 1, limit: 20 } })
|
|
106
|
+
|
|
107
|
+
const byUser = await listAgenticJobRunsByUser({ status: 'failed', currentUser })
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
| Field | Meaning |
|
|
111
|
+
| --- | --- |
|
|
112
|
+
| `jobId`, `chatId` | The job and the chat of the run. Open the chat to read everything that the agent did. |
|
|
113
|
+
| `trigger` | `schedule` or `manual`. |
|
|
114
|
+
| `scheduledFor`, `startedAt`, `finishedAt` | When it was due, when it started and when it ended. |
|
|
115
|
+
| `status` | See below. |
|
|
116
|
+
| `error` | `code` and `message` when it failed. |
|
|
117
|
+
| `skipReason` | Why a run was skipped. |
|
|
118
|
+
| `instructions`, `modelProvider`, `modelName` | What was run, as it was when the run started, even if the job was edited later. |
|
|
119
|
+
|
|
120
|
+
| Status | Meaning |
|
|
121
|
+
| --- | --- |
|
|
122
|
+
| `running` | In progress. |
|
|
123
|
+
| `completed` | The agent finished its task. |
|
|
124
|
+
| `paused` | The agent needs the user: it asked for the approval of a tool or an MCP server, or asked a question. The chat is waiting. When the user answers in the chat and it finishes, the run becomes `completed` or `failed`. |
|
|
125
|
+
| `failed` | It failed. `error` says why: the model did not answer in time, a guardrail blocked the instructions, the owner no longer exists, or the worker was lost. |
|
|
126
|
+
| `skipped` | It was due, but the previous run was still `paused`, so it was not started. It is recorded so you can notify the user. |
|
|
127
|
+
|
|
128
|
+
## The runner
|
|
129
|
+
|
|
130
|
+
The runner is a worker that checks what is due and runs it. You create it once, with the agent that your jobs should use, and start it in your backend.
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { createAgenticJobRunner } from 'openloops/agentic-jobs'
|
|
134
|
+
import { webSearchTool } from 'openloops/tools'
|
|
135
|
+
import { inputGuards } from 'openloops/guardrails'
|
|
136
|
+
|
|
137
|
+
const runner = createAgenticJobRunner({
|
|
138
|
+
agent: {
|
|
139
|
+
tools: [webSearchTool, sendEmailTool],
|
|
140
|
+
guards: [inputGuards.blockCard],
|
|
141
|
+
maxIterations: 30,
|
|
142
|
+
},
|
|
143
|
+
onRunFinished: async ({ job, run, chat }) => {
|
|
144
|
+
if (run.status === 'failed' || run.status === 'skipped') await notifyTheOwner(job, run)
|
|
145
|
+
},
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
runner.start()
|
|
149
|
+
|
|
150
|
+
process.on('SIGTERM', async () => {
|
|
151
|
+
await runner.stop()
|
|
152
|
+
process.exit(0)
|
|
153
|
+
})
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
| Option | Default | What it does |
|
|
157
|
+
| --- | --- | --- |
|
|
158
|
+
| `agent` | `{}` | The options of the `Agent` used for every run: tools, guards, `maxIterations`, `strictMode`, `identity`... It can be a function `({ job, currentUser }) => options` when they depend on the job or on the user. The loop is `AgiLoop` unless you set `loop`. A custom loop must support autonomous mode (`harness.executionMode`). |
|
|
159
|
+
| `intervalMs` | `60000` | How often it checks. Also set with `AGENTIC_JOBS_POLL_INTERVAL_MS`. |
|
|
160
|
+
| `leaseMs` | `600000` | How long a job stays locked while it runs, renewed while the run lasts. Also set with `AGENTIC_JOBS_LEASE_MS`. |
|
|
161
|
+
| `maxConcurrentRuns` | `3` | How many runs a runner executes at once. |
|
|
162
|
+
| `stopTimeoutMs` | `30000` | How long `stop()` waits for the runs in progress. |
|
|
163
|
+
| `workerId` | generated | An identifier of the worker, kept in the run. |
|
|
164
|
+
| `onRunFinished` | none | Called with `{ job, run, chat }` when a run ends, is paused or is skipped. An error in it does not affect the run. |
|
|
165
|
+
|
|
166
|
+
A new `Agent` is created for every run, so the options are the same but nothing is shared between runs.
|
|
167
|
+
|
|
168
|
+
### What every run does
|
|
169
|
+
|
|
170
|
+
- It runs as the owner of the job, which must exist.
|
|
171
|
+
- It starts a new chat, in autonomous mode, with the model of the job, and the instructions as the first message. The chat is recorded in the run as soon as it exists.
|
|
172
|
+
- It gives the agent the timezone of the job, so the local time reaches the prompts.
|
|
173
|
+
- Guards of the agent apply to the instructions. If one blocks them, the run is `failed`.
|
|
174
|
+
|
|
175
|
+
### Running by hand
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
const { run } = await runner.runNow({ jobId })
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
It starts the run at once and returns while it keeps running in the background. It does not change the next scheduled run. It is refused if the job is already running. Any process that has a runner can call it, it does not need to be the one that called `start()`.
|
|
182
|
+
|
|
183
|
+
### Several instances
|
|
184
|
+
|
|
185
|
+
You can run the worker in as many pods as you want. A job is taken with a single atomic update in the database that only one worker wins, and the same update moves `nextRunAt` to the next occurrence. So:
|
|
186
|
+
|
|
187
|
+
- A job is never started twice at the same time.
|
|
188
|
+
- A run that fails, or whose worker dies, is **not repeated** until the next occurrence.
|
|
189
|
+
- If the backend was down, a job that was due runs **once**, and the next run is counted from now.
|
|
190
|
+
- The lease expires if a worker dies. The run it left in progress is marked as `failed` and the job keeps its schedule.
|
|
191
|
+
|
|
192
|
+
If you prefer, start the runner in a single deployment and call `runNow` from the others.
|
|
193
|
+
|
|
194
|
+
### Settling the runs that wait for the user
|
|
195
|
+
|
|
196
|
+
Someone answers a paused run in the chat, outside the runner. The runner checks the open runs on every pass and updates them from the state of their chat. If you want it faster, call `syncAgenticJobRun({ runId })` when your own events tell you that a chat ended.
|
|
197
|
+
|
|
198
|
+
## Indexes
|
|
199
|
+
|
|
200
|
+
The collections are `agentic_jobs` and `agentic_job_runs`. For the queries of the runner and of the lists, create these indexes:
|
|
201
|
+
|
|
202
|
+
- `agentic_jobs`: `{ enabled: 1, nextRunAt: 1 }` and `{ ownerId: 1, createdAt: -1 }`.
|
|
203
|
+
- `agentic_job_runs`: `{ jobId: 1, createdAt: -1 }`, `{ ownerId: 1, createdAt: -1 }` and `{ status: 1, createdAt: 1 }`.
|
|
204
|
+
|
|
205
|
+
## Limits
|
|
206
|
+
|
|
207
|
+
How many jobs a user can have, how often they can run and how much they can spend is not decided here. That belongs to the module of usage limits.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Authentication
|
|
2
|
+
|
|
3
|
+
`openloops` can log a user in against its own user records and issue a token. Verifying that token on each request, and deciding who may call what, is up to your backend.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import { login } from 'openloops/authentication'
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Logging in
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
const result = await login({
|
|
13
|
+
payload: {
|
|
14
|
+
emailOrUsername: 'jose@openloops.xyz',
|
|
15
|
+
password: 'a-real-password',
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
result.data.token
|
|
20
|
+
result.data.user
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
- `token` is a JWT signed with `JWT_SECRET`. Its payload carries `userId`, `email`, `firstName` and `lastName`.
|
|
24
|
+
- Tokens last 1 hour for admins and 7 days for everyone else.
|
|
25
|
+
- `user` is the user record without the password.
|
|
26
|
+
- An unknown user fails with a 404 and a wrong password with a 401.
|
|
27
|
+
|
|
28
|
+
`JWT_SECRET` must be set. See [configuration](configuration.md).
|
|
29
|
+
|
|
30
|
+
## From a token to a `CurrentUser`
|
|
31
|
+
|
|
32
|
+
After your backend verifies the token, build the `CurrentUser` that every other call needs:
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { CurrentUser } from 'openloops/base'
|
|
36
|
+
|
|
37
|
+
const currentUser = await CurrentUser.asyncFromDB(payload.userId)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
See [users](users.md).
|
package/docs/chats.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Chats
|
|
2
|
+
|
|
3
|
+
Every conversation with an agent is a chat. The `Agent` creates and updates chats by itself, so you only use these functions to build the surrounding experience: a list of conversations, loading one, deleting it.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import { createChat, getChatById, listChatsByUser, updateChat, deleteChat } from 'openloops/chats'
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## The chat record
|
|
10
|
+
|
|
11
|
+
| Field | Meaning |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| `state` | `status`, detected `language`, `activeTaskId`, `currentActivity`, `lastError` and `stopRequested`. See [agent](agent.md#the-result) for the statuses. |
|
|
14
|
+
| `settings` | `modelProvider`, `modelName`, `loopName`, `executionMode`, `notifyOnCompletion` and `isPrivateSession`. |
|
|
15
|
+
| `messages` | The conversation. Each message has `role` (`user` or `assistant`), `source`, `content`, `answerId` and `excludeFromContext`. |
|
|
16
|
+
|
|
17
|
+
Every assistant message of one answer shares an `answerId`. It is the id you pass as `messageId` to [usage](usage.md).
|
|
18
|
+
|
|
19
|
+
`role` says on which side of the conversation a message is, and `source` says who produced it:
|
|
20
|
+
|
|
21
|
+
| `source` | Meaning |
|
|
22
|
+
| --- | --- |
|
|
23
|
+
| `user` | Written by the person. |
|
|
24
|
+
| `model` | Written by the model: the answers and questions of the agent. |
|
|
25
|
+
| `harness` | Written by the harness: the reply of a [guardrail](guardrails.md), the question that asks for an approval, the acknowledgement of a cancelled task and, in an autonomous run, the answer of the automatic evaluator, which has `role: 'user'`. |
|
|
26
|
+
|
|
27
|
+
A message saved before `source` existed has none.
|
|
28
|
+
|
|
29
|
+
Messages with `excludeFromContext` are shown in the history but never sent to the model. They are the ones blocked by a guardrail and, in an autonomous run, the questions of the model together with the automatic answers.
|
|
30
|
+
|
|
31
|
+
## Listing a user's chats
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
const result = await listChatsByUser({
|
|
35
|
+
options: { page: 1, limit: 10 },
|
|
36
|
+
currentUser,
|
|
37
|
+
})
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Sorted by last update, newest first. Defaults to page 1 and 10 chats.
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
const autonomous = await listChatsByUser({ executionMode: 'autonomous', currentUser })
|
|
44
|
+
|
|
45
|
+
const interactive = await listChatsByUser({ executionMode: 'interactive', currentUser })
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`executionMode` is optional. `autonomous` returns the chats that were created by an autonomous run and `interactive` returns the rest, including the chats saved before the mode existed. Combine it with `state.status` to show the autonomous runs that need attention: `awaiting_user_confirmation` or `awaiting_user_input` mean the run is paused until the user answers in the chat, and `failed` means it failed.
|
|
49
|
+
|
|
50
|
+
## Getting one chat
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
const result = await getChatById({ id: chatId, currentUser })
|
|
54
|
+
|
|
55
|
+
const state = await getChatById({ id: chatId, select: { state: 1 }, currentUser })
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`select` limits the fields that come back, which is handy for polling the status of a long run.
|
|
59
|
+
|
|
60
|
+
## Creating and updating
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
const created = await createChat({ payload: { settings: { loopName: 'agi' } }, currentUser })
|
|
64
|
+
|
|
65
|
+
await updateChat({ id: chatId, payload: { settings: { modelProvider: 'anthropic', modelName: 'claude-haiku-5-5' } }, currentUser })
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
You rarely need `createChat`: `agent.run` creates the chat when you omit `chatId`.
|
|
69
|
+
|
|
70
|
+
## Deleting a chat
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
await deleteChat({ id: chatId, currentUser })
|
|
74
|
+
|
|
75
|
+
await deleteChat({ id: chatId, hardDelete: true, currentUser })
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The first one is a soft delete. A hard delete is for admins only.
|
|
79
|
+
|
|
80
|
+
## Stopping a running chat
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { Agent } from 'openloops/core'
|
|
84
|
+
|
|
85
|
+
await Agent.interruptExecution(chatId, currentUser)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
See [agent](agent.md#stopping-a-running-turn).
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Configuration
|
|
2
|
+
|
|
3
|
+
`openloops` reads its configuration from environment variables. Copy `.env.example` and fill in what you use.
|
|
4
|
+
|
|
5
|
+
| Variable | Required | What it is for |
|
|
6
|
+
| --- | --- | --- |
|
|
7
|
+
| `OPENLOOPS_DB_URI` | yes | MongoDB connection string. |
|
|
8
|
+
| `OPENLOOPS_DB_NAME` | no | Database name. Defaults to `openloops`. |
|
|
9
|
+
| `SECRET_MANAGER_KEY` | yes | Key used to decrypt values that start with `ENC:`. The library throws when it loads without it. |
|
|
10
|
+
| `ANTHROPIC_API_KEY` | for the default model | API key of the default provider, `anthropic`. |
|
|
11
|
+
| `OPENAI_API_KEY`, `GEMINI_API_KEY` | for those providers | API keys of the other providers you choose per chat. |
|
|
12
|
+
| `JWT_SECRET` | for `login` | Secret that signs the tokens. See [authentication](authentication.md). |
|
|
13
|
+
| `SERPER_API_KEY` | for `webSearchTool` | See [tools](tools.md#built-in-tools). |
|
|
14
|
+
| `AGENTIC_JOBS_POLL_INTERVAL_MS` | no | How often the runner of [agentic jobs](agentic-jobs.md) checks what is due, in milliseconds. Defaults to `60000`. |
|
|
15
|
+
| `AGENTIC_JOBS_LEASE_MS` | no | How long a job stays locked while it runs, in milliseconds. Defaults to `600000`. |
|
|
16
|
+
| `LLM_CALL_TIMEOUT_MS` | no | Longest time to wait for one attempt of a model call, in milliseconds. Defaults to `60000`. See [Timeouts](#timeouts). |
|
|
17
|
+
| `MCP_TOOL_TIMEOUT_MS` | no | Longest time to wait for a tool of an MCP server, in milliseconds. Defaults to `60000`. See [Timeouts](#timeouts). |
|
|
18
|
+
| `SENTRY_DSN` | no | Errors are reported to Sentry when set, unless `IS_LOCAL` is `true` or `NODE_ENV` is `development`. |
|
|
19
|
+
| `LANGFUSE_PUBLIC_KEY`, `LANGFUSE_SECRET_KEY`, `LANGFUSE_BASE_URL` | no | Traces every LLM call in Langfuse when all three are set. |
|
|
20
|
+
| `IS_LOCAL`, `NODE_ENV` | no | Local development switches. |
|
|
21
|
+
|
|
22
|
+
Any value can be stored encrypted by prefixing it with `ENC:`. It is decrypted with `SECRET_MANAGER_KEY` when it is read.
|
|
23
|
+
|
|
24
|
+
## Default model
|
|
25
|
+
|
|
26
|
+
The default provider is `anthropic` and the default model is `claude-haiku-5-5`. It is what a chat uses when you do not choose another one, so `ANTHROPIC_API_KEY` is the only model key you need to start.
|
|
27
|
+
|
|
28
|
+
It was chosen with the project's own evals (the `evals/` folder of the repository, results of 2026-10-12), in the default `plain_chat` mode and next to `gpt-6-luna`, `gpt-4o-mini` and `gemini-2.5-flash`. The skill rows use the real prompt of the reasoning engine:
|
|
29
|
+
|
|
30
|
+
| | `claude-haiku-5-5` | Others in the same evals |
|
|
31
|
+
| --- | --- | --- |
|
|
32
|
+
| Accuracy of the reasoning engine skill | 20 of 20 runs, in two executions | 20 of 20 for `gpt-6-luna`, 10 of 10 for `gpt-4o-mini` (one execution), 17 of 20 for `gemini-2.5-flash` |
|
|
33
|
+
| Accuracy on the 10 case model suite | 30 of 30 runs | 30 of 30 for `gpt-6-luna`, 27 of 30 for `gpt-4o-mini` |
|
|
34
|
+
| Prompt tokens read from the cache | 70% to 71% | 53% to 55% for `gpt-6-luna`, 62% for `gpt-4o-mini`, 44% to 73% for `gemini-2.5-flash` |
|
|
35
|
+
| Price per million tokens | $0.10 input, $0.50 output, $0.01 cached input | $0.10 and $0.50 for `gpt-6-luna`, $0.15 and $0.60 for `gpt-4o-mini` |
|
|
36
|
+
|
|
37
|
+
It is in the low price tier, it makes the most of the prompt cache, which matters because the prompt of an agent is large and repeats in every cycle, and it was among the most accurate. These are small samples (10 runs per setup in the skill evals, 3 repetitions per case in the model suite) and results change as providers update their models, so run the evals again before relying on the numbers for another prompt or model.
|
|
38
|
+
|
|
39
|
+
## Timeouts
|
|
40
|
+
|
|
41
|
+
A model call that never answers would block the whole run, so every attempt has a time limit:
|
|
42
|
+
|
|
43
|
+
- **Model calls.** An attempt that does not answer within `LLM_CALL_TIMEOUT_MS` (60 seconds by default) is cancelled and the same call is made again, up to 3 attempts in total. When all of them time out, the run fails with the error code `LLM_TIMEOUT` and a message for the user, and the chat is left as `failed` so the user can send the message again. Waiting for a provider that asks to slow down is a separate mechanism and is not affected.
|
|
44
|
+
- **Tools of MCP servers.** A tool that does not answer within `MCP_TOOL_TIMEOUT_MS` (60 seconds by default) fails. The time starts again every time the server reports progress, so a long tool that is alive is not cut off. A tool call is never repeated automatically, because it may have changed something. The model is told that the result is unknown and that it must check before repeating it.
|
|
45
|
+
- **Langfuse.** Sending the trace of a call to Langfuse waits at most 5 seconds. If it takes longer or fails, the run continues without it.
|
|
46
|
+
|
|
47
|
+
A value that is not a positive whole number is ignored and the default is used.
|
|
48
|
+
|
|
49
|
+
## Choosing the model
|
|
50
|
+
|
|
51
|
+
Pick another one for a chat when you run it:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
await agent.run({
|
|
55
|
+
input: { message: 'hi' },
|
|
56
|
+
options: { modelProvider: 'anthropic', modelName: 'claude-haiku-5-5' },
|
|
57
|
+
currentUser,
|
|
58
|
+
})
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The choice is stored in the chat settings and used for the rest of that chat. Set the API key variable that the provider expects.
|
|
62
|
+
|
|
63
|
+
The model call goes through a single client that retries, cancels and repeats an attempt that does not answer in time, waits when the provider asks to slow down, drops a temperature setting the model rejects and turns provider errors into messages that are safe to show to the user.
|
|
64
|
+
|
|
65
|
+
## What is recorded
|
|
66
|
+
|
|
67
|
+
- Every LLM call, with its response, tokens and cost. See [usage](usage.md).
|
|
68
|
+
- A trace for every node and skill of a run, with the reasoning of the model. They are stored per chat for debugging and audit.
|
|
69
|
+
- The full ledger of actions of every task, with arguments, results and errors.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Guardrails
|
|
2
|
+
|
|
3
|
+
A guardrail is a rule that can stop a message before the agent spends anything on it. Guards are plain instances, like tools, and you register them on the `Agent`.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import { Guard, inputGuards } from 'openloops/guardrails'
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Using the ready-made guards
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { Agent } from 'openloops/core'
|
|
13
|
+
import { AgiLoop } from 'openloops/loops'
|
|
14
|
+
import { inputGuards } from 'openloops/guardrails'
|
|
15
|
+
|
|
16
|
+
const agent = new Agent({
|
|
17
|
+
loop: new AgiLoop(),
|
|
18
|
+
guards: [inputGuards.blockCode, inputGuards.blockEmail],
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
agent.addGuard(inputGuards.blockCard)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
| Guard | Blocks |
|
|
25
|
+
| --- | --- |
|
|
26
|
+
| `inputGuards.blockCode` | Messages with fenced code blocks (\`\`\` or ~~~). Inline snippets and error messages pass. |
|
|
27
|
+
| `inputGuards.blockEmail` | Messages that contain an email address. |
|
|
28
|
+
| `inputGuards.blockCard` | Messages that contain a payment card number. It looks for 13 to 19 digits that pass the Luhn check, so order numbers are left alone. |
|
|
29
|
+
|
|
30
|
+
The agent also registers a guard that blocks messages longer than `maxInputLength` (100000 characters by default).
|
|
31
|
+
|
|
32
|
+
## Changing the reply
|
|
33
|
+
|
|
34
|
+
Ready-made guards are shared and read-only. `withReply` returns a copy with another message but the same name, reference and handler:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
agent.addGuard(inputGuards.blockCard.withReply('Never send card numbers in the chat.'))
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Writing your own
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
const noSpam = new Guard({
|
|
44
|
+
name: 'no_spam',
|
|
45
|
+
description: 'Blocks obvious spam phrases',
|
|
46
|
+
type: 'input',
|
|
47
|
+
reply: 'This looks like spam.',
|
|
48
|
+
handler: ({ message }) => /buy now/i.test(message)
|
|
49
|
+
? { passed: false, reason: 'Spam phrase' }
|
|
50
|
+
: { passed: true },
|
|
51
|
+
})
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
| Prop | What it does |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| `name` | Unique name. Identifies the guard in the traces. |
|
|
57
|
+
| `type` | Where it runs. Only `'input'` exists: it runs on the user message before the model. |
|
|
58
|
+
| `reply` | What the user receives when the guard blocks. |
|
|
59
|
+
| `ref` | Reference shown to the user and written to the traces. Derived from `name` when omitted. |
|
|
60
|
+
| `handler` | Receives `{ message, chat, currentUser, currentSession, skillParams, logger }` and returns `{ passed, reason? }`. May be async. |
|
|
61
|
+
|
|
62
|
+
## What happens when a guard blocks
|
|
63
|
+
|
|
64
|
+
- Guards run in registration order and the first one that blocks wins.
|
|
65
|
+
- The model is never called and no task is created.
|
|
66
|
+
- The user receives the guard's `reply` followed by `Ref: <ref>`. The `reason` is never shown to the user. It is only written to the chat traces, so it can be specific.
|
|
67
|
+
- The blocked message is stored, flagged so it is left out of the history the model reads later.
|
|
68
|
+
- A chat that was waiting for a confirmation keeps waiting for it. Any other chat goes back to `idle`.
|
|
69
|
+
- If a handler throws, the message is blocked with a generic reply instead of passing unchecked.
|
|
70
|
+
|
|
71
|
+
Guards run on every run, including the message that answers a confirmation.
|
package/docs/harness.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# The harness
|
|
2
|
+
|
|
3
|
+
The harness is everything between a loop and the outside world. A loop decides what to do. The harness makes sure it is done safely, remembers it and shows the result back to the model in a form it can use. You get all of this by using `Agent` with any loop.
|
|
4
|
+
|
|
5
|
+
## Tool pipeline
|
|
6
|
+
|
|
7
|
+
Every action goes through the same pipeline before and after the tool runs:
|
|
8
|
+
|
|
9
|
+
| Step | What it does |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| Name resolution | Fixes a tool name written without its server prefix or with different case when there is only one match. |
|
|
12
|
+
| Approval | A destructive tool, or a tool of an MCP server the user has not approved, does not run until the user confirms. |
|
|
13
|
+
| References | Replaces `{{step_<ref>.output.<path>}}` and `{{context.<name>}}` placeholders in the arguments with real values. An unresolved reference fails the action with a clear message. |
|
|
14
|
+
| Validation | Checks the arguments against the tool's schema. |
|
|
15
|
+
| Grounding | Rejects identifiers (ids, uuids, hashes) that appear in the arguments but not in the user's messages nor in any previous result. Models invent ids, and this stops a made-up id from reaching a real system. The same check is applied to the final answer. |
|
|
16
|
+
| Duplicates | An identical call that already failed with a non transient error is blocked, so the model changes its approach instead of repeating it. |
|
|
17
|
+
| Execution | Runs the tool and records the output, the error and the timing. |
|
|
18
|
+
| Notes | Adds a short harness note to errors that say not found, validation failed or ambiguous match, telling the model what to do next. |
|
|
19
|
+
| Offloading | Large outputs are saved in the workspace and the model gets a stub it can read from. |
|
|
20
|
+
|
|
21
|
+
## Native tools
|
|
22
|
+
|
|
23
|
+
The model always has these tools, next to the ones you register:
|
|
24
|
+
|
|
25
|
+
| Tool | What it does |
|
|
26
|
+
| --- | --- |
|
|
27
|
+
| `search_tools` | Finds tools by keyword. With `server` it lists the tools of one MCP server. |
|
|
28
|
+
| `read_context` | Reads a workspace item. Supports a `path` into structured content, paging and `find` to locate an entry inside a large result without reading the whole list. |
|
|
29
|
+
| `save_context` | Keeps a note in the task workspace. It can be referenced later as `{{context.<name>}}`. |
|
|
30
|
+
| `ask_user` | Pauses the task to ask the user a question. The answer comes back as the result of the action. |
|
|
31
|
+
| `respond` | Delivers the final answer and ends the task. |
|
|
32
|
+
|
|
33
|
+
## Workspace
|
|
34
|
+
|
|
35
|
+
Tool outputs can be huge. When an output is longer than a few thousand characters it is saved in the workspace of the task. In the next cycle the model sees only a stub with its name, an outline of its shape and a preview, and loads what it needs with `read_context`. Outputs beyond a larger limit are never placed in the prompt at all. Notes the model saves with `save_context` live in the same place.
|
|
36
|
+
|
|
37
|
+
Workspace items belong to a chat and a task, so they survive between runs of the same conversation.
|
|
38
|
+
|
|
39
|
+
## Tool discovery
|
|
40
|
+
|
|
41
|
+
When your agent has more than 15 local tools, the model gets a summary per source instead of the full catalog and finds tools with `search_tools`. Tools found this way are declared from the next cycle on.
|
|
42
|
+
|
|
43
|
+
MCP tools are always discovered this way. The model sees an index of the user's servers and searches or lists them on demand. See [MCP servers](mcp-servers.md#how-the-agent-uses-the-servers).
|
|
44
|
+
|
|
45
|
+
## Approvals
|
|
46
|
+
|
|
47
|
+
Two things make an action wait for the user:
|
|
48
|
+
|
|
49
|
+
- The tool is destructive.
|
|
50
|
+
- The tool belongs to an MCP server that was never approved, or whose tools changed in a way that needs review.
|
|
51
|
+
|
|
52
|
+
The harness pauses the task, writes the question with a skill, stores the pending actions and leaves the chat as `awaiting_user_confirmation`. On the next message, a second skill reads the answer. When the user confirms, the pending actions run. When they decline, the task is cancelled. When the answer is unclear, the question is asked again.
|
|
53
|
+
|
|
54
|
+
Approving an MCP server through the chat records the decision on behalf of the user for that version of the server's manifest. If the server changes between the question and the answer, the approval is not applied and the user is asked again.
|
|
55
|
+
|
|
56
|
+
## Autonomous runs
|
|
57
|
+
|
|
58
|
+
When a run is autonomous (`executionMode: 'autonomous'`, see [agent](agent.md#autonomous-mode)) the harness stands in for the user in one place and refuses to in the rest:
|
|
59
|
+
|
|
60
|
+
- Questions the model asks with `ask_user` go to a small evaluator skill. It sees the goal, the message that created the task, what the agent learned and its latest results. It answers only when that context settles the question and never grants permissions. Its answer reaches the model with a note that it is automatic, it is not stored as something the user said and it does not count as a source for identifiers, so an id it invents is still rejected by the grounding check.
|
|
61
|
+
- Approvals are never given automatically beyond what an interactive run already does. When something needs the user, the task is paused in the chat and resumes when the user answers.
|
|
62
|
+
|
|
63
|
+
## Language
|
|
64
|
+
|
|
65
|
+
The reasoning engine reports in every turn the language in which it talks to the user, and the harness keeps it in `chat.state.language`. It is what every skill receives as `detected_language`. The model keeps the language of the conversation, changes it only when the user explicitly asks for another one, and ignores the language of pasted text, documents and tool results. A value that is not a two letter code is discarded and the previous language stays.
|
|
66
|
+
|
|
67
|
+
## Limits
|
|
68
|
+
|
|
69
|
+
| Limit | Value |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| Loop iterations per run | `maxIterations`, 50 by default |
|
|
72
|
+
| Reasoning turns per task (`AgiLoop`) | 20 |
|
|
73
|
+
| Automatic answers per autonomous task | 3 |
|
|
74
|
+
| Tool calls per task (`AgiLoop`) | 40 |
|
|
75
|
+
| Message length | `maxInputLength`, 100000 characters by default |
|
|
76
|
+
|
|
77
|
+
When a task hits a limit the agent answers with what it achieved and says what it could not do.
|
|
78
|
+
|
|
79
|
+
## Observability
|
|
80
|
+
|
|
81
|
+
Every node, skill and guard writes a trace with its reasoning. Every turn of a task records the model, mode, skill and loop versions, cost and number of blocks. Every action keeps its arguments, output and error. Together they answer why an agent did what it did.
|