openloops 0.1.22 → 0.1.24
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 +219 -0
- package/dist/agent/agent-loop.d.ts +7 -0
- package/dist/agent/agent.d.ts +20 -2
- package/dist/agent/agent.js +11 -1
- package/dist/agent/agent.mjs +11 -1
- package/dist/clients/llm-client.d.ts +2 -3
- package/dist/clients/llm-client.js +10 -13
- package/dist/clients/llm-client.mjs +10 -13
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.js +22 -0
- package/dist/common/index.mjs +1 -0
- package/dist/loops/plan-execute/plan-execute-loop.js +2 -0
- package/dist/loops/plan-execute/plan-execute-loop.mjs +2 -0
- package/dist/loops/shared/skills/fast-responder.js +0 -5
- package/dist/loops/shared/skills/fast-responder.mjs +0 -5
- package/dist/services/chats/entities/chat-settings.entity.d.ts +4 -1
- package/dist/services/chats/entities/chat-settings.entity.js +8 -1
- package/dist/services/chats/entities/chat-settings.entity.mjs +8 -1
- package/dist/services/llmcalls/entities/llmcall.entity.d.ts +4 -4
- package/dist/services/llmcalls/entities/llmcall.entity.js +7 -7
- package/dist/services/llmcalls/entities/llmcall.entity.mjs +7 -7
- package/dist/services/llmcalls/lambdas/get-llm-usage/get-llm-usage.use-case.js +8 -2
- package/dist/services/llmcalls/lambdas/get-llm-usage/get-llm-usage.use-case.mjs +8 -2
- package/dist/services/llmcalls/module.d.ts +2 -0
- package/dist/services/llmcalls/module.js +7 -0
- package/dist/services/llmcalls/module.mjs +6 -0
- package/dist/skills/skill-runner.js +1 -1
- package/dist/skills/skill-runner.mjs +1 -1
- package/dist/skills/skill.js +1 -1
- package/dist/skills/skill.mjs +1 -1
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# openloops
|
|
2
|
+
|
|
3
|
+
**Build production-grade enterprise agents in minutes, not days, weeks, or months.**
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import { Agent } from 'openloops/core'
|
|
7
|
+
import { Logger } from 'openloops/common'
|
|
8
|
+
import { CurrentUser } from 'openloops/base'
|
|
9
|
+
import { PlanExecuteLoop } from 'openloops/loops'
|
|
10
|
+
|
|
11
|
+
const logger = new Logger()
|
|
12
|
+
const currentUser = await CurrentUser.asyncFromDB(userId)
|
|
13
|
+
const agent = new Agent({ loop: new PlanExecuteLoop() })
|
|
14
|
+
|
|
15
|
+
const result = await agent.run({
|
|
16
|
+
input: { message: 'what is the current price of Bitcoin?' },
|
|
17
|
+
currentUser,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
logger.info(result.data.lastAnswer, '[Demo] Result')
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
That's it. The agent is persisted, resumable, and scoped to that one user, with tool execution, retries, and observability already wired in. No message table to design, no state machine to debug by hand, no MCP adapter to write.
|
|
24
|
+
|
|
25
|
+
## Pick a loop, or write your own
|
|
26
|
+
|
|
27
|
+
The logic that makes your agent *your* agent (how it plans, when it asks for confirmation, whether it answers in one shot or works through a sequence of tools) lives in an `AgentLoop`. `openloops` ships `PlanExecuteLoop` today, and it's built so any loop, yours or someone else's, is interchangeable.
|
|
28
|
+
|
|
29
|
+
Want a customer support agent?
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
const agent = new Agent({ loop: new CustomerSupportLoop() })
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Want a software development agent?
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
const agent = new Agent({ loop: new CodeSpecialistLoop() })
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Want a reasoning agent for deep analysis?
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
const agent = new Agent({ loop: new ReactLoop() })
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Don't see what you need in the marketplace? Build it yourself. A loop is a single file with a handful of node functions. Most people have their first working loop in an afternoon, not a sprint. See [Building an `AgentLoop`](docs/loops.md).
|
|
48
|
+
|
|
49
|
+
**Launching this week at [openloops.xyz/marketplace](https://openloops.xyz/marketplace):** a growing library of free, community-maintained loops, including `ReactLoop`, `CodeSpecialistLoop`, `CustomerSupportLoop`, and more on the way for domains like cybersecurity and finance. Building an agent for a new use case becomes a matter of picking the right loop, not writing a new framework underneath it every time.
|
|
50
|
+
|
|
51
|
+
## Built for products, not for one person
|
|
52
|
+
|
|
53
|
+
If you've stood up [OpenClaw](https://github.com/openclaw/openclaw), [Hermes Agent](https://github.com/NousResearch/hermes-agent), or [ZeroClaw](https://github.com/zeroclaw-labs/zeroclaw), you already know how good a single, always-on personal agent can feel. You also know what happens the moment you try to make it serve more than one person: there's no clean boundary between "my agent" and "your agent." Conversations, memory, and connected tools were never designed to be scoped per user in the first place.
|
|
54
|
+
|
|
55
|
+
`openloops` starts from the opposite assumption. Every chat, every task, every piece of context, and every connected MCP server is scoped to a `currentUser` from the ground up, not bolted on later. Two users, same deployment, completely separate agents, with zero risk of one seeing the other's history or tools.
|
|
56
|
+
|
|
57
|
+
## If you've already tried LangGraph or CrewAI
|
|
58
|
+
|
|
59
|
+
You know the pattern: before you write a single line of what your agent actually *does*, you're declaring a graph, wiring a checkpointer, and figuring out how tool retries and error states are supposed to work. Weeks in, you have an agent that technically runs, and a mental model of *why* it does what it does that only lives in your head, because the framework itself is a black box the moment something goes wrong in production.
|
|
60
|
+
|
|
61
|
+
`openloops` gives you one file to read to understand your agent's behavior: the loop itself. Persistence, retries, and tracing aren't something you configure. They're just already there. See the full comparison against LangGraph further down.
|
|
62
|
+
|
|
63
|
+
## What you get out of the box
|
|
64
|
+
|
|
65
|
+
- **Multi-user by design.** Chat history, task state, and MCP server configuration are all scoped per user, so the same deployment safely serves every one of your customers.
|
|
66
|
+
- **Zero-boilerplate persistence.** Messages, tasks, and every tool call your agent makes are saved automatically to MongoDB. You never write a `save()` call.
|
|
67
|
+
- **Production-grade tool execution.** Retries on failed steps, confirmation prompts before destructive actions, and graceful resume after a crash are all built into the runtime.
|
|
68
|
+
- **Native MCP support.** Connect any MCP server and its tools become regular tools instantly. No adapter package, no manual schema mapping.
|
|
69
|
+
- **Sub-agent orchestration.** An agent can launch and coordinate other agents to split up a problem. Full guide coming soon.
|
|
70
|
+
- **Any LLM provider, including local ones.** Built on [`@mariozechner/pi-ai`](https://www.npmjs.com/package/@mariozechner/pi-ai), so OpenAI, Anthropic, and self-hosted models (e.g. via Ollama) all work the same way.
|
|
71
|
+
- **Observability without ceremony.** Sentry and Langfuse are built in. Set the environment variables and they turn on, no SDK wiring required.
|
|
72
|
+
- **A loop marketplace.** Don't write a customer-support agent from scratch. Install one.
|
|
73
|
+
|
|
74
|
+
## See how little code this actually takes
|
|
75
|
+
|
|
76
|
+
Adding a custom tool:
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { Tool, BaseParams } from 'openloops/tools'
|
|
80
|
+
|
|
81
|
+
export const greetUserTool = new Tool({
|
|
82
|
+
name: 'greet_user',
|
|
83
|
+
description: 'Greet the user',
|
|
84
|
+
destructive: false,
|
|
85
|
+
parameters: {
|
|
86
|
+
type: 'object',
|
|
87
|
+
properties: { firstName: { type: 'string', description: 'First name of the user' } },
|
|
88
|
+
required: ['firstName'],
|
|
89
|
+
},
|
|
90
|
+
handler: async (params: BaseParams & { firstName: string }) => {
|
|
91
|
+
return { data: { greeting: `Hi ${params.firstName}` } }
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
agent.addTool(greetUserTool)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Connecting an MCP server for a user takes no code, just a record:
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { createMcpServer } from 'openloops/mcps'
|
|
102
|
+
|
|
103
|
+
await createMcpServer({
|
|
104
|
+
payload: { name: 'my-mcp', type: 'http', url: 'https://example.dev/api/mcp' },
|
|
105
|
+
currentUser,
|
|
106
|
+
})
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
The next time that user talks to *any* agent, its tools are already there.
|
|
110
|
+
|
|
111
|
+
## How it compares to other frameworks
|
|
112
|
+
|
|
113
|
+
This is an honest comparison against the self-hosted, open-source versions of LangGraph and CrewAI, not their paid managed offerings, which do handle persistence and infrastructure for you the same way `openloops` does, at a cost.
|
|
114
|
+
|
|
115
|
+
| | `openloops` | LangGraph (self-hosted OSS) | CrewAI (self-hosted OSS) |
|
|
116
|
+
|---|---|---|---|
|
|
117
|
+
| Persistence | Built in, zero config (MongoDB) | Requires configuring a checkpointer (e.g. Postgres) yourself | Local memory (ChromaDB + SQLite) by default, machine-bound and scoped to a single run |
|
|
118
|
+
| Multi-user scoping | Built in: chats, context, and MCP servers are per-user from the start | Not a concept of the framework, you build it | Not natively supported by default |
|
|
119
|
+
| Tool execution & retries | Built into the runtime | You write the retry/error-handling logic | Configured per task, not automatic |
|
|
120
|
+
| MCP support | Native: MCP tools become `Tool` instances automatically | Requires a separate adapter package and manual wiring | Available through a separate tools integration, not automatic per-user loading |
|
|
121
|
+
| User management | Included (`openloops/users`) | Not included, you build your own | Not included |
|
|
122
|
+
| LLM usage/cost tracking | Included (`openloops/llmcalls`) | Not included in OSS, available via paid LangSmith | Not included as a first-class module |
|
|
123
|
+
| Observability | Sentry + Langfuse, enabled via env vars | Requires your own tracing setup, or paid LangSmith | Requires a third-party tracing integration |
|
|
124
|
+
| Pre-built agents | Growing marketplace of ready-to-use loops | You build every agent from primitives | No built-in agent marketplace |
|
|
125
|
+
| What you write | Node functions (plain async functions) | Nodes and the graph's edges, explicitly | Agents, tasks, and crew orchestration, declared per role |
|
|
126
|
+
| Mental model | A state machine your loop drives itself | A graph you declare and compile ahead of time | A crew of role-based agents coordinated for you |
|
|
127
|
+
|
|
128
|
+
Neither approach is "wrong." LangGraph's explicit graph declaration is a deliberate design choice that gives you visual tooling (LangGraph Studio) and fine-grained control over parallel execution, and CrewAI's role-based model is a natural fit for problems that map cleanly onto a team of specialists. `openloops` trades some of that explicitness for a much shorter path from "I have an idea for an agent" to "it's running in production, for all my users."
|
|
129
|
+
|
|
130
|
+
## Quick start (local)
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
npm install openloops
|
|
134
|
+
# or
|
|
135
|
+
yarn add openloops
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Spin up a local MongoDB with the included `docker-compose.yml`:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
docker compose up -d
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Create a `.env` file:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
IS_LOCAL=true
|
|
148
|
+
NODE_ENV=development
|
|
149
|
+
|
|
150
|
+
OPENLOOPS_DB_URI="mongodb://localhost:27017/"
|
|
151
|
+
OPENLOOPS_DB_NAME='openloops'
|
|
152
|
+
|
|
153
|
+
SECRET_MANAGER_KEY=secret
|
|
154
|
+
|
|
155
|
+
OPENAI_API_KEY=
|
|
156
|
+
|
|
157
|
+
# Optional, see "Observability" below
|
|
158
|
+
SENTRY_DSN=
|
|
159
|
+
LANGFUSE_SECRET_KEY=
|
|
160
|
+
LANGFUSE_PUBLIC_KEY=
|
|
161
|
+
LANGFUSE_BASE_URL=
|
|
162
|
+
|
|
163
|
+
# Optional, see "Web search" below
|
|
164
|
+
SERPER_API_KEY=
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Database
|
|
168
|
+
|
|
169
|
+
By default, `openloops` creates a database named `openloops` if `OPENLOOPS_DB_NAME` isn't set. You can point it at an existing database instead, but if that database already has other collections, we recommend using a **separate database** to avoid name collisions with your own collections. If you're starting a project from scratch, using a single unified database for everything (your app's data and `openloops`'s data together) is fine and often simpler.
|
|
170
|
+
|
|
171
|
+
### Web search
|
|
172
|
+
|
|
173
|
+
The built-in `webSearchTool` uses [Serper](https://serper.dev). Create a free API key there and set `SERPER_API_KEY` in your `.env`. See [`docs/tools.md`](docs/tools.md).
|
|
174
|
+
|
|
175
|
+
### Observability
|
|
176
|
+
|
|
177
|
+
- **Sentry**: set `SENTRY_DSN` and error tracking turns on automatically.
|
|
178
|
+
- **Langfuse**: set `LANGFUSE_SECRET_KEY`, `LANGFUSE_PUBLIC_KEY`, and `LANGFUSE_BASE_URL` and every LLM call is traced automatically.
|
|
179
|
+
|
|
180
|
+
Neither requires any code changes. They're opt-in purely through environment variables.
|
|
181
|
+
|
|
182
|
+
## More examples
|
|
183
|
+
|
|
184
|
+
Every pattern above, and a lot more, lives as a runnable example in [`examples/`](examples), organized by domain: `users`, `chats`, `run-agent`, `mcps`, `usage`.
|
|
185
|
+
|
|
186
|
+
## Package structure
|
|
187
|
+
|
|
188
|
+
`openloops` is a single package with organized subpath exports, so you only pull in what you use:
|
|
189
|
+
|
|
190
|
+
| Subpath | What's in it |
|
|
191
|
+
|---|---|
|
|
192
|
+
| `openloops/core` | `Agent`, `AgentLoop`, `RunContext`: the runtime |
|
|
193
|
+
| `openloops/loops` | Built-in loops, starting with `PlanExecuteLoop` |
|
|
194
|
+
| `openloops/tools` | `Tool`, `BaseParams`, and built-in tools |
|
|
195
|
+
| `openloops/skills` | `Skill`, for writing LLM-backed reasoning steps inside a loop |
|
|
196
|
+
| `openloops/mcps` | MCP server CRUD and connection handling |
|
|
197
|
+
| `openloops/users` | User management |
|
|
198
|
+
| `openloops/llmcalls` | LLM usage/cost tracking |
|
|
199
|
+
| `openloops/base` | `CurrentUser`, `CurrentSession` |
|
|
200
|
+
| `openloops/common` | `Logger` and shared utilities |
|
|
201
|
+
| `openloops/clients` | HTTP clients used by built-in tools (e.g. Serper) |
|
|
202
|
+
| `openloops/authentication` | Authentication utilities |
|
|
203
|
+
| `openloops/chats` | Chat/conversation persistence internals |
|
|
204
|
+
|
|
205
|
+
## Learn more
|
|
206
|
+
|
|
207
|
+
- [Building an `AgentLoop`](docs/loops.md)
|
|
208
|
+
- [The `Agent` runtime](docs/agent.md)
|
|
209
|
+
- [Tools](docs/tools.md)
|
|
210
|
+
- [Skills](docs/skills.md)
|
|
211
|
+
- [MCP servers](docs/mcp-servers.md)
|
|
212
|
+
- [User management](docs/users.md)
|
|
213
|
+
- [LLM usage tracking](docs/usage.md)
|
|
214
|
+
|
|
215
|
+
## License
|
|
216
|
+
|
|
217
|
+
Apache-2.0, free and open source, including for commercial and enterprise use.
|
|
218
|
+
|
|
219
|
+
Questions? Reach out at jose@openloops.xyz.
|
|
@@ -6,6 +6,7 @@ import { Tool, BaseParams } from '../tools/tool.js';
|
|
|
6
6
|
import { SkillRunOptions } from '../skills/skill.js';
|
|
7
7
|
import { WeightedKeyword, ScoredTool } from './utils/rank-tools-by-keywords';
|
|
8
8
|
export interface RunContext {
|
|
9
|
+
identity?: AgentIdentity;
|
|
9
10
|
task?: AgentTask;
|
|
10
11
|
chat: Chat;
|
|
11
12
|
currentUser: CurrentUser;
|
|
@@ -23,6 +24,11 @@ export interface RunContext {
|
|
|
23
24
|
setNextNode: (node?: string | AgentLoopNode) => void;
|
|
24
25
|
logger: Logger;
|
|
25
26
|
}
|
|
27
|
+
interface AgentIdentity {
|
|
28
|
+
name?: string;
|
|
29
|
+
gender?: string;
|
|
30
|
+
role?: string;
|
|
31
|
+
}
|
|
26
32
|
export type AgentLoopNode = (ctx: RunContext) => Promise<void>;
|
|
27
33
|
export interface Author {
|
|
28
34
|
name: string;
|
|
@@ -36,3 +42,4 @@ export declare abstract class AgentLoop {
|
|
|
36
42
|
abstract get version(): string;
|
|
37
43
|
abstract get author(): Author;
|
|
38
44
|
}
|
|
45
|
+
export {};
|
package/dist/agent/agent.d.ts
CHANGED
|
@@ -7,15 +7,26 @@ import { AgentLoop } from './agent-loop';
|
|
|
7
7
|
export declare const AGENT_ERROR_CODES: {
|
|
8
8
|
readonly NODE_NOT_FOUND: "AGENT_NODE_NOT_FOUND";
|
|
9
9
|
};
|
|
10
|
+
interface AgentIdentity {
|
|
11
|
+
name?: string;
|
|
12
|
+
gender?: string;
|
|
13
|
+
role?: string;
|
|
14
|
+
}
|
|
10
15
|
export interface AgentOptions {
|
|
11
16
|
loop: AgentLoop;
|
|
12
17
|
tools?: Tool[];
|
|
18
|
+
identity?: AgentIdentity;
|
|
13
19
|
}
|
|
14
|
-
interface
|
|
20
|
+
interface ChatInput {
|
|
15
21
|
message: string;
|
|
16
22
|
chatId?: string;
|
|
17
23
|
messageId?: string;
|
|
24
|
+
}
|
|
25
|
+
interface ChatOptions {
|
|
26
|
+
loopName?: string;
|
|
27
|
+
modelName?: 'string';
|
|
18
28
|
isPrivateSession?: boolean;
|
|
29
|
+
notifyOnCompletion?: boolean;
|
|
19
30
|
}
|
|
20
31
|
type HookType = 'pre_execution' | 'post_execution';
|
|
21
32
|
export declare class Agent {
|
|
@@ -23,11 +34,13 @@ export declare class Agent {
|
|
|
23
34
|
private readonly chatRepository;
|
|
24
35
|
private readonly logger;
|
|
25
36
|
private readonly _loop;
|
|
37
|
+
private readonly _identity?;
|
|
26
38
|
private _tools;
|
|
27
39
|
private _mcps;
|
|
28
40
|
private _preHooks;
|
|
29
41
|
private _postHooks;
|
|
30
42
|
private currentChat;
|
|
43
|
+
private chatOptions?;
|
|
31
44
|
private currentUser?;
|
|
32
45
|
private currentSession?;
|
|
33
46
|
private currentMessage;
|
|
@@ -42,7 +55,12 @@ export declare class Agent {
|
|
|
42
55
|
get mcps(): McpServer[];
|
|
43
56
|
get notifyOnCompletion(): boolean | undefined;
|
|
44
57
|
get lastAssistantAnswer(): string | undefined;
|
|
45
|
-
run(
|
|
58
|
+
run(props: {
|
|
59
|
+
input: ChatInput;
|
|
60
|
+
options?: ChatOptions;
|
|
61
|
+
currentUser: CurrentUser;
|
|
62
|
+
currentSession?: CurrentSession;
|
|
63
|
+
}): Promise<{
|
|
46
64
|
data: Chat;
|
|
47
65
|
} | undefined>;
|
|
48
66
|
stopAgent(): void;
|
package/dist/agent/agent.js
CHANGED
|
@@ -44,11 +44,13 @@ class Agent {
|
|
|
44
44
|
chatRepository = import_tsyringe.container.resolve(import_repositories.ChatRepository);
|
|
45
45
|
logger = new import_logger.Logger();
|
|
46
46
|
_loop;
|
|
47
|
+
_identity;
|
|
47
48
|
_tools;
|
|
48
49
|
_mcps = [];
|
|
49
50
|
_preHooks = [];
|
|
50
51
|
_postHooks = [];
|
|
51
52
|
currentChat;
|
|
53
|
+
chatOptions;
|
|
52
54
|
currentUser;
|
|
53
55
|
currentSession;
|
|
54
56
|
currentMessage = "";
|
|
@@ -81,6 +83,7 @@ class Agent {
|
|
|
81
83
|
if (!agentOptions?.loop) throw new Error("[AGENT] An AgentLoop instance is required");
|
|
82
84
|
this._loop = agentOptions.loop;
|
|
83
85
|
this._tools = agentOptions.tools ?? [];
|
|
86
|
+
this._identity = agentOptions.identity;
|
|
84
87
|
this.currentChat = import_chat.Chat.withDefaults(this._loop.name);
|
|
85
88
|
}
|
|
86
89
|
get tools() {
|
|
@@ -95,8 +98,9 @@ class Agent {
|
|
|
95
98
|
get lastAssistantAnswer() {
|
|
96
99
|
return this.currentChat.lastAnswer;
|
|
97
100
|
}
|
|
98
|
-
async run(
|
|
101
|
+
async run(props) {
|
|
99
102
|
try {
|
|
103
|
+
const { input, options, currentUser, currentSession } = props || {};
|
|
100
104
|
const { chatId, message } = input || {};
|
|
101
105
|
this.logger.debug(input, "[AGENT] Agent started");
|
|
102
106
|
if (!this._loop?.nodes || !this._loop?.initialNode) throw new Error("[AGENT] Loop is missing");
|
|
@@ -108,6 +112,7 @@ class Agent {
|
|
|
108
112
|
this.currentUser = currentUser;
|
|
109
113
|
this.currentSession = currentSession;
|
|
110
114
|
this.currentMessage = message;
|
|
115
|
+
this.chatOptions = options;
|
|
111
116
|
this.answerId = new (require("mongodb")).ObjectId().toString();
|
|
112
117
|
await this.preRunner(chatId);
|
|
113
118
|
await this.runLoop();
|
|
@@ -149,6 +154,10 @@ class Agent {
|
|
|
149
154
|
role: "user",
|
|
150
155
|
content: this.currentMessage
|
|
151
156
|
});
|
|
157
|
+
if (this.chatOptions?.notifyOnCompletion) this.currentChat.settings?.setNotifyOnCompletion(true);
|
|
158
|
+
if (this.chatOptions?.isPrivateSession) this.currentChat.settings?.setIsPrivateSession(true);
|
|
159
|
+
if (this.chatOptions?.modelName) this.currentChat.settings?.setModelName(this.chatOptions.modelName);
|
|
160
|
+
if (this.chatOptions?.loopName) this.currentChat.settings?.setLoopName(this.chatOptions.loopName);
|
|
152
161
|
this.currentChat.state?.setStatus(import_agent_state.AgentStatus.PROCESSING);
|
|
153
162
|
this.currentChat.state?.setCurrentActivity("Starting...");
|
|
154
163
|
await this.saveChat({ resetStop: true });
|
|
@@ -275,6 +284,7 @@ class Agent {
|
|
|
275
284
|
buildRunContext() {
|
|
276
285
|
const sessionId = this.currentChat._id?.toString() ?? "";
|
|
277
286
|
return {
|
|
287
|
+
identity: this._identity,
|
|
278
288
|
task: this.currentChat.activeTask,
|
|
279
289
|
chat: this.currentChat,
|
|
280
290
|
currentUser: this.currentUser,
|
package/dist/agent/agent.mjs
CHANGED
|
@@ -21,11 +21,13 @@ class Agent {
|
|
|
21
21
|
chatRepository = container.resolve(ChatRepository);
|
|
22
22
|
logger = new Logger();
|
|
23
23
|
_loop;
|
|
24
|
+
_identity;
|
|
24
25
|
_tools;
|
|
25
26
|
_mcps = [];
|
|
26
27
|
_preHooks = [];
|
|
27
28
|
_postHooks = [];
|
|
28
29
|
currentChat;
|
|
30
|
+
chatOptions;
|
|
29
31
|
currentUser;
|
|
30
32
|
currentSession;
|
|
31
33
|
currentMessage = "";
|
|
@@ -58,6 +60,7 @@ class Agent {
|
|
|
58
60
|
if (!agentOptions?.loop) throw new Error("[AGENT] An AgentLoop instance is required");
|
|
59
61
|
this._loop = agentOptions.loop;
|
|
60
62
|
this._tools = agentOptions.tools ?? [];
|
|
63
|
+
this._identity = agentOptions.identity;
|
|
61
64
|
this.currentChat = Chat.withDefaults(this._loop.name);
|
|
62
65
|
}
|
|
63
66
|
get tools() {
|
|
@@ -72,8 +75,9 @@ class Agent {
|
|
|
72
75
|
get lastAssistantAnswer() {
|
|
73
76
|
return this.currentChat.lastAnswer;
|
|
74
77
|
}
|
|
75
|
-
async run(
|
|
78
|
+
async run(props) {
|
|
76
79
|
try {
|
|
80
|
+
const { input, options, currentUser, currentSession } = props || {};
|
|
77
81
|
const { chatId, message } = input || {};
|
|
78
82
|
this.logger.debug(input, "[AGENT] Agent started");
|
|
79
83
|
if (!this._loop?.nodes || !this._loop?.initialNode) throw new Error("[AGENT] Loop is missing");
|
|
@@ -85,6 +89,7 @@ class Agent {
|
|
|
85
89
|
this.currentUser = currentUser;
|
|
86
90
|
this.currentSession = currentSession;
|
|
87
91
|
this.currentMessage = message;
|
|
92
|
+
this.chatOptions = options;
|
|
88
93
|
this.answerId = new (require("mongodb")).ObjectId().toString();
|
|
89
94
|
await this.preRunner(chatId);
|
|
90
95
|
await this.runLoop();
|
|
@@ -126,6 +131,10 @@ class Agent {
|
|
|
126
131
|
role: "user",
|
|
127
132
|
content: this.currentMessage
|
|
128
133
|
});
|
|
134
|
+
if (this.chatOptions?.notifyOnCompletion) this.currentChat.settings?.setNotifyOnCompletion(true);
|
|
135
|
+
if (this.chatOptions?.isPrivateSession) this.currentChat.settings?.setIsPrivateSession(true);
|
|
136
|
+
if (this.chatOptions?.modelName) this.currentChat.settings?.setModelName(this.chatOptions.modelName);
|
|
137
|
+
if (this.chatOptions?.loopName) this.currentChat.settings?.setLoopName(this.chatOptions.loopName);
|
|
129
138
|
this.currentChat.state?.setStatus(AgentStatus.PROCESSING);
|
|
130
139
|
this.currentChat.state?.setCurrentActivity("Starting...");
|
|
131
140
|
await this.saveChat({ resetStop: true });
|
|
@@ -252,6 +261,7 @@ class Agent {
|
|
|
252
261
|
buildRunContext() {
|
|
253
262
|
const sessionId = this.currentChat._id?.toString() ?? "";
|
|
254
263
|
return {
|
|
264
|
+
identity: this._identity,
|
|
255
265
|
task: this.currentChat.activeTask,
|
|
256
266
|
chat: this.currentChat,
|
|
257
267
|
currentUser: this.currentUser,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
1
|
import type { KnownProvider, Message, AssistantMessage } from '@mariozechner/pi-ai';
|
|
3
2
|
import { CurrentUser } from '../common/base/index.js';
|
|
4
3
|
export declare class LLMClient {
|
|
@@ -12,7 +11,7 @@ export declare class LLMClient {
|
|
|
12
11
|
private formatMessagesForLog;
|
|
13
12
|
}
|
|
14
13
|
export interface LLMCompletionParams {
|
|
15
|
-
|
|
14
|
+
origin: string;
|
|
16
15
|
sessionId: string;
|
|
17
16
|
answerId: string;
|
|
18
17
|
currentUser?: CurrentUser;
|
|
@@ -23,7 +22,7 @@ export interface LLMCompletionParams {
|
|
|
23
22
|
temperature?: number;
|
|
24
23
|
}
|
|
25
24
|
export interface LLMPostResponseParams {
|
|
26
|
-
|
|
25
|
+
origin: string;
|
|
27
26
|
sessionId: string;
|
|
28
27
|
answerId: string;
|
|
29
28
|
currentUser?: CurrentUser;
|
|
@@ -31,13 +31,11 @@ __export(llm_client_exports, {
|
|
|
31
31
|
LLMClient: () => LLMClient
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(llm_client_exports);
|
|
34
|
-
var import_reflect_metadata = require("reflect-metadata");
|
|
35
|
-
var import_tsyringe = require("tsyringe");
|
|
36
34
|
var import_langfuse = require("langfuse");
|
|
37
35
|
var import_secret_manager = require("../common/utils/secret-manager.js");
|
|
38
36
|
var import_logger = require("../common/logger/index.js");
|
|
39
37
|
var import_helpers = require("../common/helpers/index.js");
|
|
40
|
-
var
|
|
38
|
+
var import_llmcalls = require("../services/llmcalls/index.js");
|
|
41
39
|
class LLMClient {
|
|
42
40
|
logger = new import_logger.Logger();
|
|
43
41
|
langfuse;
|
|
@@ -58,7 +56,7 @@ class LLMClient {
|
|
|
58
56
|
async complete(params) {
|
|
59
57
|
const { getModel, complete } = await import("@mariozechner/pi-ai");
|
|
60
58
|
const {
|
|
61
|
-
|
|
59
|
+
origin,
|
|
62
60
|
sessionId,
|
|
63
61
|
answerId,
|
|
64
62
|
currentUser,
|
|
@@ -74,7 +72,7 @@ class LLMClient {
|
|
|
74
72
|
messages
|
|
75
73
|
};
|
|
76
74
|
this.logger.debug({
|
|
77
|
-
|
|
75
|
+
origin,
|
|
78
76
|
context: {
|
|
79
77
|
...context,
|
|
80
78
|
messages: this.formatMessagesForLog(messages)
|
|
@@ -82,10 +80,10 @@ class LLMClient {
|
|
|
82
80
|
}, "[LLM Service] context");
|
|
83
81
|
const trace = this.langfuseEnabled ? this.langfuse.trace({
|
|
84
82
|
sessionId,
|
|
85
|
-
name:
|
|
83
|
+
name: origin,
|
|
86
84
|
userId: currentUser?.userId,
|
|
87
85
|
metadata: {
|
|
88
|
-
|
|
86
|
+
origin,
|
|
89
87
|
email: currentUser?.email,
|
|
90
88
|
sessionId
|
|
91
89
|
}
|
|
@@ -110,13 +108,13 @@ class LLMClient {
|
|
|
110
108
|
});
|
|
111
109
|
if (this.langfuseEnabled) await this.langfuse.flushAsync();
|
|
112
110
|
this.logger.debug({
|
|
113
|
-
|
|
111
|
+
origin,
|
|
114
112
|
response: {
|
|
115
113
|
...response,
|
|
116
114
|
content: this.formatContentForLog(response?.content)
|
|
117
115
|
}
|
|
118
116
|
}, "[LLM Service] Response");
|
|
119
|
-
await this.postResponse({
|
|
117
|
+
await this.postResponse({ origin, sessionId, answerId, currentUser, response });
|
|
120
118
|
return response;
|
|
121
119
|
} catch (error) {
|
|
122
120
|
generation?.end({
|
|
@@ -128,11 +126,10 @@ class LLMClient {
|
|
|
128
126
|
}
|
|
129
127
|
}
|
|
130
128
|
async postResponse(params) {
|
|
131
|
-
const {
|
|
132
|
-
|
|
133
|
-
await createLLMCallUseCase.execute({
|
|
129
|
+
const { origin, sessionId, answerId, currentUser, response } = params ?? {};
|
|
130
|
+
await (0, import_llmcalls.createLLMCall)({
|
|
134
131
|
payload: {
|
|
135
|
-
|
|
132
|
+
origin,
|
|
136
133
|
sessionId,
|
|
137
134
|
answerId,
|
|
138
135
|
response,
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import "../chunk-CF3WOMB3.mjs";
|
|
2
|
-
import "reflect-metadata";
|
|
3
|
-
import { container } from "tsyringe";
|
|
4
2
|
import { Langfuse } from "langfuse";
|
|
5
3
|
import { secretManager } from "../common/utils/secret-manager.js";
|
|
6
4
|
import { Logger } from "../common/logger/index.js";
|
|
7
5
|
import { extractJSON } from "../common/helpers/index.js";
|
|
8
|
-
import {
|
|
6
|
+
import { createLLMCall } from "../services/llmcalls/index.js";
|
|
9
7
|
class LLMClient {
|
|
10
8
|
logger = new Logger();
|
|
11
9
|
langfuse;
|
|
@@ -26,7 +24,7 @@ class LLMClient {
|
|
|
26
24
|
async complete(params) {
|
|
27
25
|
const { getModel, complete } = await import("@mariozechner/pi-ai");
|
|
28
26
|
const {
|
|
29
|
-
|
|
27
|
+
origin,
|
|
30
28
|
sessionId,
|
|
31
29
|
answerId,
|
|
32
30
|
currentUser,
|
|
@@ -42,7 +40,7 @@ class LLMClient {
|
|
|
42
40
|
messages
|
|
43
41
|
};
|
|
44
42
|
this.logger.debug({
|
|
45
|
-
|
|
43
|
+
origin,
|
|
46
44
|
context: {
|
|
47
45
|
...context,
|
|
48
46
|
messages: this.formatMessagesForLog(messages)
|
|
@@ -50,10 +48,10 @@ class LLMClient {
|
|
|
50
48
|
}, "[LLM Service] context");
|
|
51
49
|
const trace = this.langfuseEnabled ? this.langfuse.trace({
|
|
52
50
|
sessionId,
|
|
53
|
-
name:
|
|
51
|
+
name: origin,
|
|
54
52
|
userId: currentUser?.userId,
|
|
55
53
|
metadata: {
|
|
56
|
-
|
|
54
|
+
origin,
|
|
57
55
|
email: currentUser?.email,
|
|
58
56
|
sessionId
|
|
59
57
|
}
|
|
@@ -78,13 +76,13 @@ class LLMClient {
|
|
|
78
76
|
});
|
|
79
77
|
if (this.langfuseEnabled) await this.langfuse.flushAsync();
|
|
80
78
|
this.logger.debug({
|
|
81
|
-
|
|
79
|
+
origin,
|
|
82
80
|
response: {
|
|
83
81
|
...response,
|
|
84
82
|
content: this.formatContentForLog(response?.content)
|
|
85
83
|
}
|
|
86
84
|
}, "[LLM Service] Response");
|
|
87
|
-
await this.postResponse({
|
|
85
|
+
await this.postResponse({ origin, sessionId, answerId, currentUser, response });
|
|
88
86
|
return response;
|
|
89
87
|
} catch (error) {
|
|
90
88
|
generation?.end({
|
|
@@ -96,11 +94,10 @@ class LLMClient {
|
|
|
96
94
|
}
|
|
97
95
|
}
|
|
98
96
|
async postResponse(params) {
|
|
99
|
-
const {
|
|
100
|
-
|
|
101
|
-
await createLLMCallUseCase.execute({
|
|
97
|
+
const { origin, sessionId, answerId, currentUser, response } = params ?? {};
|
|
98
|
+
await createLLMCall({
|
|
102
99
|
payload: {
|
|
103
|
-
|
|
100
|
+
origin,
|
|
104
101
|
sessionId,
|
|
105
102
|
answerId,
|
|
106
103
|
response,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './logger';
|
|
@@ -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 common_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(common_exports);
|
|
18
|
+
__reExport(common_exports, require("./logger"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./logger")
|
|
22
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./logger";
|
|
@@ -55,9 +55,11 @@ class PlanExecuteLoop extends import_agent.AgentLoop {
|
|
|
55
55
|
async fastResponder(ctx) {
|
|
56
56
|
ctx.chat.state?.setCurrentActivity("Analyzing requirement...");
|
|
57
57
|
const chat_history = ctx.chat.lastHistoryMessages();
|
|
58
|
+
const agentIdentity = ctx.identity;
|
|
58
59
|
const result = await import_skills.fastResponder.run({
|
|
59
60
|
...ctx.skillParams,
|
|
60
61
|
contextInjection: {
|
|
62
|
+
...agentIdentity && Object.keys(agentIdentity)?.length ? { agentIdentity } : {},
|
|
61
63
|
...chat_history?.length ? { chat_history } : {}
|
|
62
64
|
}
|
|
63
65
|
});
|
|
@@ -40,9 +40,11 @@ class PlanExecuteLoop extends AgentLoop {
|
|
|
40
40
|
async fastResponder(ctx) {
|
|
41
41
|
ctx.chat.state?.setCurrentActivity("Analyzing requirement...");
|
|
42
42
|
const chat_history = ctx.chat.lastHistoryMessages();
|
|
43
|
+
const agentIdentity = ctx.identity;
|
|
43
44
|
const result = await fastResponder.run({
|
|
44
45
|
...ctx.skillParams,
|
|
45
46
|
contextInjection: {
|
|
47
|
+
...agentIdentity && Object.keys(agentIdentity)?.length ? { agentIdentity } : {},
|
|
46
48
|
...chat_history?.length ? { chat_history } : {}
|
|
47
49
|
}
|
|
48
50
|
});
|
|
@@ -31,11 +31,6 @@ const fastResponder = new import_skill.Skill({
|
|
|
31
31
|
systemInstructions: {
|
|
32
32
|
instruction_set: {
|
|
33
33
|
goal: "Provide general assistance in a friendly, empathetic, and natural manner as a close companion.",
|
|
34
|
-
identity: {
|
|
35
|
-
name: "Sofi",
|
|
36
|
-
gender: "Female",
|
|
37
|
-
role: "Personal assistant and daily companion"
|
|
38
|
-
},
|
|
39
34
|
soul: {
|
|
40
35
|
tone: "Warm, fluid, and enthusiastic, and empathetic",
|
|
41
36
|
style: "Conversational and natural, avoiding overly formal language",
|
|
@@ -9,11 +9,6 @@ const fastResponder = new Skill({
|
|
|
9
9
|
systemInstructions: {
|
|
10
10
|
instruction_set: {
|
|
11
11
|
goal: "Provide general assistance in a friendly, empathetic, and natural manner as a close companion.",
|
|
12
|
-
identity: {
|
|
13
|
-
name: "Sofi",
|
|
14
|
-
gender: "Female",
|
|
15
|
-
role: "Personal assistant and daily companion"
|
|
16
|
-
},
|
|
17
12
|
soul: {
|
|
18
13
|
tone: "Warm, fluid, and enthusiastic, and empathetic",
|
|
19
14
|
style: "Conversational and natural, avoiding overly formal language",
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
export interface ChatSettingsProps {
|
|
2
2
|
notifyOnCompletion?: boolean;
|
|
3
|
+
isPrivateSession?: boolean;
|
|
3
4
|
modelName?: string;
|
|
4
5
|
loopName?: string;
|
|
5
6
|
}
|
|
6
7
|
export declare class ChatSettings {
|
|
7
8
|
private readonly props;
|
|
8
9
|
notifyOnCompletion?: boolean | undefined;
|
|
10
|
+
isPrivateSession?: boolean | undefined;
|
|
9
11
|
modelName?: string | undefined;
|
|
10
12
|
loopName?: string | undefined;
|
|
11
|
-
constructor(props: ChatSettingsProps, notifyOnCompletion?: boolean | undefined, modelName?: string | undefined, loopName?: string | undefined);
|
|
13
|
+
constructor(props: ChatSettingsProps, notifyOnCompletion?: boolean | undefined, isPrivateSession?: boolean | undefined, modelName?: string | undefined, loopName?: string | undefined);
|
|
12
14
|
static fromJSON(props: ChatSettingsProps): ChatSettings;
|
|
13
15
|
toJSON(): ChatSettingsProps;
|
|
14
16
|
setLoopName(loopName: string): void;
|
|
15
17
|
setModelName(modelName: string): void;
|
|
16
18
|
setNotifyOnCompletion(notifyOnCompletion: boolean): void;
|
|
19
|
+
setIsPrivateSession(isPrivateSession: boolean): void;
|
|
17
20
|
}
|
|
@@ -22,20 +22,23 @@ __export(chat_settings_entity_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(chat_settings_entity_exports);
|
|
24
24
|
class ChatSettings {
|
|
25
|
-
constructor(props, notifyOnCompletion, modelName, loopName) {
|
|
25
|
+
constructor(props, notifyOnCompletion, isPrivateSession, modelName, loopName) {
|
|
26
26
|
this.props = props;
|
|
27
27
|
this.notifyOnCompletion = notifyOnCompletion;
|
|
28
|
+
this.isPrivateSession = isPrivateSession;
|
|
28
29
|
this.modelName = modelName;
|
|
29
30
|
this.loopName = loopName;
|
|
30
31
|
}
|
|
31
32
|
props;
|
|
32
33
|
notifyOnCompletion;
|
|
34
|
+
isPrivateSession;
|
|
33
35
|
modelName;
|
|
34
36
|
loopName;
|
|
35
37
|
static fromJSON(props) {
|
|
36
38
|
return new ChatSettings(
|
|
37
39
|
props,
|
|
38
40
|
props.notifyOnCompletion,
|
|
41
|
+
props.isPrivateSession,
|
|
39
42
|
props.modelName,
|
|
40
43
|
props.loopName
|
|
41
44
|
);
|
|
@@ -43,6 +46,7 @@ class ChatSettings {
|
|
|
43
46
|
toJSON() {
|
|
44
47
|
return {
|
|
45
48
|
notifyOnCompletion: this.notifyOnCompletion,
|
|
49
|
+
isPrivateSession: this.isPrivateSession,
|
|
46
50
|
modelName: this.modelName,
|
|
47
51
|
loopName: this.loopName
|
|
48
52
|
};
|
|
@@ -56,6 +60,9 @@ class ChatSettings {
|
|
|
56
60
|
setNotifyOnCompletion(notifyOnCompletion) {
|
|
57
61
|
this.notifyOnCompletion = notifyOnCompletion;
|
|
58
62
|
}
|
|
63
|
+
setIsPrivateSession(isPrivateSession) {
|
|
64
|
+
this.isPrivateSession = isPrivateSession;
|
|
65
|
+
}
|
|
59
66
|
}
|
|
60
67
|
// Annotate the CommonJS export names for ESM import in node:
|
|
61
68
|
0 && (module.exports = {
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import "../../../chunk-CF3WOMB3.mjs";
|
|
2
2
|
class ChatSettings {
|
|
3
|
-
constructor(props, notifyOnCompletion, modelName, loopName) {
|
|
3
|
+
constructor(props, notifyOnCompletion, isPrivateSession, modelName, loopName) {
|
|
4
4
|
this.props = props;
|
|
5
5
|
this.notifyOnCompletion = notifyOnCompletion;
|
|
6
|
+
this.isPrivateSession = isPrivateSession;
|
|
6
7
|
this.modelName = modelName;
|
|
7
8
|
this.loopName = loopName;
|
|
8
9
|
}
|
|
9
10
|
props;
|
|
10
11
|
notifyOnCompletion;
|
|
12
|
+
isPrivateSession;
|
|
11
13
|
modelName;
|
|
12
14
|
loopName;
|
|
13
15
|
static fromJSON(props) {
|
|
14
16
|
return new ChatSettings(
|
|
15
17
|
props,
|
|
16
18
|
props.notifyOnCompletion,
|
|
19
|
+
props.isPrivateSession,
|
|
17
20
|
props.modelName,
|
|
18
21
|
props.loopName
|
|
19
22
|
);
|
|
@@ -21,6 +24,7 @@ class ChatSettings {
|
|
|
21
24
|
toJSON() {
|
|
22
25
|
return {
|
|
23
26
|
notifyOnCompletion: this.notifyOnCompletion,
|
|
27
|
+
isPrivateSession: this.isPrivateSession,
|
|
24
28
|
modelName: this.modelName,
|
|
25
29
|
loopName: this.loopName
|
|
26
30
|
};
|
|
@@ -34,6 +38,9 @@ class ChatSettings {
|
|
|
34
38
|
setNotifyOnCompletion(notifyOnCompletion) {
|
|
35
39
|
this.notifyOnCompletion = notifyOnCompletion;
|
|
36
40
|
}
|
|
41
|
+
setIsPrivateSession(isPrivateSession) {
|
|
42
|
+
this.isPrivateSession = isPrivateSession;
|
|
43
|
+
}
|
|
37
44
|
}
|
|
38
45
|
export {
|
|
39
46
|
ChatSettings
|
|
@@ -2,7 +2,7 @@ import { ObjectId } from 'mongodb';
|
|
|
2
2
|
import type { AssistantMessage } from '@mariozechner/pi-ai';
|
|
3
3
|
import { BaseEntity, BaseEntityProps } from '../../../common/base/base.entity.js';
|
|
4
4
|
export interface LLMCallProps extends BaseEntityProps {
|
|
5
|
-
|
|
5
|
+
origin?: string;
|
|
6
6
|
answerId?: string | ObjectId;
|
|
7
7
|
sessionId?: string | ObjectId;
|
|
8
8
|
costInUsd?: number;
|
|
@@ -10,14 +10,14 @@ export interface LLMCallProps extends BaseEntityProps {
|
|
|
10
10
|
}
|
|
11
11
|
export declare class LLMCall extends BaseEntity {
|
|
12
12
|
private readonly props;
|
|
13
|
-
|
|
13
|
+
origin?: string | undefined;
|
|
14
14
|
answerId?: ObjectId | undefined;
|
|
15
15
|
sessionId?: ObjectId | undefined;
|
|
16
16
|
costInUsd?: number | undefined;
|
|
17
17
|
response?: AssistantMessage | undefined;
|
|
18
18
|
static fromJSON(props: LLMCallProps): LLMCall;
|
|
19
|
-
constructor(props: LLMCallProps,
|
|
19
|
+
constructor(props: LLMCallProps, origin?: string | undefined, answerId?: ObjectId | undefined, sessionId?: ObjectId | undefined, costInUsd?: number | undefined, response?: AssistantMessage | undefined);
|
|
20
20
|
toJSON(): LLMCallProps;
|
|
21
21
|
setResponse(response: AssistantMessage): void;
|
|
22
|
-
|
|
22
|
+
setOrigin(origin: string): void;
|
|
23
23
|
}
|
|
@@ -23,17 +23,17 @@ __export(llmcall_entity_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(llmcall_entity_exports);
|
|
24
24
|
var import_base = require("../../../common/base/base.entity.js");
|
|
25
25
|
class LLMCall extends import_base.BaseEntity {
|
|
26
|
-
constructor(props,
|
|
26
|
+
constructor(props, origin, answerId, sessionId, costInUsd, response) {
|
|
27
27
|
super(props);
|
|
28
28
|
this.props = props;
|
|
29
|
-
this.
|
|
29
|
+
this.origin = origin;
|
|
30
30
|
this.answerId = answerId;
|
|
31
31
|
this.sessionId = sessionId;
|
|
32
32
|
this.costInUsd = costInUsd;
|
|
33
33
|
this.response = response;
|
|
34
34
|
}
|
|
35
35
|
props;
|
|
36
|
-
|
|
36
|
+
origin;
|
|
37
37
|
answerId;
|
|
38
38
|
sessionId;
|
|
39
39
|
costInUsd;
|
|
@@ -41,7 +41,7 @@ class LLMCall extends import_base.BaseEntity {
|
|
|
41
41
|
static fromJSON(props) {
|
|
42
42
|
return new LLMCall(
|
|
43
43
|
props,
|
|
44
|
-
props.
|
|
44
|
+
props.origin || void 0,
|
|
45
45
|
import_base.BaseEntity.toObjectId(props.answerId),
|
|
46
46
|
import_base.BaseEntity.toObjectId(props.sessionId),
|
|
47
47
|
props.costInUsd ? Number(props.costInUsd) : void 0,
|
|
@@ -51,7 +51,7 @@ class LLMCall extends import_base.BaseEntity {
|
|
|
51
51
|
toJSON() {
|
|
52
52
|
return {
|
|
53
53
|
...super.toJSON(),
|
|
54
|
-
|
|
54
|
+
origin: this.origin,
|
|
55
55
|
answerId: this.answerId,
|
|
56
56
|
sessionId: this.sessionId,
|
|
57
57
|
costInUsd: this.costInUsd,
|
|
@@ -61,8 +61,8 @@ class LLMCall extends import_base.BaseEntity {
|
|
|
61
61
|
setResponse(response) {
|
|
62
62
|
this.response = response;
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
this.
|
|
64
|
+
setOrigin(origin) {
|
|
65
|
+
this.origin = origin;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import "../../../chunk-CF3WOMB3.mjs";
|
|
2
2
|
import { BaseEntity } from "../../../common/base/base.entity.js";
|
|
3
3
|
class LLMCall extends BaseEntity {
|
|
4
|
-
constructor(props,
|
|
4
|
+
constructor(props, origin, answerId, sessionId, costInUsd, response) {
|
|
5
5
|
super(props);
|
|
6
6
|
this.props = props;
|
|
7
|
-
this.
|
|
7
|
+
this.origin = origin;
|
|
8
8
|
this.answerId = answerId;
|
|
9
9
|
this.sessionId = sessionId;
|
|
10
10
|
this.costInUsd = costInUsd;
|
|
11
11
|
this.response = response;
|
|
12
12
|
}
|
|
13
13
|
props;
|
|
14
|
-
|
|
14
|
+
origin;
|
|
15
15
|
answerId;
|
|
16
16
|
sessionId;
|
|
17
17
|
costInUsd;
|
|
@@ -19,7 +19,7 @@ class LLMCall extends BaseEntity {
|
|
|
19
19
|
static fromJSON(props) {
|
|
20
20
|
return new LLMCall(
|
|
21
21
|
props,
|
|
22
|
-
props.
|
|
22
|
+
props.origin || void 0,
|
|
23
23
|
BaseEntity.toObjectId(props.answerId),
|
|
24
24
|
BaseEntity.toObjectId(props.sessionId),
|
|
25
25
|
props.costInUsd ? Number(props.costInUsd) : void 0,
|
|
@@ -29,7 +29,7 @@ class LLMCall extends BaseEntity {
|
|
|
29
29
|
toJSON() {
|
|
30
30
|
return {
|
|
31
31
|
...super.toJSON(),
|
|
32
|
-
|
|
32
|
+
origin: this.origin,
|
|
33
33
|
answerId: this.answerId,
|
|
34
34
|
sessionId: this.sessionId,
|
|
35
35
|
costInUsd: this.costInUsd,
|
|
@@ -39,8 +39,8 @@ class LLMCall extends BaseEntity {
|
|
|
39
39
|
setResponse(response) {
|
|
40
40
|
this.response = response;
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
this.
|
|
42
|
+
setOrigin(origin) {
|
|
43
|
+
this.origin = origin;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
export {
|
|
@@ -105,13 +105,19 @@ let GetLLMUsageUseCase = class extends import_base.BaseUseCase {
|
|
|
105
105
|
_id: "$ownerId",
|
|
106
106
|
totalTokens: { $sum: "$response.usage.totalTokens" }
|
|
107
107
|
}
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
$project: {
|
|
111
|
+
_id: 0,
|
|
112
|
+
userId: "$_id",
|
|
113
|
+
totalTokens: 1
|
|
114
|
+
}
|
|
108
115
|
}
|
|
109
116
|
];
|
|
110
117
|
const result = await this.llmCallRepository?._.aggregate(pipeline);
|
|
111
118
|
return {
|
|
112
119
|
data: {
|
|
113
|
-
...result[0]
|
|
114
|
-
tokensLimit: 5e6
|
|
120
|
+
...result[0]
|
|
115
121
|
}
|
|
116
122
|
};
|
|
117
123
|
}
|
|
@@ -77,13 +77,19 @@ let GetLLMUsageUseCase = class extends BaseUseCase {
|
|
|
77
77
|
_id: "$ownerId",
|
|
78
78
|
totalTokens: { $sum: "$response.usage.totalTokens" }
|
|
79
79
|
}
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
$project: {
|
|
83
|
+
_id: 0,
|
|
84
|
+
userId: "$_id",
|
|
85
|
+
totalTokens: 1
|
|
86
|
+
}
|
|
80
87
|
}
|
|
81
88
|
];
|
|
82
89
|
const result = await this.llmCallRepository?._.aggregate(pipeline);
|
|
83
90
|
return {
|
|
84
91
|
data: {
|
|
85
|
-
...result[0]
|
|
86
|
-
tokensLimit: 5e6
|
|
92
|
+
...result[0]
|
|
87
93
|
}
|
|
88
94
|
};
|
|
89
95
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { Params as LParams, Output as LOutput } from './lambdas/get-llm-usage';
|
|
3
|
+
import { Params as CParams, Output as COutput } from './lambdas/create-llmcall';
|
|
3
4
|
export declare function getLLMUsage(props: LParams): Promise<LOutput>;
|
|
5
|
+
export declare function createLLMCall(props: CParams): Promise<COutput>;
|
|
@@ -18,17 +18,24 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var module_exports = {};
|
|
20
20
|
__export(module_exports, {
|
|
21
|
+
createLLMCall: () => createLLMCall,
|
|
21
22
|
getLLMUsage: () => getLLMUsage
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(module_exports);
|
|
24
25
|
var import_reflect_metadata = require("reflect-metadata");
|
|
25
26
|
var import_tsyringe = require("tsyringe");
|
|
26
27
|
var import_get_llm_usage = require("./lambdas/get-llm-usage");
|
|
28
|
+
var import_create_llmcall = require("./lambdas/create-llmcall");
|
|
27
29
|
async function getLLMUsage(props) {
|
|
28
30
|
const getLLMUsageUseCase = import_tsyringe.container.resolve(import_get_llm_usage.GetLLMUsageUseCase);
|
|
29
31
|
return getLLMUsageUseCase.execute(props);
|
|
30
32
|
}
|
|
33
|
+
async function createLLMCall(props) {
|
|
34
|
+
const createLLMCall2 = import_tsyringe.container.resolve(import_create_llmcall.CreateLLMCallUseCase);
|
|
35
|
+
return createLLMCall2.execute(props);
|
|
36
|
+
}
|
|
31
37
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
38
|
0 && (module.exports = {
|
|
39
|
+
createLLMCall,
|
|
33
40
|
getLLMUsage
|
|
34
41
|
});
|
|
@@ -2,10 +2,16 @@ import "../../chunk-CF3WOMB3.mjs";
|
|
|
2
2
|
import "reflect-metadata";
|
|
3
3
|
import { container } from "tsyringe";
|
|
4
4
|
import { GetLLMUsageUseCase } from "./lambdas/get-llm-usage";
|
|
5
|
+
import { CreateLLMCallUseCase } from "./lambdas/create-llmcall";
|
|
5
6
|
async function getLLMUsage(props) {
|
|
6
7
|
const getLLMUsageUseCase = container.resolve(GetLLMUsageUseCase);
|
|
7
8
|
return getLLMUsageUseCase.execute(props);
|
|
8
9
|
}
|
|
10
|
+
async function createLLMCall(props) {
|
|
11
|
+
const createLLMCall2 = container.resolve(CreateLLMCallUseCase);
|
|
12
|
+
return createLLMCall2.execute(props);
|
|
13
|
+
}
|
|
9
14
|
export {
|
|
15
|
+
createLLMCall,
|
|
10
16
|
getLLMUsage
|
|
11
17
|
};
|
package/dist/skills/skill.js
CHANGED
package/dist/skills/skill.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openloops",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.24",
|
|
4
4
|
"description": "Framework to build AI Agents",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Jose Barcos",
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
"types": "./dist/common/base/index.d.ts",
|
|
20
20
|
"default": "./dist/common/base/index.js"
|
|
21
21
|
},
|
|
22
|
+
"./common": {
|
|
23
|
+
"types": "./dist/common/index.d.ts",
|
|
24
|
+
"default": "./dist/common/index.js"
|
|
25
|
+
},
|
|
22
26
|
"./core": {
|
|
23
27
|
"types": "./dist/agent/index.d.ts",
|
|
24
28
|
"default": "./dist/agent/index.js"
|