openloops 0.1.38 → 0.2.1
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 +60 -5
- package/dist/clients/index.d.ts +2 -2
- package/dist/clients/index.js +4 -4
- package/dist/clients/index.mjs +2 -2
- package/dist/clients/llm/index.d.ts +1 -0
- package/dist/{loops/plan-execute → clients/llm}/index.js +4 -4
- package/dist/clients/llm/index.mjs +1 -0
- package/dist/clients/{llm-client.d.ts → llm/llm-client.d.ts} +3 -14
- package/dist/clients/{llm-client.js → llm/llm-client.js} +14 -37
- package/dist/clients/{llm-client.mjs → llm/llm-client.mjs} +15 -38
- package/dist/clients/{llm-error.mjs → llm/llm-error.mjs} +1 -1
- package/dist/clients/{llm-types.d.ts → llm/llm-types.d.ts} +1 -1
- package/dist/clients/llm/model-resolution.d.ts +20 -0
- package/dist/clients/llm/model-resolution.js +83 -0
- package/dist/clients/llm/model-resolution.mjs +46 -0
- package/dist/clients/{pi-ai-adapter.mjs → llm/pi-ai-adapter.mjs} +1 -1
- package/dist/clients/serper/index.d.ts +1 -0
- package/dist/clients/serper/index.js +22 -0
- package/dist/clients/serper/index.mjs +1 -0
- package/dist/clients/{serper-client.js → serper/serper-client.js} +2 -2
- package/dist/clients/{serper-client.mjs → serper/serper-client.mjs} +3 -3
- package/dist/harness/agent-loop.d.ts +0 -1
- package/dist/harness/agent.d.ts +6 -1
- package/dist/harness/agent.js +21 -13
- package/dist/harness/agent.mjs +21 -13
- package/dist/harness/native-tools.d.ts +1 -1
- package/dist/{loops/shared → harness}/skills/approval-request.d.ts +1 -1
- package/dist/{loops/shared → harness}/skills/approval-request.js +1 -1
- package/dist/{loops/shared → harness}/skills/approval-request.mjs +2 -2
- package/dist/{loops/shared → harness}/skills/autonomous-answer.d.ts +1 -1
- package/dist/{loops/shared → harness}/skills/autonomous-answer.js +1 -1
- package/dist/{loops/shared → harness}/skills/autonomous-answer.mjs +2 -2
- package/dist/{loops/shared → harness}/skills/confirmation-gate.d.ts +1 -1
- package/dist/{loops/shared → harness}/skills/confirmation-gate.js +1 -1
- package/dist/{loops/shared → harness}/skills/confirmation-gate.mjs +2 -2
- package/dist/harness/skills/index.d.ts +4 -0
- package/dist/{loops/plan-execute → harness}/skills/index.js +8 -8
- package/dist/harness/skills/index.mjs +4 -0
- package/dist/{loops/shared → harness}/skills/mcp-change-review.d.ts +1 -1
- package/dist/{loops/shared → harness}/skills/mcp-change-review.js +1 -1
- package/dist/{loops/shared → harness}/skills/mcp-change-review.mjs +2 -2
- package/dist/harness/tool-catalog.d.ts +1 -1
- package/dist/loops/index.d.ts +0 -1
- package/dist/loops/index.js +0 -2
- package/dist/loops/index.mjs +0 -1
- package/dist/loops/shared/skills/index.d.ts +0 -4
- package/dist/loops/shared/skills/index.js +1 -9
- package/dist/loops/shared/skills/index.mjs +0 -4
- 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/dist/services/chats/entities/chat.entity.d.ts +0 -5
- package/dist/services/chats/entities/chat.entity.js +0 -10
- package/dist/services/chats/entities/chat.entity.mjs +0 -10
- package/dist/services/llmcalls/module.d.ts +4 -2
- package/dist/services/llmcalls/module.js +13 -6
- package/dist/services/llmcalls/module.mjs +11 -5
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.d.ts +14 -0
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.js +62 -0
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.mjs +33 -0
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.d.ts +14 -0
- package/dist/services/llmcalls/use-cases/{get-llm-usage.use-case.js → get-llm-usage-by-message.use-case.js} +18 -37
- package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.mjs +33 -0
- package/dist/services/llmcalls/utils/usage-totals.d.ts +20 -0
- package/dist/services/llmcalls/utils/usage-totals.js +31 -0
- package/dist/services/llmcalls/utils/usage-totals.mjs +29 -0
- package/dist/services/tasks/entities/agent-task.entity.d.ts +2 -24
- package/dist/services/tasks/entities/agent-task.entity.js +2 -75
- package/dist/services/tasks/entities/agent-task.entity.mjs +2 -75
- package/dist/services/users/entities/user-default-model.d.ts +11 -0
- package/dist/services/users/entities/user-default-model.js +42 -0
- package/dist/services/users/entities/user-default-model.mjs +19 -0
- package/dist/services/users/entities/user-preferences.d.ts +4 -1
- package/dist/services/users/entities/user-preferences.js +8 -3
- package/dist/services/users/entities/user-preferences.mjs +8 -3
- package/dist/services/users/use-cases/create-user.use-case.js +3 -1
- package/dist/services/users/use-cases/create-user.use-case.mjs +3 -1
- package/dist/services/users/use-cases/update-user.use-case.js +4 -1
- package/dist/services/users/use-cases/update-user.use-case.mjs +4 -1
- package/dist/services/users/utils/default-model.d.ts +6 -0
- package/dist/services/users/utils/default-model.js +38 -0
- package/dist/services/users/utils/default-model.mjs +15 -0
- package/dist/skills/call-modes.d.ts +1 -1
- package/dist/skills/skill.d.ts +1 -1
- package/dist/skills/skill.js +1 -1
- package/dist/skills/skill.mjs +1 -1
- package/dist/tools/core/web-search/web-search.tool.js +1 -1
- package/dist/tools/core/web-search/web-search.tool.mjs +1 -1
- package/docs/README.md +46 -0
- package/docs/agent.md +202 -0
- package/docs/agentic-jobs.md +207 -0
- package/docs/assets/harness-car.svg +79 -0
- package/docs/authentication.md +40 -0
- package/docs/chats.md +88 -0
- package/docs/configuration.md +83 -0
- package/docs/guardrails.md +71 -0
- package/docs/harness.md +92 -0
- package/docs/integration-guide.md +138 -0
- package/docs/llms.txt +35 -0
- package/docs/loops.md +136 -0
- package/docs/mcp-servers.md +148 -0
- package/docs/skills.md +104 -0
- package/docs/tools.md +90 -0
- package/docs/usage.md +91 -0
- package/docs/users.md +108 -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-fallback-model.ts +25 -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 +20 -0
- package/examples/usage/get-message-usage.ts +20 -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/set-default-model.ts +36 -0
- package/examples/users/update-user.ts +22 -0
- package/package.json +9 -5
- package/dist/loops/plan-execute/index.d.ts +0 -1
- package/dist/loops/plan-execute/index.mjs +0 -1
- package/dist/loops/plan-execute/loop.d.ts +0 -26
- package/dist/loops/plan-execute/loop.js +0 -267
- package/dist/loops/plan-execute/loop.mjs +0 -249
- package/dist/loops/plan-execute/skills/action-planner.d.ts +0 -35
- package/dist/loops/plan-execute/skills/action-planner.js +0 -71
- package/dist/loops/plan-execute/skills/action-planner.mjs +0 -48
- package/dist/loops/plan-execute/skills/final-responder.d.ts +0 -7
- package/dist/loops/plan-execute/skills/final-responder.js +0 -58
- package/dist/loops/plan-execute/skills/final-responder.mjs +0 -35
- package/dist/loops/plan-execute/skills/index.d.ts +0 -4
- package/dist/loops/plan-execute/skills/index.mjs +0 -4
- package/dist/loops/plan-execute/skills/state-observer.d.ts +0 -10
- package/dist/loops/plan-execute/skills/state-observer.js +0 -61
- package/dist/loops/plan-execute/skills/state-observer.mjs +0 -38
- package/dist/loops/plan-execute/skills/strategy-engine.d.ts +0 -11
- package/dist/loops/plan-execute/skills/strategy-engine.js +0 -61
- package/dist/loops/plan-execute/skills/strategy-engine.mjs +0 -38
- package/dist/services/llmcalls/use-cases/get-llm-usage.use-case.d.ts +0 -24
- package/dist/services/llmcalls/use-cases/get-llm-usage.use-case.mjs +0 -51
- package/dist/skills/skill-runner.d.ts +0 -30
- package/dist/skills/skill-runner.js +0 -121
- package/dist/skills/skill-runner.mjs +0 -92
- /package/dist/clients/{llm-error.d.ts → llm/llm-error.d.ts} +0 -0
- /package/dist/clients/{llm-error.js → llm/llm-error.js} +0 -0
- /package/dist/clients/{llm-types.js → llm/llm-types.js} +0 -0
- /package/dist/clients/{llm-types.mjs → llm/llm-types.mjs} +0 -0
- /package/dist/clients/{pi-ai-adapter.d.ts → llm/pi-ai-adapter.d.ts} +0 -0
- /package/dist/clients/{pi-ai-adapter.js → llm/pi-ai-adapter.js} +0 -0
- /package/dist/clients/{serper-client.d.ts → serper/serper-client.d.ts} +0 -0
package/dist/skills/skill.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "../chunk-CF3WOMB3.mjs";
|
|
2
2
|
import { container } from "tsyringe";
|
|
3
3
|
import { extractJSON } from "../common/helpers/index.js";
|
|
4
|
-
import { LLMClient } from "../clients/llm-client.js";
|
|
4
|
+
import { LLMClient } from "../clients/llm/llm-client.js";
|
|
5
5
|
import { Logger } from "../common/logger/index.js";
|
|
6
6
|
import { buildRuntimeContext } from "./runtime-context";
|
|
7
7
|
import { DEFAULT_SKILL_MODE, buildModeCall, readModeResponse } from "./call-modes";
|
|
@@ -22,7 +22,7 @@ __export(web_search_tool_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(web_search_tool_exports);
|
|
24
24
|
var import_tool = require("../../tool");
|
|
25
|
-
var import_serper_client = require("../../../clients/serper-client.js");
|
|
25
|
+
var import_serper_client = require("../../../clients/serper/serper-client.js");
|
|
26
26
|
const webSearchTool = new import_tool.Tool({
|
|
27
27
|
name: "web_search",
|
|
28
28
|
description: "Search on web",
|
|
@@ -2,7 +2,7 @@ import "../../../chunk-CF3WOMB3.mjs";
|
|
|
2
2
|
import { Tool } from "../../tool";
|
|
3
3
|
import {
|
|
4
4
|
SerperClient
|
|
5
|
-
} from "../../../clients/serper-client.js";
|
|
5
|
+
} from "../../../clients/serper/serper-client.js";
|
|
6
6
|
const webSearchTool = new Tool({
|
|
7
7
|
name: "web_search",
|
|
8
8
|
description: "Search on web",
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# openloops documentation
|
|
2
|
+
|
|
3
|
+
Start with the [README](../README.md) for what `openloops` is and how to run it. These pages go deeper, grouped by what you are trying to do.
|
|
4
|
+
|
|
5
|
+
## Start here
|
|
6
|
+
|
|
7
|
+
| Page | What it covers |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| [Integration guide](integration-guide.md) | What to write in a backend: which endpoint calls what, the authorization you own and a security checklist. |
|
|
10
|
+
|
|
11
|
+
## Run an agent
|
|
12
|
+
|
|
13
|
+
| Page | What it covers |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| [The `Agent`](agent.md) | Options, running a turn, the result and its statuses, confirmations, autonomous mode, hooks and interruption. |
|
|
16
|
+
| [Configuration](configuration.md) | Environment variables, choosing the model and what is recorded. |
|
|
17
|
+
| [Agentic jobs](agentic-jobs.md) | Tasks that the agent runs by itself on a schedule: recurrence, the history of runs and the runner that executes them. |
|
|
18
|
+
| [Chats](chats.md) | The chat record, its messages and their `source`, listing, reading and deleting chats. |
|
|
19
|
+
|
|
20
|
+
## Shape how the agent works
|
|
21
|
+
|
|
22
|
+
| Page | What it covers |
|
|
23
|
+
| --- | --- |
|
|
24
|
+
| [Building an `AgentLoop`](loops.md) | `AgiLoop`, the contract of a loop, `RunContext`, `Harness` and tasks. |
|
|
25
|
+
| [Skills](skills.md) | Writing and running LLM-backed reasoning steps and their call modes. |
|
|
26
|
+
| [Tools](tools.md) | Writing tools, validation, built-in tools and how MCP tools differ. |
|
|
27
|
+
| [Guardrails](guardrails.md) | Blocking input before the model sees it, ready-made guards and writing your own. |
|
|
28
|
+
| [The harness](harness.md) | The tool pipeline, native tools, the workspace, discovery, approvals, language and limits. |
|
|
29
|
+
|
|
30
|
+
## Connect to the outside world
|
|
31
|
+
|
|
32
|
+
| Page | What it covers |
|
|
33
|
+
| --- | --- |
|
|
34
|
+
| [MCP servers](mcp-servers.md) | Registering servers, the trust flow, approving and blocking, and how the agent uses them. |
|
|
35
|
+
|
|
36
|
+
## Users and cost
|
|
37
|
+
|
|
38
|
+
| Page | What it covers |
|
|
39
|
+
| --- | --- |
|
|
40
|
+
| [User management](users.md) | `CurrentUser`, creating, listing, updating and deleting users. |
|
|
41
|
+
| [Authentication](authentication.md) | Login and tokens. |
|
|
42
|
+
| [LLM usage tracking](usage.md) | Tokens and cost per chat or answer, and per-user statistics. |
|
|
43
|
+
|
|
44
|
+
## Examples
|
|
45
|
+
|
|
46
|
+
Runnable examples for every page live in [`examples/`](../examples), organized by domain.
|
package/docs/agent.md
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# The `Agent`
|
|
2
|
+
|
|
3
|
+
`Agent` is the entry point of the [harness](harness.md), and it drives an `AgentLoop`. It owns everything a loop shouldn't have to think about: loading and saving the chat, dispatching to the right node, running guardrails, resolving tools (native and MCP), asking for confirmation, handling interruption requests, and tracking usage.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import { Agent } from 'openloops/core'
|
|
7
|
+
import { AgiLoop } from 'openloops/loops'
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Creating an agent
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
const agent = new Agent({
|
|
14
|
+
loop: new AgiLoop(),
|
|
15
|
+
tools: [],
|
|
16
|
+
guards: [],
|
|
17
|
+
identity: {
|
|
18
|
+
name: 'Sofi',
|
|
19
|
+
gender: 'Female',
|
|
20
|
+
role: 'Personal assistant and daily companion',
|
|
21
|
+
},
|
|
22
|
+
maxInputLength: 100_000,
|
|
23
|
+
maxIterations: 50,
|
|
24
|
+
strictMode: false,
|
|
25
|
+
})
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
| Option | Required | Default | What it does |
|
|
29
|
+
| --- | --- | --- | --- |
|
|
30
|
+
| `loop` | yes | none | An instance of a class extending `AgentLoop`. Use `AgiLoop` unless you wrote your own. See [loops](loops.md). |
|
|
31
|
+
| `tools` | no | `[]` | Extra native `Tool` instances. See [tools](tools.md). |
|
|
32
|
+
| `guards` | no | `[]` | Input guards that run before the model sees a message. See [guardrails](guardrails.md). |
|
|
33
|
+
| `identity` | no | none | Name, gender and role injected into every skill. |
|
|
34
|
+
| `maxInputLength` | no | `100000` | Longest message accepted, in characters. Longer messages are blocked by a built-in guard. |
|
|
35
|
+
| `maxIterations` | no | `50` | Hard limit of loop iterations in one run. When reached, the run fails with `AGENT_MAX_ITERATIONS_REACHED`. |
|
|
36
|
+
| `fallbackModel` | no | none | `{ provider, model }` used when neither the run, the chat nor the user chose a model. See [configuration](configuration.md#which-model-a-chat-uses). |
|
|
37
|
+
| `strictMode` | no | `false` | When `true`, the user is always asked before the agent uses an MCP server whose tools changed after being approved. See [MCP servers](mcp-servers.md#how-the-agent-uses-the-servers). |
|
|
38
|
+
|
|
39
|
+
An `Agent` instance holds the state of the run it is executing, so run one conversation at a time per instance and create another instance for concurrent runs.
|
|
40
|
+
|
|
41
|
+
## Running a turn
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
const result = await agent.run({
|
|
45
|
+
input: {
|
|
46
|
+
message: 'hi, how are you?',
|
|
47
|
+
chatId: undefined,
|
|
48
|
+
},
|
|
49
|
+
options: {
|
|
50
|
+
notifyOnCompletion: true,
|
|
51
|
+
modelProvider: 'anthropic',
|
|
52
|
+
modelName: 'claude-haiku-5-5',
|
|
53
|
+
},
|
|
54
|
+
currentUser,
|
|
55
|
+
currentSession,
|
|
56
|
+
})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Omit `chatId` to start a brand-new chat. Pass an existing `chatId` to continue a conversation: `openloops` loads it, appends the new message, and resumes the loop exactly where it left off, including mid-confirmation or mid-question.
|
|
60
|
+
|
|
61
|
+
`options` are stored in the chat settings, so they stick for the following turns of that chat:
|
|
62
|
+
|
|
63
|
+
| Option | What it does |
|
|
64
|
+
| --- | --- |
|
|
65
|
+
| `modelProvider`, `modelName` | Model for this run, always together. It is saved in the chat and used by the next runs that do not send one. Without it, the model comes from the chat, the preference of the user and the fallbacks. See [configuration](configuration.md#which-model-a-chat-uses). |
|
|
66
|
+
| `loopName` | Name of the loop driving the chat. Set automatically from the loop. |
|
|
67
|
+
| `executionMode` | `interactive` (default) or `autonomous`. See [Autonomous mode](#autonomous-mode). |
|
|
68
|
+
| `notifyOnCompletion` | Exposed as `agent.notifyOnCompletion` so a post execution hook can notify the user. |
|
|
69
|
+
| `isPrivateSession` | Stored in the chat settings for your application to use. |
|
|
70
|
+
|
|
71
|
+
`currentSession` is optional. It carries device, location and locale, which skills use to answer in the right time zone and language.
|
|
72
|
+
|
|
73
|
+
## Autonomous mode
|
|
74
|
+
|
|
75
|
+
An autonomous run is one where nobody is in the chat while the agent works, for example a scheduled task. Pass the mode in the run:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
await agent.run({
|
|
79
|
+
input: { message: 'Every morning, summarize my open tickets' },
|
|
80
|
+
options: { executionMode: 'autonomous' },
|
|
81
|
+
currentUser,
|
|
82
|
+
})
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`currentUser` is still required: it owns the chat and the MCP servers. What changes while a run is autonomous:
|
|
86
|
+
|
|
87
|
+
- The model is told that nobody is present, so it plans the whole task and writes a complete final answer.
|
|
88
|
+
- Questions the model sends with `ask_user` are answered by an automatic evaluator, a skill that only knows the context of the task. The model receives the answer marked as automatic and is told to use its judgment. The evaluator never grants permissions and says it cannot decide when the context does not settle the question. At most 3 questions per task are answered this way.
|
|
89
|
+
- Whatever needs the user (a destructive tool, an MCP server that was not approved or that changed in a way that needs review, a question the evaluator cannot answer) pauses the run. The chat stays in `awaiting_user_confirmation` or `awaiting_user_input` with the question as its last message. The user opens the chat and answers, and the task continues where it stopped.
|
|
90
|
+
- Small changes in an approved MCP server are still approved by the review skill, as in an interactive run. A server used for the first time, or any change with `strictMode: true`, always pauses the run.
|
|
91
|
+
|
|
92
|
+
The mode is saved in `chat.settings.executionMode` when the chat is created and is not changed later. Each run takes its mode only from its own `executionMode` option and is interactive when it is not given, so a user who continues an autonomous chat by hand is working interactively and the chat is still listed as autonomous. See [chats](chats.md#listing-a-users-chats).
|
|
93
|
+
|
|
94
|
+
- The first step of the loop, the one that answers conversation directly, is skipped: the task goes straight to the reasoning engine.
|
|
95
|
+
- Each question of the model and its automatic answer are saved in the chat history so the user can see them later, marked with `source` and excluded from the context of the model.
|
|
96
|
+
|
|
97
|
+
Only `AgiLoop` supports autonomous mode.
|
|
98
|
+
|
|
99
|
+
To run an agent on a schedule, see [agentic jobs](agentic-jobs.md).
|
|
100
|
+
|
|
101
|
+
## The result
|
|
102
|
+
|
|
103
|
+
`agent.run` does not throw for failures inside the run. It returns:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
const { data, error } = await agent.run({ input, currentUser })
|
|
107
|
+
|
|
108
|
+
data?.lastAnswer
|
|
109
|
+
data?.messages
|
|
110
|
+
data?.tasks
|
|
111
|
+
data?.state?.status
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
- `data` is the `Chat` after the turn, or `undefined` if the chat could not even be created.
|
|
115
|
+
- `error` is a message you can show to the user, present only when the run failed. The chat is marked as `failed` and saved.
|
|
116
|
+
|
|
117
|
+
`data.state.status` tells you where the conversation is:
|
|
118
|
+
|
|
119
|
+
| Status | Meaning |
|
|
120
|
+
| --- | --- |
|
|
121
|
+
| `idle` | The task finished and the agent is ready for a new request. |
|
|
122
|
+
| `processing` | A run is in progress. |
|
|
123
|
+
| `awaiting_user_input` | The agent asked a question. Send the answer as the next message. |
|
|
124
|
+
| `awaiting_user_confirmation` | The agent asked the user to approve an action. Send the answer as the next message. |
|
|
125
|
+
| `failed` | The run failed. `data.state.lastError` has the code and message. |
|
|
126
|
+
|
|
127
|
+
## Confirmations
|
|
128
|
+
|
|
129
|
+
When the loop is about to run a tool that is destructive, or a tool from an MCP server the user has not approved yet, the agent stops, asks the user in the chat and leaves the status as `awaiting_user_confirmation`. The user's next message is read by the `confirmation_gate` skill:
|
|
130
|
+
|
|
131
|
+
- A yes runs the pending actions. For an MCP server, the harness records the approval on behalf of the user.
|
|
132
|
+
- A no cancels the task. For an MCP server, it is blocked.
|
|
133
|
+
- An unclear answer makes the agent ask again.
|
|
134
|
+
|
|
135
|
+
You do not implement any of this. See [harness](harness.md#approvals).
|
|
136
|
+
|
|
137
|
+
## Identity
|
|
138
|
+
|
|
139
|
+
Pass `identity` once when constructing the `Agent` and it is injected into every skill's context. This is how you reskin an agent (name, personality framing) without touching a single line of loop or skill code.
|
|
140
|
+
|
|
141
|
+
## Tools
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
agent.addTool(myCustomTool)
|
|
145
|
+
agent.tools
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Tools you add are available for the whole run, next to the tools of the user's MCP servers. `agent.tools` also includes the MCP tools that have been loaded so far in the current run. See [tools](tools.md) and [MCP servers](mcp-servers.md).
|
|
149
|
+
|
|
150
|
+
## MCP servers
|
|
151
|
+
|
|
152
|
+
You never call anything MCP-related on `Agent`. At the start of a turn the agent looks up the user's registered servers and shows them to the model as an index (name, description, state). It connects to a server only when the model asks for its tools, checks that its manifest is the one the user approved, and disconnects every session at the end of the turn, including when the turn fails.
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
agent.mcps
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
`agent.mcps` is the list of `McpServer` entities known during the current turn. See [MCP servers](mcp-servers.md).
|
|
159
|
+
|
|
160
|
+
## Guardrails
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
import { inputGuards } from 'openloops/guardrails'
|
|
164
|
+
|
|
165
|
+
agent.addGuard(inputGuards.blockCard)
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Guards run on the user message before any model call. See [guardrails](guardrails.md).
|
|
169
|
+
|
|
170
|
+
## Hooks
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
agent.addHook('pre_execution', () => {
|
|
174
|
+
// runs once, right before the loop starts
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
agent.addHook('post_execution', async () => {
|
|
178
|
+
if (agent.notifyOnCompletion) {
|
|
179
|
+
// send a push notification, etc.
|
|
180
|
+
}
|
|
181
|
+
})
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Hooks do not run when a guard blocks the message, because the loop never starts.
|
|
185
|
+
|
|
186
|
+
## Stopping a running turn
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
await Agent.interruptExecution(chatId, currentUser)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Call it from a separate request while `agent.run()` is still executing, for example when the user presses stop. The running loop checks for the request before every node and stops cleanly. The next message in that chat starts again from the initial node of the loop.
|
|
193
|
+
|
|
194
|
+
`agent.stopAgent()` stops the loop of the same instance from your own code.
|
|
195
|
+
|
|
196
|
+
## What gets stored
|
|
197
|
+
|
|
198
|
+
For every chat, `openloops` persists the chat and its messages, the tasks, every action (tool call) with its result, the traces of each node and skill, and the workspace items that hold large tool outputs and notes. Every LLM call is recorded with its cost, see [usage](usage.md).
|
|
199
|
+
|
|
200
|
+
## Error handling
|
|
201
|
+
|
|
202
|
+
If a turn fails for any reason, `Agent` marks the chat as failed, saves it, closes any open MCP session and returns the error in `result.error`. LLM failures such as rate limits, exhausted quota or a model that does not answer in time (`LLM_TIMEOUT`) carry a user-facing message and a retryable flag in `data.state.lastError`.
|
|
@@ -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 of the owner is used, then the fallbacks. See [configuration](configuration.md#which-model-a-chat-uses). |
|
|
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,79 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 560 310" width="560" height="310" role="img" aria-labelledby="t d">
|
|
2
|
+
<title id="t">The openloops harness</title>
|
|
3
|
+
<desc id="d">A car made of an engine (the AI model), a chassis (the harness) and a body (the loop). The body changes while the engine and the chassis stay the same: a different body, a different agent.</desc>
|
|
4
|
+
<style>
|
|
5
|
+
.mono{font-family:ui-monospace, SFMono-Regular, Menlo, Consolas, monospace}
|
|
6
|
+
.body,.role{opacity:0;animation:cycle 12.8s infinite both;transform-box:fill-box}
|
|
7
|
+
.b0{opacity:1}
|
|
8
|
+
@keyframes cycle{0%{opacity:0;transform:translateY(-14px)}1.5%{opacity:1;transform:translateY(0)}23.5%{opacity:1;transform:translateY(0)}25%{opacity:0;transform:translateY(-10px)}100%{opacity:0}}
|
|
9
|
+
.spin{animation:spin 1.1s linear infinite;transform-origin:0 0}
|
|
10
|
+
@keyframes spin{to{transform:rotate(360deg)}}
|
|
11
|
+
.motor{animation:motor .8s ease-in-out infinite}
|
|
12
|
+
@keyframes motor{0%,100%{opacity:1}50%{opacity:.6}}
|
|
13
|
+
.node{animation:node 1.2s ease-in-out infinite}
|
|
14
|
+
@keyframes node{0%,100%{opacity:.35}50%{opacity:1}}
|
|
15
|
+
@media (prefers-reduced-motion:reduce){.body,.role,.spin,.motor,.node{animation:none}.node{opacity:1}}
|
|
16
|
+
</style>
|
|
17
|
+
<defs><pattern id="grid" width="20" height="20" patternUnits="userSpaceOnUse"><path d="M 20 0 L 0 0 0 20" fill="none" stroke="#ffffff" stroke-opacity="0.05"/></pattern></defs>
|
|
18
|
+
<rect x="0.5" y="0.5" width="559" height="309" rx="16" fill="#0d1016" stroke="#ffffff" stroke-opacity="0.12"/>
|
|
19
|
+
<rect x="1" y="1" width="558" height="308" rx="15" fill="url(#grid)"/>
|
|
20
|
+
<line x1="30" y1="218" x2="530" y2="218" stroke="#64748b" stroke-width="1" stroke-dasharray="6 8"/>
|
|
21
|
+
<g class="body b0" style="animation-delay:0s">
|
|
22
|
+
<path d="M 90 150 L 90 128 Q 90 118 104 116 L 190 110 L 225 82 Q 232 76 244 76 L 330 76 Q 342 76 350 84 L 378 110 L 462 118 Q 478 120 478 134 L 478 150 Z" fill="#cbd5e1" fill-opacity="0.04" stroke="#cbd5e1" stroke-width="1.75" stroke-linejoin="round"/>
|
|
23
|
+
<path d="M 232 84 L 292 84 L 292 108 L 205 108 Z M 300 84 L 336 84 L 366 108 L 300 108 Z" fill="#cbd5e1" fill-opacity="0.08" stroke="#cbd5e1" stroke-width="1" stroke-linejoin="round"/>
|
|
24
|
+
<line x1="290" y1="62" x2="290" y2="72" stroke="#64748b" stroke-width="1" stroke-dasharray="3 3"/>
|
|
25
|
+
<text class="mono" x="290" y="54" text-anchor="middle" font-size="11" letter-spacing="1.2" fill="#cbd5e1">BODY<tspan fill="#94a3b8"> (</tspan><tspan fill="#f8fafc">LOOP</tspan><tspan fill="#94a3b8">)</tspan></text>
|
|
26
|
+
</g>
|
|
27
|
+
<g class="body b1" style="animation-delay:3.2s">
|
|
28
|
+
<path d="M 90 150 L 90 132 Q 90 124 102 122 L 200 116 Q 240 84 290 84 L 330 84 Q 350 86 362 104 L 372 114 L 462 124 Q 480 128 480 138 L 480 150 Z" fill="#cbd5e1" fill-opacity="0.04" stroke="#cbd5e1" stroke-width="1.75" stroke-linejoin="round"/>
|
|
29
|
+
<path d="M 232 112 Q 258 92 290 92 L 330 92 Q 342 94 350 110 Z" fill="#cbd5e1" fill-opacity="0.08" stroke="#cbd5e1" stroke-width="1" stroke-linejoin="round"/>
|
|
30
|
+
<line x1="290" y1="62" x2="290" y2="80" stroke="#64748b" stroke-width="1" stroke-dasharray="3 3"/>
|
|
31
|
+
<text class="mono" x="290" y="54" text-anchor="middle" font-size="11" letter-spacing="1.2" fill="#cbd5e1">BODY<tspan fill="#94a3b8"> (</tspan><tspan fill="#f8fafc">LOOP</tspan><tspan fill="#94a3b8">)</tspan></text>
|
|
32
|
+
</g>
|
|
33
|
+
<g class="body b2" style="animation-delay:6.4s">
|
|
34
|
+
<path d="M 90 150 L 90 100 Q 90 84 106 84 L 340 84 Q 352 84 358 96 L 380 118 L 462 124 Q 478 126 478 140 L 478 150 Z" fill="#cbd5e1" fill-opacity="0.04" stroke="#cbd5e1" stroke-width="1.75" stroke-linejoin="round"/>
|
|
35
|
+
<path d="M 110 96 L 166 96 L 166 124 L 110 124 Z M 176 96 L 232 96 L 232 124 L 176 124 Z M 242 96 L 298 96 L 298 124 L 242 124 Z M 308 96 L 342 96 L 366 118 L 308 118 Z" fill="#cbd5e1" fill-opacity="0.08" stroke="#cbd5e1" stroke-width="1" stroke-linejoin="round"/>
|
|
36
|
+
<line x1="240" y1="62" x2="240" y2="80" stroke="#64748b" stroke-width="1" stroke-dasharray="3 3"/>
|
|
37
|
+
<text class="mono" x="240" y="54" text-anchor="middle" font-size="11" letter-spacing="1.2" fill="#cbd5e1">BODY<tspan fill="#94a3b8"> (</tspan><tspan fill="#f8fafc">LOOP</tspan><tspan fill="#94a3b8">)</tspan></text>
|
|
38
|
+
</g>
|
|
39
|
+
<g class="body b3" style="animation-delay:9.6s">
|
|
40
|
+
<path d="M 290 150 L 290 100 Q 292 84 308 82 L 352 82 Q 364 82 370 92 L 384 114 L 462 120 Q 478 122 478 136 L 478 150 Z M 90 150 L 90 110 L 100 110 L 104 140 L 270 140 L 274 110 L 284 110 L 284 150 Z" fill="#cbd5e1" fill-opacity="0.04" stroke="#cbd5e1" stroke-width="1.75" stroke-linejoin="round"/>
|
|
41
|
+
<path d="M 302 92 L 348 92 L 372 114 L 302 114 Z" fill="#cbd5e1" fill-opacity="0.08" stroke="#cbd5e1" stroke-width="1" stroke-linejoin="round"/>
|
|
42
|
+
<line x1="330" y1="62" x2="330" y2="78" stroke="#64748b" stroke-width="1" stroke-dasharray="3 3"/>
|
|
43
|
+
<text class="mono" x="330" y="54" text-anchor="middle" font-size="11" letter-spacing="1.2" fill="#cbd5e1">BODY<tspan fill="#94a3b8"> (</tspan><tspan fill="#f8fafc">LOOP</tspan><tspan fill="#94a3b8">)</tspan></text>
|
|
44
|
+
</g>
|
|
45
|
+
<g>
|
|
46
|
+
<rect class="motor" x="394" y="122" width="66" height="26" rx="4" fill="#ffffff" fill-opacity="0.06" stroke="#cbd5e1" stroke-width="1.5"/>
|
|
47
|
+
<line x1="410" y1="128" x2="410" y2="142" stroke="#cbd5e1" stroke-opacity="0.45" stroke-width="3" stroke-linecap="round"/>
|
|
48
|
+
<line x1="426" y1="128" x2="426" y2="142" stroke="#cbd5e1" stroke-opacity="0.45" stroke-width="3" stroke-linecap="round"/>
|
|
49
|
+
<line x1="442" y1="128" x2="442" y2="142" stroke="#cbd5e1" stroke-opacity="0.45" stroke-width="3" stroke-linecap="round"/>
|
|
50
|
+
<line x1="427" y1="108" x2="427" y2="120" stroke="#64748b" stroke-width="1" stroke-dasharray="3 3"/>
|
|
51
|
+
<text class="mono" x="445" y="100" text-anchor="middle" font-size="11" letter-spacing="1.2" fill="#cbd5e1">ENGINE<tspan fill="#94a3b8"> (</tspan><tspan fill="#f8fafc">AI MODEL</tspan><tspan fill="#94a3b8">)</tspan></text>
|
|
52
|
+
</g>
|
|
53
|
+
<g><rect x="80" y="150" width="400" height="18" rx="9" fill="#C06CF0" fill-opacity="0.2" stroke="#C06CF0" stroke-width="2"/>
|
|
54
|
+
<circle class="node" cx="170" cy="159" r="4" fill="#C06CF0" style="animation-delay:0s"/>
|
|
55
|
+
<circle class="node" cx="235" cy="159" r="4" fill="#C06CF0" style="animation-delay:0.25s"/>
|
|
56
|
+
<circle class="node" cx="300" cy="159" r="4" fill="#C06CF0" style="animation-delay:0.5s"/>
|
|
57
|
+
<circle class="node" cx="365" cy="159" r="4" fill="#C06CF0" style="animation-delay:0.75s"/>
|
|
58
|
+
<g transform="translate(150 190)"><circle r="28" fill="#0B0E14" stroke="#cbd5e1" stroke-width="2.5"/><g class="spin">
|
|
59
|
+
<line x1="0" y1="-8" x2="0" y2="-20" stroke="#64748b" stroke-width="2" transform="rotate(0)"/>
|
|
60
|
+
<line x1="0" y1="-8" x2="0" y2="-20" stroke="#64748b" stroke-width="2" transform="rotate(72)"/>
|
|
61
|
+
<line x1="0" y1="-8" x2="0" y2="-20" stroke="#64748b" stroke-width="2" transform="rotate(144)"/>
|
|
62
|
+
<line x1="0" y1="-8" x2="0" y2="-20" stroke="#64748b" stroke-width="2" transform="rotate(216)"/>
|
|
63
|
+
<line x1="0" y1="-8" x2="0" y2="-20" stroke="#64748b" stroke-width="2" transform="rotate(288)"/>
|
|
64
|
+
</g><circle r="8" fill="#0B0E14" stroke="#cbd5e1" stroke-width="1.5"/></g>
|
|
65
|
+
<g transform="translate(410 190)"><circle r="28" fill="#0B0E14" stroke="#cbd5e1" stroke-width="2.5"/><g class="spin">
|
|
66
|
+
<line x1="0" y1="-8" x2="0" y2="-20" stroke="#64748b" stroke-width="2" transform="rotate(0)"/>
|
|
67
|
+
<line x1="0" y1="-8" x2="0" y2="-20" stroke="#64748b" stroke-width="2" transform="rotate(72)"/>
|
|
68
|
+
<line x1="0" y1="-8" x2="0" y2="-20" stroke="#64748b" stroke-width="2" transform="rotate(144)"/>
|
|
69
|
+
<line x1="0" y1="-8" x2="0" y2="-20" stroke="#64748b" stroke-width="2" transform="rotate(216)"/>
|
|
70
|
+
<line x1="0" y1="-8" x2="0" y2="-20" stroke="#64748b" stroke-width="2" transform="rotate(288)"/>
|
|
71
|
+
</g><circle r="8" fill="#0B0E14" stroke="#cbd5e1" stroke-width="1.5"/></g>
|
|
72
|
+
<line x1="280" y1="172" x2="280" y2="232" stroke="#64748b" stroke-width="1" stroke-dasharray="3 3"/>
|
|
73
|
+
<text class="mono" x="280" y="248" text-anchor="middle" font-size="11" letter-spacing="1.2" font-weight="700" fill="#C06CF0">CHASSIS<tspan fill="#94a3b8"> (</tspan><tspan fill="#e9d5ff">HARNESS</tspan><tspan fill="#94a3b8">)</tspan></text></g>
|
|
74
|
+
<text class="mono role b0" x="280" y="278" text-anchor="middle" font-size="13" fill="#f8fafc" style="animation-delay:0s">Personal assistant</text>
|
|
75
|
+
<text class="mono role b1" x="280" y="278" text-anchor="middle" font-size="13" fill="#f8fafc" style="animation-delay:3.2s">Analyst</text>
|
|
76
|
+
<text class="mono role b2" x="280" y="278" text-anchor="middle" font-size="13" fill="#f8fafc" style="animation-delay:6.4s">Customer support</text>
|
|
77
|
+
<text class="mono role b3" x="280" y="278" text-anchor="middle" font-size="13" fill="#f8fafc" style="animation-delay:9.6s">Programmer</text>
|
|
78
|
+
<text class="mono" x="280" y="298" text-anchor="middle" font-size="11" fill="#94a3b8">Same engine. Same chassis. A different body, a different agent.</text>
|
|
79
|
+
</svg>
|
|
@@ -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).
|