openloops 0.1.39 → 0.2.2
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 +40 -4
- 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/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 +1 -1
- package/docs/agent.md +4 -3
- package/docs/agentic-jobs.md +1 -1
- package/docs/assets/harness-car.svg +79 -0
- package/docs/chats.md +1 -1
- package/docs/configuration.md +18 -4
- package/docs/harness.md +12 -1
- package/docs/integration-guide.md +2 -2
- package/docs/llms.txt +1 -1
- package/docs/loops.md +4 -15
- package/docs/usage.md +19 -14
- package/docs/users.md +23 -0
- package/examples/run-agent/run-agent-with-fallback-model.ts +25 -0
- package/examples/usage/get-chat-usage.ts +8 -10
- package/examples/usage/get-message-usage.ts +5 -7
- package/examples/users/set-default-model.ts +36 -0
- package/package.json +1 -16
- 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/README.md
CHANGED
|
@@ -2,16 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
**Build production-grade enterprise agents in minutes, not days, weeks, or months.**
|
|
4
4
|
|
|
5
|
+
`openloops` is an open source **harness** for AI agents. An agent is three things: a **model** that thinks (the engine), a **harness** that gives it hands, memory and rules (the chassis), and a **loop** that decides what it is for (the body). `openloops` is the harness, and it ships the loop. Change the model, or the loop, and the rest stays the same.
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<img src="https://raw.githubusercontent.com/jbarcosdev/openloops/main/docs/assets/harness-car.svg" alt="A car made of an engine (the AI model), a chassis (the harness) and a body (the loop). The body changes between a personal assistant, an analyst, customer support and a programmer, while the engine and the chassis stay the same." width="560">
|
|
9
|
+
</p>
|
|
10
|
+
|
|
5
11
|
```typescript
|
|
6
12
|
import { Agent } from 'openloops/core'
|
|
7
13
|
import { Logger } from 'openloops/common'
|
|
8
14
|
import { CurrentUser } from 'openloops/base'
|
|
9
15
|
import { AgiLoop } from 'openloops/loops'
|
|
16
|
+
import { webSearchTool } from 'openloops/tools'
|
|
10
17
|
|
|
11
18
|
const logger = new Logger()
|
|
12
19
|
const currentUser = await CurrentUser.asyncFromDB(userId)
|
|
13
20
|
const agent = new Agent({ loop: new AgiLoop() })
|
|
14
21
|
|
|
22
|
+
agent.addTool(webSearchTool) // needs SERPER_API_KEY, see "Web search" below
|
|
23
|
+
|
|
15
24
|
const result = await agent.run({
|
|
16
25
|
input: { message: 'what is the current price of Bitcoin?' },
|
|
17
26
|
currentUser,
|
|
@@ -22,6 +31,29 @@ logger.info(result.data.lastAnswer, '[Demo] Result')
|
|
|
22
31
|
|
|
23
32
|
That's it. The agent is persisted, resumable, and scoped to that one user, with tool execution, guardrails, and observability already wired in. No message table to design, no state machine to debug by hand, no MCP adapter to write.
|
|
24
33
|
|
|
34
|
+
## What the harness gives your agent
|
|
35
|
+
|
|
36
|
+
A model alone only chats. The harness is what lets it act, safely, for many users:
|
|
37
|
+
|
|
38
|
+
| Part | What it does | In `openloops` |
|
|
39
|
+
| --- | --- | --- |
|
|
40
|
+
| **Transmission** | Takes the model to the outside world | Your tools and MCP servers, found on demand and validated before they run. See [tools](docs/tools.md) and [MCP servers](docs/mcp-servers.md) |
|
|
41
|
+
| **Brakes** | Stops the agent when it should stop | Confirmation of destructive tools, approval of MCP servers, input guardrails, timeouts and a budget per task. See [guardrails](docs/guardrails.md) and [the harness](docs/harness.md) |
|
|
42
|
+
| **Logbook** | Remembers and records everything | Chats, tasks, every tool call, traces, and usage and cost per call. See [chats](docs/chats.md) and [usage](docs/usage.md) |
|
|
43
|
+
| **Steering** | Decides how the agent is driven | Interactive and autonomous runs, scheduled jobs, stopping a run, and the model per chat and per user. See [the Agent](docs/agent.md), [agentic jobs](docs/agentic-jobs.md) and [configuration](docs/configuration.md) |
|
|
44
|
+
|
|
45
|
+
## Why it is a good harness
|
|
46
|
+
|
|
47
|
+
Not adjectives, mechanisms that you can read in the code and in the tests:
|
|
48
|
+
|
|
49
|
+
- **It rejects what the model invents.** An identifier that is not in the messages of the user or in a previous result never reaches a real system, and the same check applies to the final answer.
|
|
50
|
+
- **It does not let the model loop.** An identical call that already completed or failed is blocked, so the agent changes its approach.
|
|
51
|
+
- **It keeps the prompt small.** Large tool outputs go to a workspace and the model reads them on demand.
|
|
52
|
+
- **It keeps the prompt stable**, so the provider's cache is used. With the default model, about 70% of the prompt tokens were read from the cache in the project's evals. See [configuration](docs/configuration.md#which-model-a-chat-uses).
|
|
53
|
+
- **Nobody changes what your agent does in silence.** An MCP server must be approved before its first tool runs, and a change in its tools is reviewed again.
|
|
54
|
+
- **A call that never answers does not block a run.** It is cancelled and repeated, and a tool call that may have changed something is never repeated by itself.
|
|
55
|
+
- **It is measured.** The `evals/` folder compares models, call modes and the prompts of the skills with the same cases.
|
|
56
|
+
|
|
25
57
|
## Building a backend with it
|
|
26
58
|
|
|
27
59
|
If you or your coding agent are going to build the backend that uses `openloops`, start with the [integration guide](docs/integration-guide.md). It lists which endpoint calls which use case, what authorization is left to you (the package has no HTTP layer), how to run agents and scheduled jobs, and a security checklist. The whole documentation is also shipped inside the package, in `node_modules/openloops/docs`, with an index for tools in [`docs/llms.txt`](docs/llms.txt).
|
|
@@ -135,7 +167,7 @@ This is a comparison against the self-hosted, open-source versions of LangGraph
|
|
|
135
167
|
|---|---|---|---|
|
|
136
168
|
| Persistence | Built in, zero config (MongoDB) | You choose and configure a checkpointer: in-memory, SQLite or Postgres, the last two in separate packages | Memory is opt-in and stored as local files (ChromaDB and SQLite, or LanceDB in newer versions), tied to the machine |
|
|
137
169
|
| Multi-user scoping | Built in: chats, tasks, context, and MCP servers are per-user from the start | Conversations are scoped by a `thread_id`. Mapping them to users, and scoping memory and tools per user, is up to you | Not a concept of the framework, you build it |
|
|
138
|
-
| Tool execution & retries | Validation, confirmation of destructive tools, duplicate and invented-id protection, and LLM and MCP connection retries are built into the
|
|
170
|
+
| Tool execution & retries | Validation, confirmation of destructive tools, duplicate and invented-id protection, and LLM and MCP connection retries are built into the harness. A failed step goes back to the model, which decides how to continue | Per-node `RetryPolicy` and error handling that you configure | Retry limits are configured per agent or task |
|
|
139
171
|
| MCP support | Native: servers are a per-user record, tools load on demand, and every server goes through an approval flow | A separate package (`langchain-mcp-adapters`) with a client that you wire into the graph | Native `mcps` field on agents, or `MCPServerAdapter`. Servers are declared in code, not loaded per user |
|
|
140
172
|
| User management | Included (`openloops/users`, `openloops/authentication`) | Not included, you build your own | Not included, you build your own |
|
|
141
173
|
| LLM usage/cost tracking | Included (`openloops/llmcalls`): per answer, per chat, and per-user statistics | Not included in OSS, available via paid LangSmith | Third-party integrations such as OpenLIT report token usage and cost |
|
|
@@ -180,7 +212,11 @@ GEMINI_API_KEY=
|
|
|
180
212
|
# Required for login
|
|
181
213
|
JWT_SECRET=
|
|
182
214
|
|
|
183
|
-
# Optional,
|
|
215
|
+
# Optional, see docs/configuration.md
|
|
216
|
+
LLM_FALLBACK_PROVIDER=
|
|
217
|
+
LLM_FALLBACK_MODEL=
|
|
218
|
+
|
|
219
|
+
# Optional, in milliseconds
|
|
184
220
|
AGENTIC_JOBS_POLL_INTERVAL_MS=
|
|
185
221
|
AGENTIC_JOBS_LEASE_MS=
|
|
186
222
|
LLM_CALL_TIMEOUT_MS=
|
|
@@ -223,7 +259,7 @@ Every pattern above, and a lot more, lives as a runnable example in [`examples/`
|
|
|
223
259
|
|
|
224
260
|
| Subpath | What's in it |
|
|
225
261
|
|---|---|
|
|
226
|
-
| `openloops/core` | `Agent`, `AgentLoop`, `RunContext`, `Harness`: the
|
|
262
|
+
| `openloops/core` | `Agent`, `AgentLoop`, `RunContext`, `Harness`: the harness |
|
|
227
263
|
| `openloops/loops` | Built-in loops (`AgiLoop`) and the skills shared by loops |
|
|
228
264
|
| `openloops/tools` | `Tool`, `BaseParams`, and built-in tools |
|
|
229
265
|
| `openloops/skills` | `Skill`, for writing LLM-backed reasoning steps inside a loop |
|
|
@@ -242,7 +278,7 @@ Every pattern above, and a lot more, lives as a runnable example in [`examples/`
|
|
|
242
278
|
|
|
243
279
|
- [Integration guide](docs/integration-guide.md)
|
|
244
280
|
- [Documentation index](docs/README.md)
|
|
245
|
-
- [The `Agent`
|
|
281
|
+
- [The `Agent`](docs/agent.md)
|
|
246
282
|
- [Building an `AgentLoop`](docs/loops.md)
|
|
247
283
|
- [How the harness works](docs/harness.md)
|
|
248
284
|
- [Tools](docs/tools.md)
|
package/dist/clients/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './llm
|
|
2
|
-
export * from './serper
|
|
1
|
+
export * from './llm';
|
|
2
|
+
export * from './serper';
|
package/dist/clients/index.js
CHANGED
|
@@ -15,10 +15,10 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
15
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
16
|
var clients_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(clients_exports);
|
|
18
|
-
__reExport(clients_exports, require("./llm
|
|
19
|
-
__reExport(clients_exports, require("./serper
|
|
18
|
+
__reExport(clients_exports, require("./llm"), module.exports);
|
|
19
|
+
__reExport(clients_exports, require("./serper"), module.exports);
|
|
20
20
|
// Annotate the CommonJS export names for ESM import in node:
|
|
21
21
|
0 && (module.exports = {
|
|
22
|
-
...require("./llm
|
|
23
|
-
...require("./serper
|
|
22
|
+
...require("./llm"),
|
|
23
|
+
...require("./serper")
|
|
24
24
|
});
|
package/dist/clients/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./llm
|
|
2
|
-
export * from "./serper
|
|
1
|
+
export * from "./llm";
|
|
2
|
+
export * from "./serper";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './llm-client';
|
|
@@ -13,10 +13,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
13
13
|
};
|
|
14
14
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
-
var
|
|
17
|
-
module.exports = __toCommonJS(
|
|
18
|
-
__reExport(
|
|
16
|
+
var llm_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(llm_exports);
|
|
18
|
+
__reExport(llm_exports, require("./llm-client"), module.exports);
|
|
19
19
|
// Annotate the CommonJS export names for ESM import in node:
|
|
20
20
|
0 && (module.exports = {
|
|
21
|
-
...require("./
|
|
21
|
+
...require("./llm-client")
|
|
22
22
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./llm-client";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { CurrentUser } from '
|
|
1
|
+
import type { AssistantMessage } from '@earendil-works/pi-ai';
|
|
2
|
+
import { CurrentUser } from '../../common/base/index.js';
|
|
3
3
|
import { LLMChatParams, LLMResponse } from './llm-types';
|
|
4
4
|
export declare class LLMClient {
|
|
5
5
|
private static readonly modelsWithoutTemperature;
|
|
@@ -9,7 +9,7 @@ export declare class LLMClient {
|
|
|
9
9
|
private readonly callTimeoutMs;
|
|
10
10
|
constructor();
|
|
11
11
|
chat(params: LLMChatParams): Promise<LLMResponse>;
|
|
12
|
-
|
|
12
|
+
private chooseModel;
|
|
13
13
|
private withDeadline;
|
|
14
14
|
private flushLangfuse;
|
|
15
15
|
private withoutRejectedTemperature;
|
|
@@ -21,17 +21,6 @@ export declare class LLMClient {
|
|
|
21
21
|
private formatTextForLog;
|
|
22
22
|
private formatMessagesForLog;
|
|
23
23
|
}
|
|
24
|
-
export interface LLMCompletionParams {
|
|
25
|
-
origin: string;
|
|
26
|
-
sessionId: string;
|
|
27
|
-
answerId: string;
|
|
28
|
-
currentUser?: CurrentUser;
|
|
29
|
-
systemPrompt?: string;
|
|
30
|
-
messages: Message[];
|
|
31
|
-
provider?: KnownProvider;
|
|
32
|
-
modelName?: string;
|
|
33
|
-
temperature?: number;
|
|
34
|
-
}
|
|
35
24
|
export interface LLMPostResponseParams {
|
|
36
25
|
origin: string;
|
|
37
26
|
sessionId: string;
|
|
@@ -32,15 +32,14 @@ __export(llm_client_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(llm_client_exports);
|
|
34
34
|
var import_langfuse = require("langfuse");
|
|
35
|
-
var import_secret_manager = require("
|
|
36
|
-
var import_logger = require("
|
|
37
|
-
var import_helpers = require("
|
|
38
|
-
var import_llmcalls = require("
|
|
35
|
+
var import_secret_manager = require("../../common/utils/secret-manager.js");
|
|
36
|
+
var import_logger = require("../../common/logger/index.js");
|
|
37
|
+
var import_helpers = require("../../common/helpers/index.js");
|
|
38
|
+
var import_llmcalls = require("../../services/llmcalls/index.js");
|
|
39
39
|
var import_pi_ai_adapter = require("./pi-ai-adapter");
|
|
40
|
-
var import_number_setting = require("
|
|
40
|
+
var import_number_setting = require("../../common/utils/number-setting.js");
|
|
41
|
+
var import_model_resolution = require("./model-resolution");
|
|
41
42
|
var import_llm_error = require("./llm-error");
|
|
42
|
-
const DEFAULT_PROVIDER = "anthropic";
|
|
43
|
-
const DEFAULT_MODEL = "claude-haiku-5-5";
|
|
44
43
|
const DEFAULT_TEMPERATURE = 0.7;
|
|
45
44
|
const MAX_RETRIES = 4;
|
|
46
45
|
const MAX_RATE_LIMIT_WAITS = 2;
|
|
@@ -88,10 +87,9 @@ class LLMClient {
|
|
|
88
87
|
messages,
|
|
89
88
|
tools,
|
|
90
89
|
toolChoice,
|
|
91
|
-
provider = DEFAULT_PROVIDER,
|
|
92
|
-
modelName = DEFAULT_MODEL,
|
|
93
90
|
temperature = DEFAULT_TEMPERATURE
|
|
94
91
|
} = params;
|
|
92
|
+
const { provider, model: modelName } = this.chooseModel(params);
|
|
95
93
|
const { builtinModels } = await import("@earendil-works/pi-ai/providers/all");
|
|
96
94
|
const models = builtinModels();
|
|
97
95
|
const model = models.getModel(provider, modelName);
|
|
@@ -113,34 +111,13 @@ class LLMClient {
|
|
|
113
111
|
}
|
|
114
112
|
return (0, import_pi_ai_adapter.fromPiMessage)(raw);
|
|
115
113
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
origin,
|
|
124
|
-
sessionId,
|
|
125
|
-
answerId,
|
|
126
|
-
currentUser,
|
|
127
|
-
systemPrompt,
|
|
128
|
-
messages,
|
|
129
|
-
provider = DEFAULT_PROVIDER,
|
|
130
|
-
modelName = DEFAULT_MODEL,
|
|
131
|
-
temperature = DEFAULT_TEMPERATURE
|
|
132
|
-
} = params ?? {};
|
|
133
|
-
const model = models.getModel(provider, modelName);
|
|
134
|
-
if (!model) throw new Error("[LLM Client] model not found");
|
|
135
|
-
const context = {
|
|
136
|
-
systemPrompt,
|
|
137
|
-
messages
|
|
138
|
-
};
|
|
139
|
-
return this.traced(
|
|
140
|
-
{ origin, sessionId, answerId, currentUser, modelName, provider, temperature },
|
|
141
|
-
context,
|
|
142
|
-
() => this.withoutRejectedTemperature(`${provider}/${modelName}`, (omitTemperature) => this.withDeadline((signal) => models.complete(model, context, { ...omitTemperature ? {} : { temperature }, maxRetries: MAX_RETRIES, signal })))
|
|
143
|
-
);
|
|
114
|
+
chooseModel(params) {
|
|
115
|
+
const { provider, modelName, currentUser } = params ?? {};
|
|
116
|
+
if (Boolean(provider) !== Boolean(modelName)) throw new Error("[LLM Client] provider and modelName must be given together");
|
|
117
|
+
return (0, import_model_resolution.resolveModel)({
|
|
118
|
+
run: (0, import_model_resolution.toModelRef)({ provider, model: modelName }),
|
|
119
|
+
user: (0, import_model_resolution.toModelRef)(currentUser?.preferences?.defaultModel)
|
|
120
|
+
});
|
|
144
121
|
}
|
|
145
122
|
async withDeadline(call) {
|
|
146
123
|
for (let attempt = 1; attempt <= MAX_TIMEOUT_RETRIES + 1; attempt++) {
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import "
|
|
1
|
+
import "../../chunk-CF3WOMB3.mjs";
|
|
2
2
|
import { Langfuse } from "langfuse";
|
|
3
|
-
import { secretManager } from "
|
|
4
|
-
import { Logger } from "
|
|
5
|
-
import { extractJSON } from "
|
|
6
|
-
import { createLLMCall } from "
|
|
3
|
+
import { secretManager } from "../../common/utils/secret-manager.js";
|
|
4
|
+
import { Logger } from "../../common/logger/index.js";
|
|
5
|
+
import { extractJSON } from "../../common/helpers/index.js";
|
|
6
|
+
import { createLLMCall } from "../../services/llmcalls/index.js";
|
|
7
7
|
import { toPiContext, fromPiMessage } from "./pi-ai-adapter";
|
|
8
|
-
import { numberSetting } from "
|
|
8
|
+
import { numberSetting } from "../../common/utils/number-setting.js";
|
|
9
|
+
import { resolveModel, toModelRef } from "./model-resolution";
|
|
9
10
|
import { LLMError, retryDelayMs, rejectsSamplingParameter } from "./llm-error";
|
|
10
|
-
const DEFAULT_PROVIDER = "anthropic";
|
|
11
|
-
const DEFAULT_MODEL = "claude-haiku-5-5";
|
|
12
11
|
const DEFAULT_TEMPERATURE = 0.7;
|
|
13
12
|
const MAX_RETRIES = 4;
|
|
14
13
|
const MAX_RATE_LIMIT_WAITS = 2;
|
|
@@ -56,10 +55,9 @@ class LLMClient {
|
|
|
56
55
|
messages,
|
|
57
56
|
tools,
|
|
58
57
|
toolChoice,
|
|
59
|
-
provider = DEFAULT_PROVIDER,
|
|
60
|
-
modelName = DEFAULT_MODEL,
|
|
61
58
|
temperature = DEFAULT_TEMPERATURE
|
|
62
59
|
} = params;
|
|
60
|
+
const { provider, model: modelName } = this.chooseModel(params);
|
|
63
61
|
const { builtinModels } = await import("@earendil-works/pi-ai/providers/all");
|
|
64
62
|
const models = builtinModels();
|
|
65
63
|
const model = models.getModel(provider, modelName);
|
|
@@ -81,34 +79,13 @@ class LLMClient {
|
|
|
81
79
|
}
|
|
82
80
|
return fromPiMessage(raw);
|
|
83
81
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
origin,
|
|
92
|
-
sessionId,
|
|
93
|
-
answerId,
|
|
94
|
-
currentUser,
|
|
95
|
-
systemPrompt,
|
|
96
|
-
messages,
|
|
97
|
-
provider = DEFAULT_PROVIDER,
|
|
98
|
-
modelName = DEFAULT_MODEL,
|
|
99
|
-
temperature = DEFAULT_TEMPERATURE
|
|
100
|
-
} = params ?? {};
|
|
101
|
-
const model = models.getModel(provider, modelName);
|
|
102
|
-
if (!model) throw new Error("[LLM Client] model not found");
|
|
103
|
-
const context = {
|
|
104
|
-
systemPrompt,
|
|
105
|
-
messages
|
|
106
|
-
};
|
|
107
|
-
return this.traced(
|
|
108
|
-
{ origin, sessionId, answerId, currentUser, modelName, provider, temperature },
|
|
109
|
-
context,
|
|
110
|
-
() => this.withoutRejectedTemperature(`${provider}/${modelName}`, (omitTemperature) => this.withDeadline((signal) => models.complete(model, context, { ...omitTemperature ? {} : { temperature }, maxRetries: MAX_RETRIES, signal })))
|
|
111
|
-
);
|
|
82
|
+
chooseModel(params) {
|
|
83
|
+
const { provider, modelName, currentUser } = params ?? {};
|
|
84
|
+
if (Boolean(provider) !== Boolean(modelName)) throw new Error("[LLM Client] provider and modelName must be given together");
|
|
85
|
+
return resolveModel({
|
|
86
|
+
run: toModelRef({ provider, model: modelName }),
|
|
87
|
+
user: toModelRef(currentUser?.preferences?.defaultModel)
|
|
88
|
+
});
|
|
112
89
|
}
|
|
113
90
|
async withDeadline(call) {
|
|
114
91
|
for (let attempt = 1; attempt <= MAX_TIMEOUT_RETRIES + 1; attempt++) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "
|
|
1
|
+
import "../../chunk-CF3WOMB3.mjs";
|
|
2
2
|
const USER_MESSAGES = {
|
|
3
3
|
LLM_RATE_LIMITED: "The model is receiving too many requests right now. Please try again in a few seconds.",
|
|
4
4
|
LLM_QUOTA_EXCEEDED: "The usage quota of the model provider has been exhausted. Please check the plan and billing of the provider.",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface ModelRef {
|
|
2
|
+
provider: string;
|
|
3
|
+
model: string;
|
|
4
|
+
}
|
|
5
|
+
export type ModelSource = 'run' | 'chat' | 'user' | 'agent' | 'backend' | 'client';
|
|
6
|
+
export declare const CLIENT_FALLBACK_MODEL: ModelRef;
|
|
7
|
+
export declare function toModelRef(value?: {
|
|
8
|
+
provider?: unknown;
|
|
9
|
+
model?: unknown;
|
|
10
|
+
} | null): ModelRef | undefined;
|
|
11
|
+
export declare function backendFallbackModel(): ModelRef | undefined;
|
|
12
|
+
export declare function resolveModel(levels: {
|
|
13
|
+
run?: ModelRef;
|
|
14
|
+
chat?: ModelRef;
|
|
15
|
+
user?: ModelRef;
|
|
16
|
+
agent?: ModelRef;
|
|
17
|
+
}): ModelRef & {
|
|
18
|
+
source: ModelSource;
|
|
19
|
+
};
|
|
20
|
+
export declare function isKnownModel(provider: string, model: string): Promise<boolean>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var model_resolution_exports = {};
|
|
30
|
+
__export(model_resolution_exports, {
|
|
31
|
+
CLIENT_FALLBACK_MODEL: () => CLIENT_FALLBACK_MODEL,
|
|
32
|
+
backendFallbackModel: () => backendFallbackModel,
|
|
33
|
+
isKnownModel: () => isKnownModel,
|
|
34
|
+
resolveModel: () => resolveModel,
|
|
35
|
+
toModelRef: () => toModelRef
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(model_resolution_exports);
|
|
38
|
+
var import_secret_manager = require("../../common/utils/secret-manager.js");
|
|
39
|
+
var import_logger = require("../../common/logger/index.js");
|
|
40
|
+
const CLIENT_FALLBACK_MODEL = { provider: "anthropic", model: "claude-haiku-5-5" };
|
|
41
|
+
let warnedAboutBackendFallback = false;
|
|
42
|
+
function toModelRef(value) {
|
|
43
|
+
const provider = typeof value?.provider === "string" ? value.provider.trim() : "";
|
|
44
|
+
const model = typeof value?.model === "string" ? value.model.trim() : "";
|
|
45
|
+
return provider && model ? { provider, model } : void 0;
|
|
46
|
+
}
|
|
47
|
+
function backendFallbackModel() {
|
|
48
|
+
const provider = import_secret_manager.secretManager.get("LLM_FALLBACK_PROVIDER");
|
|
49
|
+
const model = import_secret_manager.secretManager.get("LLM_FALLBACK_MODEL");
|
|
50
|
+
if (Boolean(provider) !== Boolean(model)) {
|
|
51
|
+
if (!warnedAboutBackendFallback) {
|
|
52
|
+
warnedAboutBackendFallback = true;
|
|
53
|
+
import_logger.logger.warn("[LLM Client] LLM_FALLBACK_PROVIDER and LLM_FALLBACK_MODEL must be set together, so they are ignored");
|
|
54
|
+
}
|
|
55
|
+
return void 0;
|
|
56
|
+
}
|
|
57
|
+
return toModelRef({ provider, model });
|
|
58
|
+
}
|
|
59
|
+
function resolveModel(levels) {
|
|
60
|
+
if (levels.run) return { ...levels.run, source: "run" };
|
|
61
|
+
if (levels.chat) return { ...levels.chat, source: "chat" };
|
|
62
|
+
if (levels.user) return { ...levels.user, source: "user" };
|
|
63
|
+
if (levels.agent) return { ...levels.agent, source: "agent" };
|
|
64
|
+
const backend = backendFallbackModel();
|
|
65
|
+
if (backend) return { ...backend, source: "backend" };
|
|
66
|
+
return { ...CLIENT_FALLBACK_MODEL, source: "client" };
|
|
67
|
+
}
|
|
68
|
+
async function isKnownModel(provider, model) {
|
|
69
|
+
try {
|
|
70
|
+
const { builtinModels } = await import("@earendil-works/pi-ai/providers/all");
|
|
71
|
+
return Boolean(builtinModels().getModel(provider, model));
|
|
72
|
+
} catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
CLIENT_FALLBACK_MODEL,
|
|
79
|
+
backendFallbackModel,
|
|
80
|
+
isKnownModel,
|
|
81
|
+
resolveModel,
|
|
82
|
+
toModelRef
|
|
83
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import "../../chunk-CF3WOMB3.mjs";
|
|
2
|
+
import { secretManager } from "../../common/utils/secret-manager.js";
|
|
3
|
+
import { logger } from "../../common/logger/index.js";
|
|
4
|
+
const CLIENT_FALLBACK_MODEL = { provider: "anthropic", model: "claude-haiku-5-5" };
|
|
5
|
+
let warnedAboutBackendFallback = false;
|
|
6
|
+
function toModelRef(value) {
|
|
7
|
+
const provider = typeof value?.provider === "string" ? value.provider.trim() : "";
|
|
8
|
+
const model = typeof value?.model === "string" ? value.model.trim() : "";
|
|
9
|
+
return provider && model ? { provider, model } : void 0;
|
|
10
|
+
}
|
|
11
|
+
function backendFallbackModel() {
|
|
12
|
+
const provider = secretManager.get("LLM_FALLBACK_PROVIDER");
|
|
13
|
+
const model = secretManager.get("LLM_FALLBACK_MODEL");
|
|
14
|
+
if (Boolean(provider) !== Boolean(model)) {
|
|
15
|
+
if (!warnedAboutBackendFallback) {
|
|
16
|
+
warnedAboutBackendFallback = true;
|
|
17
|
+
logger.warn("[LLM Client] LLM_FALLBACK_PROVIDER and LLM_FALLBACK_MODEL must be set together, so they are ignored");
|
|
18
|
+
}
|
|
19
|
+
return void 0;
|
|
20
|
+
}
|
|
21
|
+
return toModelRef({ provider, model });
|
|
22
|
+
}
|
|
23
|
+
function resolveModel(levels) {
|
|
24
|
+
if (levels.run) return { ...levels.run, source: "run" };
|
|
25
|
+
if (levels.chat) return { ...levels.chat, source: "chat" };
|
|
26
|
+
if (levels.user) return { ...levels.user, source: "user" };
|
|
27
|
+
if (levels.agent) return { ...levels.agent, source: "agent" };
|
|
28
|
+
const backend = backendFallbackModel();
|
|
29
|
+
if (backend) return { ...backend, source: "backend" };
|
|
30
|
+
return { ...CLIENT_FALLBACK_MODEL, source: "client" };
|
|
31
|
+
}
|
|
32
|
+
async function isKnownModel(provider, model) {
|
|
33
|
+
try {
|
|
34
|
+
const { builtinModels } = await import("@earendil-works/pi-ai/providers/all");
|
|
35
|
+
return Boolean(builtinModels().getModel(provider, model));
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
CLIENT_FALLBACK_MODEL,
|
|
42
|
+
backendFallbackModel,
|
|
43
|
+
isKnownModel,
|
|
44
|
+
resolveModel,
|
|
45
|
+
toModelRef
|
|
46
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './serper-client';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var serper_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(serper_exports);
|
|
18
|
+
__reExport(serper_exports, require("./serper-client"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./serper-client")
|
|
22
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./serper-client";
|
|
@@ -32,8 +32,8 @@ __export(serper_client_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(serper_client_exports);
|
|
34
34
|
var import_axios = __toESM(require("axios"));
|
|
35
|
-
var import_logger = require("
|
|
36
|
-
var import_secret_manager = require("
|
|
35
|
+
var import_logger = require("../../common/logger/index.js");
|
|
36
|
+
var import_secret_manager = require("../../common/utils/secret-manager.js");
|
|
37
37
|
class SerperClient {
|
|
38
38
|
logger = new import_logger.Logger();
|
|
39
39
|
async searchOnGoogle(params) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import "
|
|
1
|
+
import "../../chunk-CF3WOMB3.mjs";
|
|
2
2
|
import axios from "axios";
|
|
3
|
-
import { Logger } from "
|
|
4
|
-
import { secretManager } from "
|
|
3
|
+
import { Logger } from "../../common/logger/index.js";
|
|
4
|
+
import { secretManager } from "../../common/utils/secret-manager.js";
|
|
5
5
|
class SerperClient {
|
|
6
6
|
logger = new Logger();
|
|
7
7
|
async searchOnGoogle(params) {
|
|
@@ -40,7 +40,6 @@ export interface Harness {
|
|
|
40
40
|
requestApproval: (actions: AgentAction[], opts: {
|
|
41
41
|
resumeAt: string | AgentLoopNode;
|
|
42
42
|
}) => Promise<void>;
|
|
43
|
-
reopenTask: (taskId: string) => Promise<AgentTask | undefined>;
|
|
44
43
|
reply: (content: string) => void;
|
|
45
44
|
setNextNode: (node?: string | AgentLoopNode) => void;
|
|
46
45
|
}
|
package/dist/harness/agent.d.ts
CHANGED
|
@@ -24,6 +24,10 @@ export interface AgentOptions {
|
|
|
24
24
|
identity?: AgentIdentity;
|
|
25
25
|
maxIterations?: number;
|
|
26
26
|
strictMode?: boolean;
|
|
27
|
+
fallbackModel?: {
|
|
28
|
+
provider: string;
|
|
29
|
+
model: string;
|
|
30
|
+
};
|
|
27
31
|
}
|
|
28
32
|
interface ChatInput {
|
|
29
33
|
message: string;
|
|
@@ -37,6 +41,8 @@ export declare class Agent {
|
|
|
37
41
|
private readonly _identity?;
|
|
38
42
|
private readonly maxIterations;
|
|
39
43
|
private readonly strictMode;
|
|
44
|
+
private readonly fallbackModel?;
|
|
45
|
+
private model?;
|
|
40
46
|
private _tools;
|
|
41
47
|
private _mcps;
|
|
42
48
|
private mcpListing?;
|
|
@@ -130,7 +136,6 @@ export declare class Agent {
|
|
|
130
136
|
private getWorkspace;
|
|
131
137
|
private getPipeline;
|
|
132
138
|
private runAction;
|
|
133
|
-
private reopenTask;
|
|
134
139
|
private buildRunContext;
|
|
135
140
|
private buildHarness;
|
|
136
141
|
}
|