@agentuity/runtime 0.0.92 → 0.0.94
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/dist/_standalone.d.ts.map +1 -1
- package/dist/_standalone.js +27 -21
- package/dist/_standalone.js.map +1 -1
- package/package.json +5 -5
- package/src/_standalone.ts +74 -66
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_standalone.d.ts","sourceRoot":"","sources":["../src/_standalone.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqC,KAAK,OAAO,EAAS,MAAM,oBAAoB,CAAC;AAE5F,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"_standalone.d.ts","sourceRoot":"","sources":["../src/_standalone.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqC,KAAK,OAAO,EAAS,MAAM,oBAAoB,CAAC;AAE5F,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrF,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASjD;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACxC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,iBAAiB,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;CACjE;AAED;;GAEG;AACH,MAAM,W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M,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC;CA+O1E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EACnE,OAAO,CAAC,EAAE,wBAAwB,GAChC,sBAAsB,CAAC,aAAa,EAAE,OAAO,EAAE,SAAS,CAAC,CAE3D"}
|
package/dist/_standalone.js
CHANGED
|
@@ -5,8 +5,8 @@ import { generateId } from './session';
|
|
|
5
5
|
import WaitUntilHandler from './_waituntil';
|
|
6
6
|
import { registerServices } from './_services';
|
|
7
7
|
import { getAgentAsyncLocalStorage } from './_context';
|
|
8
|
-
import { getLogger, getTracer, getAppState
|
|
9
|
-
import { getThreadProvider, getSessionProvider, getSessionEventProvider
|
|
8
|
+
import { getLogger, getTracer, getAppState } from './_server';
|
|
9
|
+
import { getThreadProvider, getSessionProvider, getSessionEventProvider } from './_services';
|
|
10
10
|
import * as runtimeConfig from './_config';
|
|
11
11
|
/**
|
|
12
12
|
* Standalone agent context for executing agents outside of HTTP requests.
|
|
@@ -80,22 +80,26 @@ export class StandaloneAgentContext {
|
|
|
80
80
|
// Session ID will be set properly in invoke() after span is created
|
|
81
81
|
this.sessionId = options?.sessionId ?? 'pending';
|
|
82
82
|
// Thread and session will be restored in invoke()
|
|
83
|
-
this.thread =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
83
|
+
this.thread =
|
|
84
|
+
options?.thread ??
|
|
85
|
+
{
|
|
86
|
+
id: 'pending',
|
|
87
|
+
state: new Map(),
|
|
88
|
+
addEventListener: () => { },
|
|
89
|
+
removeEventListener: () => { },
|
|
90
|
+
destroy: async () => { },
|
|
91
|
+
empty: () => true,
|
|
92
|
+
};
|
|
93
|
+
this.session =
|
|
94
|
+
options?.session ??
|
|
95
|
+
{
|
|
96
|
+
id: 'pending',
|
|
97
|
+
thread: this.thread,
|
|
98
|
+
state: new Map(),
|
|
99
|
+
addEventListener: () => { },
|
|
100
|
+
removeEventListener: () => { },
|
|
101
|
+
serializeUserData: () => undefined,
|
|
102
|
+
};
|
|
99
103
|
// Create isolated runtime state
|
|
100
104
|
this[AGENT_RUNTIME] = {
|
|
101
105
|
agents: new Map(),
|
|
@@ -167,12 +171,14 @@ export class StandaloneAgentContext {
|
|
|
167
171
|
return await trace.getTracer('standalone-agent').startActiveSpan(options?.spanName ?? 'agent-invocation', {
|
|
168
172
|
kind: SpanKind.INTERNAL, // Not HTTP, but internal invocation
|
|
169
173
|
attributes: {
|
|
170
|
-
|
|
174
|
+
trigger: this.trigger,
|
|
171
175
|
},
|
|
172
176
|
}, async (span) => {
|
|
173
177
|
const sctx = span.spanContext();
|
|
174
178
|
// Generate sessionId from traceId if not provided
|
|
175
|
-
invocationSessionId =
|
|
179
|
+
invocationSessionId =
|
|
180
|
+
this.initialSessionId ??
|
|
181
|
+
(sctx?.traceId ? `sess_${sctx.traceId}` : generateId('sess'));
|
|
176
182
|
callContext.sessionId = invocationSessionId;
|
|
177
183
|
// Add to tracestate (like otelMiddleware does)
|
|
178
184
|
// Note: SpanContext.traceState is readonly, so we update it by setting the span with a new context
|
|
@@ -196,7 +202,7 @@ export class StandaloneAgentContext {
|
|
|
196
202
|
// as the span already has the trace state we need for propagation
|
|
197
203
|
trace.setSpan(context.active(), trace.wrapSpanContext({
|
|
198
204
|
...sctx,
|
|
199
|
-
traceState
|
|
205
|
+
traceState,
|
|
200
206
|
}));
|
|
201
207
|
// Restore thread and session (like otelMiddleware does)
|
|
202
208
|
// For standalone contexts, we create a simple thread/session if not provided
|
package/dist/_standalone.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_standalone.js","sourceRoot":"","sources":["../src/_standalone.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAgB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC5F,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"_standalone.js","sourceRoot":"","sources":["../src/_standalone.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAgB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC5F,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGrD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,gBAAgB,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC7F,OAAO,KAAK,aAAa,MAAM,WAAW,CAAC;AAwC3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,OAAO,sBAAsB;IAMlC,4DAA4D;IAC5D,KAAK,GAAc,EAAe,CAAC;IACnC,MAAM,CAAS;IACf,MAAM,CAAsC;IAC5C,EAAE,CAAmB;IACrB,MAAM,CAAiB;IACvB,MAAM,CAAiB;IACvB,MAAM,CAAU;IAChB,GAAG,CAAY;IACf,CAAC,aAAa,CAAC,CAAoB;IAEnC,uFAAuF;IACvF,oFAAoF;IACpF,SAAS,CAAS;IAClB,KAA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e,EAAE,CAAC;wBACtB,IAAI,CAAC;4BACJ,MAAM,eAAe,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;4BAC9C,MAAM,cAAc,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;wBAC7C,CAAC;gCAAS,CAAC;4BACV,IAAI,CAAC,GAAG,EAAE,CAAC;wBACZ,CAAC;oBACF,CAAC;gBACF,CAAC;YACF,CAAC,CACD,CAAC;QACH,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,UAAU,kBAAkB,CACjC,OAAkC;IAElC,OAAO,IAAI,sBAAsB,CAAoC,OAAO,CAAC,CAAC;AAC/E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentuity/runtime",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.94",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"author": "Agentuity employees and contributors",
|
|
6
6
|
"type": "module",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"prepublishOnly": "bun run clean && bun run build"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@agentuity/core": "0.0.
|
|
30
|
-
"@agentuity/schema": "0.0.
|
|
31
|
-
"@agentuity/server": "0.0.
|
|
29
|
+
"@agentuity/core": "0.0.94",
|
|
30
|
+
"@agentuity/schema": "0.0.94",
|
|
31
|
+
"@agentuity/server": "0.0.94",
|
|
32
32
|
"@opentelemetry/api": "^1.9.0",
|
|
33
33
|
"@opentelemetry/api-logs": "^0.207.0",
|
|
34
34
|
"@opentelemetry/auto-instrumentations-node": "^0.66.0",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@types/ws": "^8.5.13"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@agentuity/test-utils": "0.0.
|
|
57
|
+
"@agentuity/test-utils": "0.0.94",
|
|
58
58
|
"@types/bun": "latest",
|
|
59
59
|
"@types/react": "^19.2.2",
|
|
60
60
|
"@types/react-dom": "^19.2.2",
|
package/src/_standalone.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { context, SpanKind, SpanStatusCode, type Context, trace } from '@opentelemetry/api';
|
|
2
2
|
import { TraceState } from '@opentelemetry/core';
|
|
3
|
-
import type {
|
|
4
|
-
KeyValueStorage,
|
|
5
|
-
StreamStorage,
|
|
6
|
-
VectorStorage,
|
|
7
|
-
} from '@agentuity/core';
|
|
3
|
+
import type { KeyValueStorage, StreamStorage, VectorStorage } from '@agentuity/core';
|
|
8
4
|
import type { AgentContext, AgentRegistry, AgentRuntimeState } from './agent';
|
|
9
5
|
import { AGENT_RUNTIME, AGENT_IDS } from './_config';
|
|
10
6
|
import type { Logger } from './logger';
|
|
@@ -13,21 +9,13 @@ import { generateId } from './session';
|
|
|
13
9
|
import WaitUntilHandler from './_waituntil';
|
|
14
10
|
import { registerServices } from './_services';
|
|
15
11
|
import { getAgentAsyncLocalStorage } from './_context';
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
getTracer,
|
|
19
|
-
getAppState,
|
|
20
|
-
} from './_server';
|
|
21
|
-
import {
|
|
22
|
-
getThreadProvider,
|
|
23
|
-
getSessionProvider,
|
|
24
|
-
getSessionEventProvider,
|
|
25
|
-
} from './_services';
|
|
12
|
+
import { getLogger, getTracer, getAppState } from './_server';
|
|
13
|
+
import { getThreadProvider, getSessionProvider, getSessionEventProvider } from './_services';
|
|
26
14
|
import * as runtimeConfig from './_config';
|
|
27
15
|
|
|
28
16
|
/**
|
|
29
17
|
* Options for creating a standalone agent context.
|
|
30
|
-
*
|
|
18
|
+
*
|
|
31
19
|
* Use this when executing agents outside of HTTP requests (Discord bots, cron jobs, etc.)
|
|
32
20
|
*/
|
|
33
21
|
export interface StandaloneContextOptions {
|
|
@@ -65,30 +53,30 @@ export interface InvokeOptions {
|
|
|
65
53
|
|
|
66
54
|
/**
|
|
67
55
|
* Standalone agent context for executing agents outside of HTTP requests.
|
|
68
|
-
*
|
|
56
|
+
*
|
|
69
57
|
* This context provides the same infrastructure as HTTP request contexts:
|
|
70
58
|
* - OpenTelemetry tracing with proper span hierarchy
|
|
71
59
|
* - Session and thread management (save/restore)
|
|
72
60
|
* - Background task handling (waitUntil)
|
|
73
61
|
* - Session event tracking (start/complete)
|
|
74
62
|
* - Access to all services (kv, stream, vector)
|
|
75
|
-
*
|
|
63
|
+
*
|
|
76
64
|
* @example
|
|
77
65
|
* ```typescript
|
|
78
66
|
* import { createAgentContext } from '@agentuity/runtime';
|
|
79
67
|
* import myAgent from './agents/my-agent';
|
|
80
|
-
*
|
|
68
|
+
*
|
|
81
69
|
* // Simple usage:
|
|
82
70
|
* const ctx = createAgentContext();
|
|
83
71
|
* const result = await ctx.invoke(() => myAgent.run(input));
|
|
84
|
-
*
|
|
72
|
+
*
|
|
85
73
|
* // With custom session tracking:
|
|
86
|
-
* const ctx = createAgentContext({
|
|
74
|
+
* const ctx = createAgentContext({
|
|
87
75
|
* sessionId: discordMessage.id,
|
|
88
76
|
* trigger: 'discord'
|
|
89
77
|
* });
|
|
90
78
|
* const result = await ctx.invoke(() => myAgent.run(input));
|
|
91
|
-
*
|
|
79
|
+
*
|
|
92
80
|
* // Reuse context for multiple agents:
|
|
93
81
|
* const ctx = createAgentContext();
|
|
94
82
|
* const result1 = await ctx.invoke(() => agent1.run(input1));
|
|
@@ -111,7 +99,7 @@ export class StandaloneAgentContext<
|
|
|
111
99
|
config: TConfig;
|
|
112
100
|
app: TAppState;
|
|
113
101
|
[AGENT_RUNTIME]: AgentRuntimeState;
|
|
114
|
-
|
|
102
|
+
|
|
115
103
|
// Note: The following are mutable and will be set per-invocation via AsyncLocalStorage
|
|
116
104
|
// They exist on the interface for compatibility but are overwritten during invoke()
|
|
117
105
|
sessionId: string;
|
|
@@ -119,7 +107,7 @@ export class StandaloneAgentContext<
|
|
|
119
107
|
session: Session;
|
|
120
108
|
thread: Thread;
|
|
121
109
|
[AGENT_IDS]?: Set<string>;
|
|
122
|
-
|
|
110
|
+
|
|
123
111
|
// Immutable options stored from constructor
|
|
124
112
|
private readonly parentContext: Context;
|
|
125
113
|
private readonly trigger: import('@agentuity/core').SessionStartEvent['trigger'];
|
|
@@ -147,25 +135,29 @@ export class StandaloneAgentContext<
|
|
|
147
135
|
|
|
148
136
|
// Session ID will be set properly in invoke() after span is created
|
|
149
137
|
this.sessionId = options?.sessionId ?? 'pending';
|
|
150
|
-
|
|
138
|
+
|
|
151
139
|
// Thread and session will be restored in invoke()
|
|
152
|
-
this.thread =
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
140
|
+
this.thread =
|
|
141
|
+
options?.thread ??
|
|
142
|
+
({
|
|
143
|
+
id: 'pending',
|
|
144
|
+
state: new Map(),
|
|
145
|
+
addEventListener: () => {},
|
|
146
|
+
removeEventListener: () => {},
|
|
147
|
+
destroy: async () => {},
|
|
148
|
+
empty: () => true,
|
|
149
|
+
} as Thread);
|
|
150
|
+
|
|
151
|
+
this.session =
|
|
152
|
+
options?.session ??
|
|
153
|
+
({
|
|
154
|
+
id: 'pending',
|
|
155
|
+
thread: this.thread,
|
|
156
|
+
state: new Map(),
|
|
157
|
+
addEventListener: () => {},
|
|
158
|
+
removeEventListener: () => {},
|
|
159
|
+
serializeUserData: () => undefined,
|
|
160
|
+
} as Session);
|
|
169
161
|
|
|
170
162
|
// Create isolated runtime state
|
|
171
163
|
this[AGENT_RUNTIME] = {
|
|
@@ -187,7 +179,7 @@ export class StandaloneAgentContext<
|
|
|
187
179
|
|
|
188
180
|
/**
|
|
189
181
|
* Execute a function within this agent context.
|
|
190
|
-
*
|
|
182
|
+
*
|
|
191
183
|
* This method:
|
|
192
184
|
* 1. Creates an OpenTelemetry span for the invocation
|
|
193
185
|
* 2. Restores/creates session and thread
|
|
@@ -196,16 +188,16 @@ export class StandaloneAgentContext<
|
|
|
196
188
|
* 5. Waits for background tasks (waitUntil)
|
|
197
189
|
* 6. Saves session and thread
|
|
198
190
|
* 7. Sends session complete event
|
|
199
|
-
*
|
|
191
|
+
*
|
|
200
192
|
* @param fn - Function to execute (typically () => agent.run(input))
|
|
201
193
|
* @param options - Optional configuration for the invocation
|
|
202
194
|
* @returns Promise that resolves to the function's return value
|
|
203
|
-
*
|
|
195
|
+
*
|
|
204
196
|
* @example
|
|
205
197
|
* ```typescript
|
|
206
198
|
* const result = await ctx.invoke(() => myAgent.run({ userId: '123' }));
|
|
207
199
|
* ```
|
|
208
|
-
*
|
|
200
|
+
*
|
|
209
201
|
* @example
|
|
210
202
|
* ```typescript
|
|
211
203
|
* // Multiple agents in sequence:
|
|
@@ -220,7 +212,7 @@ export class StandaloneAgentContext<
|
|
|
220
212
|
const sessionProvider = getSessionProvider();
|
|
221
213
|
const sessionEventProvider = getSessionEventProvider();
|
|
222
214
|
const storage = getAgentAsyncLocalStorage();
|
|
223
|
-
|
|
215
|
+
|
|
224
216
|
// Create per-invocation state (prevents race conditions on concurrent calls)
|
|
225
217
|
const waitUntilHandler = new WaitUntilHandler(this.tracer);
|
|
226
218
|
const agentIds = new Set<string>();
|
|
@@ -228,9 +220,13 @@ export class StandaloneAgentContext<
|
|
|
228
220
|
let invocationThread: Thread;
|
|
229
221
|
let invocationSession: Session;
|
|
230
222
|
const invocationState = new Map<string, unknown>();
|
|
231
|
-
|
|
223
|
+
|
|
232
224
|
// Create a per-call context that inherits from this but has isolated mutable state
|
|
233
|
-
const callContext = Object.create(this) as StandaloneAgentContext<
|
|
225
|
+
const callContext = Object.create(this) as StandaloneAgentContext<
|
|
226
|
+
TAgentMap,
|
|
227
|
+
TConfig,
|
|
228
|
+
TAppState
|
|
229
|
+
>;
|
|
234
230
|
callContext.sessionId = invocationSessionId;
|
|
235
231
|
callContext.state = invocationState;
|
|
236
232
|
callContext[AGENT_IDS] = agentIds;
|
|
@@ -246,14 +242,16 @@ export class StandaloneAgentContext<
|
|
|
246
242
|
{
|
|
247
243
|
kind: SpanKind.INTERNAL, // Not HTTP, but internal invocation
|
|
248
244
|
attributes: {
|
|
249
|
-
|
|
245
|
+
trigger: this.trigger,
|
|
250
246
|
},
|
|
251
247
|
},
|
|
252
248
|
async (span) => {
|
|
253
249
|
const sctx = span.spanContext();
|
|
254
|
-
|
|
250
|
+
|
|
255
251
|
// Generate sessionId from traceId if not provided
|
|
256
|
-
invocationSessionId =
|
|
252
|
+
invocationSessionId =
|
|
253
|
+
this.initialSessionId ??
|
|
254
|
+
(sctx?.traceId ? `sess_${sctx.traceId}` : generateId('sess'));
|
|
257
255
|
callContext.sessionId = invocationSessionId;
|
|
258
256
|
|
|
259
257
|
// Add to tracestate (like otelMiddleware does)
|
|
@@ -272,7 +270,7 @@ export class StandaloneAgentContext<
|
|
|
272
270
|
if (isDevMode) {
|
|
273
271
|
traceState = traceState.set('d', '1');
|
|
274
272
|
}
|
|
275
|
-
|
|
273
|
+
|
|
276
274
|
// Update the active context with the new trace state
|
|
277
275
|
// We do this by setting the span in the context with updated trace state
|
|
278
276
|
// Note: This creates a new context but we don't need to use it directly
|
|
@@ -281,7 +279,7 @@ export class StandaloneAgentContext<
|
|
|
281
279
|
context.active(),
|
|
282
280
|
trace.wrapSpanContext({
|
|
283
281
|
...sctx,
|
|
284
|
-
traceState
|
|
282
|
+
traceState,
|
|
285
283
|
})
|
|
286
284
|
);
|
|
287
285
|
|
|
@@ -293,8 +291,11 @@ export class StandaloneAgentContext<
|
|
|
293
291
|
const threadId = genId('thrd');
|
|
294
292
|
invocationThread = new DefaultThread(threadProvider, threadId);
|
|
295
293
|
callContext.thread = invocationThread;
|
|
296
|
-
|
|
297
|
-
invocationSession = await sessionProvider.restore(
|
|
294
|
+
|
|
295
|
+
invocationSession = await sessionProvider.restore(
|
|
296
|
+
invocationThread,
|
|
297
|
+
invocationSessionId
|
|
298
|
+
);
|
|
298
299
|
callContext.session = invocationSession;
|
|
299
300
|
|
|
300
301
|
// Send session start event (if configured)
|
|
@@ -334,7 +335,10 @@ export class StandaloneAgentContext<
|
|
|
334
335
|
waitUntilHandler
|
|
335
336
|
.waitUntilAll(this.logger, invocationSessionId)
|
|
336
337
|
.then(async () => {
|
|
337
|
-
this.logger.debug(
|
|
338
|
+
this.logger.debug(
|
|
339
|
+
'wait until finished for session %s',
|
|
340
|
+
invocationSessionId
|
|
341
|
+
);
|
|
338
342
|
await sessionProvider.save(invocationSession);
|
|
339
343
|
await threadProvider.save(invocationThread);
|
|
340
344
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
@@ -353,7 +357,11 @@ export class StandaloneAgentContext<
|
|
|
353
357
|
}
|
|
354
358
|
})
|
|
355
359
|
.catch((ex) => {
|
|
356
|
-
this.logger.error(
|
|
360
|
+
this.logger.error(
|
|
361
|
+
'wait until errored for session %s. %s',
|
|
362
|
+
invocationSessionId,
|
|
363
|
+
ex
|
|
364
|
+
);
|
|
357
365
|
if (ex instanceof Error) {
|
|
358
366
|
span.recordException(ex);
|
|
359
367
|
}
|
|
@@ -442,34 +450,34 @@ export class StandaloneAgentContext<
|
|
|
442
450
|
|
|
443
451
|
/**
|
|
444
452
|
* Create a standalone agent context for executing agents outside of HTTP requests.
|
|
445
|
-
*
|
|
453
|
+
*
|
|
446
454
|
* This is useful for Discord bots, cron jobs, WebSocket callbacks, or any scenario
|
|
447
455
|
* where you need to run agents but don't have an HTTP request context.
|
|
448
|
-
*
|
|
456
|
+
*
|
|
449
457
|
* @param options - Optional configuration for the context
|
|
450
458
|
* @returns A StandaloneAgentContext instance
|
|
451
|
-
*
|
|
459
|
+
*
|
|
452
460
|
* @example
|
|
453
461
|
* ```typescript
|
|
454
462
|
* import { createAgentContext } from '@agentuity/runtime';
|
|
455
463
|
* import myAgent from './agents/my-agent';
|
|
456
|
-
*
|
|
464
|
+
*
|
|
457
465
|
* // Simple usage:
|
|
458
466
|
* const ctx = createAgentContext();
|
|
459
467
|
* const result = await ctx.invoke(() => myAgent.run(input));
|
|
460
|
-
*
|
|
468
|
+
*
|
|
461
469
|
* // Discord bot example:
|
|
462
470
|
* client.on('messageCreate', async (message) => {
|
|
463
|
-
* const ctx = createAgentContext({
|
|
471
|
+
* const ctx = createAgentContext({
|
|
464
472
|
* sessionId: message.id,
|
|
465
473
|
* trigger: 'discord'
|
|
466
474
|
* });
|
|
467
|
-
* const response = await ctx.invoke(() =>
|
|
475
|
+
* const response = await ctx.invoke(() =>
|
|
468
476
|
* chatAgent.run({ message: message.content })
|
|
469
477
|
* );
|
|
470
478
|
* await message.reply(response.text);
|
|
471
479
|
* });
|
|
472
|
-
*
|
|
480
|
+
*
|
|
473
481
|
* // Cron job example:
|
|
474
482
|
* cron.schedule('0 * * * *', async () => {
|
|
475
483
|
* const ctx = createAgentContext({ trigger: 'cron' });
|