@openai/agents-core 0.0.16 → 0.0.17
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/agent.d.ts +1 -1
- package/dist/agent.js +29 -22
- package/dist/agent.js.map +1 -1
- package/dist/computer.js +2 -1
- package/dist/config.js +12 -6
- package/dist/config.js.map +1 -1
- package/dist/errors.js +21 -9
- package/dist/errors.js.map +1 -1
- package/dist/events.js +9 -3
- package/dist/events.js.map +1 -1
- package/dist/extensions/handoffFilters.js +9 -6
- package/dist/extensions/handoffFilters.js.map +1 -1
- package/dist/extensions/handoffPrompt.js +7 -3
- package/dist/extensions/handoffPrompt.js.map +1 -1
- package/dist/extensions/index.js +8 -2
- package/dist/extensions/index.js.map +1 -1
- package/dist/guardrail.js +6 -2
- package/dist/guardrail.js.map +1 -1
- package/dist/handoff.js +28 -18
- package/dist/handoff.js.map +1 -1
- package/dist/helpers/message.js +8 -3
- package/dist/helpers/message.js.map +1 -1
- package/dist/index.js +121 -25
- package/dist/index.js.map +1 -1
- package/dist/items.js +23 -11
- package/dist/items.js.map +1 -1
- package/dist/lifecycle.js +12 -6
- package/dist/lifecycle.js.map +1 -1
- package/dist/logger.js +15 -8
- package/dist/logger.js.map +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +60 -45
- package/dist/mcp.js.map +1 -1
- package/dist/mcp.mjs +1 -1
- package/dist/mcp.mjs.map +1 -1
- package/dist/mcpUtil.js +4 -1
- package/dist/mcpUtil.js.map +1 -1
- package/dist/metadata.d.ts +0 -1
- package/dist/metadata.js +7 -5
- package/dist/metadata.js.map +1 -1
- package/dist/metadata.mjs +2 -3
- package/dist/metadata.mjs.map +1 -1
- package/dist/model.js +2 -1
- package/dist/providers.js +6 -2
- package/dist/providers.js.map +1 -1
- package/dist/result.js +22 -14
- package/dist/result.js.map +1 -1
- package/dist/run.js +106 -95
- package/dist/run.js.map +1 -1
- package/dist/runContext.js +13 -6
- package/dist/runContext.js.map +1 -1
- package/dist/runImplementation.d.ts +1 -1
- package/dist/runImplementation.js +106 -89
- package/dist/runImplementation.js.map +1 -1
- package/dist/runImplementation.mjs +1 -1
- package/dist/runImplementation.mjs.map +1 -1
- package/dist/runState.d.ts +7 -1
- package/dist/runState.js +204 -151
- package/dist/runState.js.map +1 -1
- package/dist/runState.mjs +10 -1
- package/dist/runState.mjs.map +1 -1
- package/dist/shims/interface.js +2 -1
- package/dist/shims/mcp-server/browser.js +10 -4
- package/dist/shims/mcp-server/browser.js.map +1 -1
- package/dist/shims/mcp-server/node.js +67 -25
- package/dist/shims/mcp-server/node.js.map +1 -1
- package/dist/shims/shims-browser.js +25 -13
- package/dist/shims/shims-browser.js.map +1 -1
- package/dist/shims/shims-node.js +72 -15
- package/dist/shims/shims-node.js.map +1 -1
- package/dist/shims/shims-node.mjs +11 -3
- package/dist/shims/shims-node.mjs.map +1 -1
- package/dist/shims/shims-workerd.js +77 -18
- package/dist/shims/shims-workerd.js.map +1 -1
- package/dist/shims/shims-workerd.mjs +11 -3
- package/dist/shims/shims-workerd.mjs.map +1 -1
- package/dist/shims/shims.js +17 -1
- package/dist/shims/shims.js.map +1 -1
- package/dist/tool.d.ts +1 -1
- package/dist/tool.js +37 -29
- package/dist/tool.js.map +1 -1
- package/dist/tracing/context.js +25 -14
- package/dist/tracing/context.js.map +1 -1
- package/dist/tracing/createSpans.js +52 -38
- package/dist/tracing/createSpans.js.map +1 -1
- package/dist/tracing/index.js +51 -15
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/processor.js +31 -20
- package/dist/tracing/processor.js.map +1 -1
- package/dist/tracing/provider.js +53 -45
- package/dist/tracing/provider.js.map +1 -1
- package/dist/tracing/spans.js +18 -10
- package/dist/tracing/spans.js.map +1 -1
- package/dist/tracing/traces.js +11 -6
- package/dist/tracing/traces.js.map +1 -1
- package/dist/tracing/utils.js +16 -9
- package/dist/tracing/utils.js.map +1 -1
- package/dist/types/aliases.js +2 -1
- package/dist/types/helpers.d.ts +1 -1
- package/dist/types/helpers.js +2 -1
- package/dist/types/index.js +44 -5
- package/dist/types/index.js.map +1 -1
- package/dist/types/protocol.d.ts +1 -1
- package/dist/types/protocol.js +188 -185
- package/dist/types/protocol.js.map +1 -1
- package/dist/types/protocol.mjs +1 -1
- package/dist/types/protocol.mjs.map +1 -1
- package/dist/types/providerData.js +2 -1
- package/dist/usage.js +7 -3
- package/dist/usage.js.map +1 -1
- package/dist/utils/index.js +9 -3
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/messages.js +6 -2
- package/dist/utils/messages.js.map +1 -1
- package/dist/utils/safeExecute.js +4 -1
- package/dist/utils/safeExecute.js.map +1 -1
- package/dist/utils/serialize.js +6 -2
- package/dist/utils/serialize.js.map +1 -1
- package/dist/utils/smartString.js +4 -1
- package/dist/utils/smartString.js.map +1 -1
- package/dist/utils/tools.js +16 -11
- package/dist/utils/tools.js.map +1 -1
- package/dist/utils/typeGuards.d.ts +1 -1
- package/dist/utils/typeGuards.js +6 -2
- package/dist/utils/typeGuards.js.map +1 -1
- package/package.json +22 -41
package/dist/agent.d.ts
CHANGED
package/dist/agent.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Agent = void 0;
|
|
7
|
+
const lifecycle_1 = require("./lifecycle.js");
|
|
8
|
+
const mcp_1 = require("./mcp.js");
|
|
9
|
+
const tool_1 = require("./tool.js");
|
|
10
|
+
const run_1 = require("./run.js");
|
|
11
|
+
const tools_1 = require("./utils/tools.js");
|
|
12
|
+
const messages_1 = require("./utils/messages.js");
|
|
13
|
+
const typeGuards_1 = require("./utils/typeGuards.js");
|
|
14
|
+
const typeGuards_2 = require("./utils/typeGuards.js");
|
|
15
|
+
const errors_1 = require("./errors.js");
|
|
16
|
+
const logger_1 = __importDefault(require("./logger.js"));
|
|
11
17
|
/**
|
|
12
18
|
* The class representing an AI agent configured with instructions, tools, guardrails, handoffs and more.
|
|
13
19
|
*
|
|
@@ -18,7 +24,7 @@ import logger from "./logger.js";
|
|
|
18
24
|
* Agents are generic on the context type. The context is a (mutable) object you create. It is
|
|
19
25
|
* passed to tool functions, handoffs, guardrails, etc.
|
|
20
26
|
*/
|
|
21
|
-
|
|
27
|
+
class Agent extends lifecycle_1.AgentHooks {
|
|
22
28
|
/**
|
|
23
29
|
* Create an Agent with handoffs and automatically infer the union type for TOutput from the handoff agents' output types.
|
|
24
30
|
*/
|
|
@@ -48,7 +54,7 @@ export class Agent extends AgentHooks {
|
|
|
48
54
|
constructor(config) {
|
|
49
55
|
super();
|
|
50
56
|
if (typeof config.name !== 'string' || config.name.trim() === '') {
|
|
51
|
-
throw new UserError('Agent must have a name.');
|
|
57
|
+
throw new errors_1.UserError('Agent must have a name.');
|
|
52
58
|
}
|
|
53
59
|
this.name = config.name;
|
|
54
60
|
this.instructions = config.instructions ?? Agent.DEFAULT_MODEL_PLACEHOLDER;
|
|
@@ -80,7 +86,7 @@ export class Agent extends AgentHooks {
|
|
|
80
86
|
}
|
|
81
87
|
}
|
|
82
88
|
if (outputTypes.size > 1) {
|
|
83
|
-
|
|
89
|
+
logger_1.default.warn(`[Agent] Warning: Handoff agents have different output types: ${Array.from(outputTypes).join(', ')}. You can make it type-safe by using Agent.create({ ... }) method instead.`);
|
|
84
90
|
}
|
|
85
91
|
}
|
|
86
92
|
}
|
|
@@ -92,7 +98,7 @@ export class Agent extends AgentHooks {
|
|
|
92
98
|
if (this.outputType === 'text') {
|
|
93
99
|
return 'text';
|
|
94
100
|
}
|
|
95
|
-
else if (isZodObject(this.outputType)) {
|
|
101
|
+
else if ((0, typeGuards_2.isZodObject)(this.outputType)) {
|
|
96
102
|
return 'ZodOutput';
|
|
97
103
|
}
|
|
98
104
|
else if (typeof this.outputType === 'object') {
|
|
@@ -130,8 +136,8 @@ export class Agent extends AgentHooks {
|
|
|
130
136
|
*/
|
|
131
137
|
asTool(options) {
|
|
132
138
|
const { toolName, toolDescription, customOutputExtractor } = options;
|
|
133
|
-
return tool({
|
|
134
|
-
name: toolName ?? toFunctionToolName(this.name),
|
|
139
|
+
return (0, tool_1.tool)({
|
|
140
|
+
name: toolName ?? (0, tools_1.toFunctionToolName)(this.name),
|
|
135
141
|
description: toolDescription ?? '',
|
|
136
142
|
parameters: {
|
|
137
143
|
type: 'object',
|
|
@@ -145,17 +151,17 @@ export class Agent extends AgentHooks {
|
|
|
145
151
|
},
|
|
146
152
|
strict: true,
|
|
147
153
|
execute: async (data, context) => {
|
|
148
|
-
if (!isAgentToolInput(data)) {
|
|
149
|
-
throw new ModelBehaviorError('Agent tool called with invalid input');
|
|
154
|
+
if (!(0, typeGuards_1.isAgentToolInput)(data)) {
|
|
155
|
+
throw new errors_1.ModelBehaviorError('Agent tool called with invalid input');
|
|
150
156
|
}
|
|
151
|
-
const runner = new Runner();
|
|
157
|
+
const runner = new run_1.Runner();
|
|
152
158
|
const result = await runner.run(this, data.input, {
|
|
153
159
|
context: context?.context,
|
|
154
160
|
});
|
|
155
161
|
if (typeof customOutputExtractor === 'function') {
|
|
156
162
|
return customOutputExtractor(result);
|
|
157
163
|
}
|
|
158
|
-
return getOutputText(result.rawResponses[result.rawResponses.length - 1]);
|
|
164
|
+
return (0, messages_1.getOutputText)(result.rawResponses[result.rawResponses.length - 1]);
|
|
159
165
|
},
|
|
160
166
|
});
|
|
161
167
|
}
|
|
@@ -189,7 +195,7 @@ export class Agent extends AgentHooks {
|
|
|
189
195
|
*/
|
|
190
196
|
async getMcpTools(runContext) {
|
|
191
197
|
if (this.mcpServers.length > 0) {
|
|
192
|
-
return getAllMcpTools({
|
|
198
|
+
return (0, mcp_1.getAllMcpTools)({
|
|
193
199
|
mcpServers: this.mcpServers,
|
|
194
200
|
runContext,
|
|
195
201
|
agent: this,
|
|
@@ -218,7 +224,7 @@ export class Agent extends AgentHooks {
|
|
|
218
224
|
}
|
|
219
225
|
if (typeof this.outputType === 'object') {
|
|
220
226
|
const parsed = JSON.parse(output);
|
|
221
|
-
if (isZodObject(this.outputType)) {
|
|
227
|
+
if ((0, typeGuards_2.isZodObject)(this.outputType)) {
|
|
222
228
|
return this.outputType.parse(parsed);
|
|
223
229
|
}
|
|
224
230
|
return parsed;
|
|
@@ -236,4 +242,5 @@ export class Agent extends AgentHooks {
|
|
|
236
242
|
};
|
|
237
243
|
}
|
|
238
244
|
}
|
|
245
|
+
exports.Agent = Agent;
|
|
239
246
|
//# sourceMappingURL=agent.js.map
|
package/dist/agent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":";;;;;;AAGA,8CAAyC;AACzC,kCAAuD;AAGvD,oCAKgB;AAShB,kCAA+B;AAC/B,4CAAmD;AACnD,kDAAiD;AACjD,sDAAsD;AACtD,sDAAiD;AACjD,wCAAyD;AAEzD,yDAA8B;AA0P9B;;;;;;;;;GASG;AACH,MAAa,KAIX,SAAQ,sBAA6B;IAGrC;;OAEG;IACH,MAAM,CAAC,MAAM,CAIX,MAAkD;QAElD,OAAO,IAAI,KAAK,CAA0D;YACxE,GAAG,MAAM;YACT,QAAQ,EAAE,MAAM,CAAC,QAAe;YAChC,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,+BAA+B,EAAE,KAAK;SACvC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,yBAAyB,GAAG,EAAE,CAAC;IAEtC,IAAI,CAAS;IACb,YAAY,CAKuB;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AAK,CAAC,WAAW,CACf,UAAgC;QAEhC,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IAClE,CAAC;IAED;;;;;OAKG;IACH,kBAAkB,CAAC,MAAc;QAC/B,IAAI,IAAI,CAAC,UAAU,KAAK,MAAM,EAAE,CAAC;YAC/B,OAAO,MAAsC,CAAC;QAChD,CAAC;QAED,IAAI,OAAO,IAAI,CAAC,UAAU,KAAK,QAAQ,EAAE,CAAC;YACxC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAElC,IAAI,IAAA,wBAAW,EAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;gBACjC,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAiC,CAAC;YACvE,CAAC;YAED,OAAO,MAAsC,CAAC;QAChD,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,wBAAwB,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC;IACJ,CAAC;;AA/RH,sBAgSC"}
|
package/dist/computer.js
CHANGED
package/dist/config.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logging = exports.tracing = void 0;
|
|
4
|
+
exports.loadEnv = loadEnv;
|
|
5
|
+
// Use function instead of exporting the value to prevent
|
|
6
|
+
// circular dependency resolution issues caused by other exports in '@openai/agents-core/_shims'
|
|
7
|
+
const _shims_1 = require("@openai/agents-core/_shims");
|
|
2
8
|
/**
|
|
3
9
|
* Loads environment variables from the process environment.
|
|
4
10
|
*
|
|
5
11
|
* @returns An object containing the environment variables.
|
|
6
12
|
*/
|
|
7
|
-
|
|
8
|
-
return
|
|
13
|
+
function loadEnv() {
|
|
14
|
+
return (0, _shims_1.loadEnv)();
|
|
9
15
|
}
|
|
10
16
|
/**
|
|
11
17
|
* Checks if a flag is enabled in the environment.
|
|
@@ -21,9 +27,9 @@ function isEnabled(flagName) {
|
|
|
21
27
|
/**
|
|
22
28
|
* Global configuration for tracing.
|
|
23
29
|
*/
|
|
24
|
-
|
|
30
|
+
exports.tracing = {
|
|
25
31
|
get disabled() {
|
|
26
|
-
if (isBrowserEnvironment()) {
|
|
32
|
+
if ((0, _shims_1.isBrowserEnvironment)()) {
|
|
27
33
|
return true;
|
|
28
34
|
}
|
|
29
35
|
else if (loadEnv().NODE_ENV === 'test') {
|
|
@@ -36,7 +42,7 @@ export const tracing = {
|
|
|
36
42
|
/**
|
|
37
43
|
* Global configuration for logging.
|
|
38
44
|
*/
|
|
39
|
-
|
|
45
|
+
exports.logging = {
|
|
40
46
|
get dontLogModelData() {
|
|
41
47
|
return isEnabled('OPENAI_AGENTS_DONT_LOG_MODEL_DATA');
|
|
42
48
|
},
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAYA,0BAEC;AAdD,yDAAyD;AACzD,gGAAgG;AAChG,uDAGoC;AAEpC;;;;GAIG;AACH,SAAgB,OAAO;IACrB,OAAO,IAAA,gBAAQ,GAAE,CAAC;AACpB,CAAC;AAED;;;;;GAKG;AACH,SAAS,SAAS,CAAC,QAAgB;IACjC,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;IACtB,OAAO,CACL,OAAO,GAAG,KAAK,WAAW;QAC1B,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,MAAM,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,GAAG,CAAC,CACpD,CAAC;AACJ,CAAC;AAED;;GAEG;AACU,QAAA,OAAO,GAAG;IACrB,IAAI,QAAQ;QACV,IAAI,IAAA,6BAAoB,GAAE,EAAE,CAAC;YAC3B,OAAO,IAAI,CAAC;QACd,CAAC;aAAM,IAAI,OAAO,EAAE,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;YACzC,gCAAgC;YAChC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,SAAS,CAAC,+BAA+B,CAAC,CAAC;IACpD,CAAC;CACF,CAAC;AAEF;;GAEG;AACU,QAAA,OAAO,GAAG;IACrB,IAAI,gBAAgB;QAClB,OAAO,SAAS,CAAC,mCAAmC,CAAC,CAAC;IACxD,CAAC;IACD,IAAI,eAAe;QACjB,OAAO,SAAS,CAAC,kCAAkC,CAAC,CAAC;IACvD,CAAC;CACF,CAAC"}
|
package/dist/errors.js
CHANGED
|
@@ -1,72 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OutputGuardrailTripwireTriggered = exports.InputGuardrailTripwireTriggered = exports.ToolCallError = exports.GuardrailExecutionError = exports.UserError = exports.ModelBehaviorError = exports.MaxTurnsExceededError = exports.SystemError = exports.AgentsError = void 0;
|
|
1
4
|
/**
|
|
2
5
|
* Base class for all errors thrown by the library.
|
|
3
6
|
*/
|
|
4
|
-
|
|
7
|
+
class AgentsError extends Error {
|
|
5
8
|
state;
|
|
6
9
|
constructor(message, state) {
|
|
7
10
|
super(message);
|
|
8
11
|
this.state = state;
|
|
9
12
|
}
|
|
10
13
|
}
|
|
14
|
+
exports.AgentsError = AgentsError;
|
|
11
15
|
/**
|
|
12
16
|
* System error thrown when the library encounters an error that is not caused by the user's
|
|
13
17
|
* misconfiguration.
|
|
14
18
|
*/
|
|
15
|
-
|
|
19
|
+
class SystemError extends AgentsError {
|
|
16
20
|
}
|
|
21
|
+
exports.SystemError = SystemError;
|
|
17
22
|
/**
|
|
18
23
|
* Error thrown when the maximum number of turns is exceeded.
|
|
19
24
|
*/
|
|
20
|
-
|
|
25
|
+
class MaxTurnsExceededError extends AgentsError {
|
|
21
26
|
}
|
|
27
|
+
exports.MaxTurnsExceededError = MaxTurnsExceededError;
|
|
22
28
|
/**
|
|
23
29
|
* Error thrown when a model behavior is unexpected.
|
|
24
30
|
*/
|
|
25
|
-
|
|
31
|
+
class ModelBehaviorError extends AgentsError {
|
|
26
32
|
}
|
|
33
|
+
exports.ModelBehaviorError = ModelBehaviorError;
|
|
27
34
|
/**
|
|
28
35
|
* Error thrown when the error is caused by the library user's misconfiguration.
|
|
29
36
|
*/
|
|
30
|
-
|
|
37
|
+
class UserError extends AgentsError {
|
|
31
38
|
}
|
|
39
|
+
exports.UserError = UserError;
|
|
32
40
|
/**
|
|
33
41
|
* Error thrown when a guardrail execution fails.
|
|
34
42
|
*/
|
|
35
|
-
|
|
43
|
+
class GuardrailExecutionError extends AgentsError {
|
|
36
44
|
error;
|
|
37
45
|
constructor(message, error, state) {
|
|
38
46
|
super(message, state);
|
|
39
47
|
this.error = error;
|
|
40
48
|
}
|
|
41
49
|
}
|
|
50
|
+
exports.GuardrailExecutionError = GuardrailExecutionError;
|
|
42
51
|
/**
|
|
43
52
|
* Error thrown when a tool call fails.
|
|
44
53
|
*/
|
|
45
|
-
|
|
54
|
+
class ToolCallError extends AgentsError {
|
|
46
55
|
error;
|
|
47
56
|
constructor(message, error, state) {
|
|
48
57
|
super(message, state);
|
|
49
58
|
this.error = error;
|
|
50
59
|
}
|
|
51
60
|
}
|
|
61
|
+
exports.ToolCallError = ToolCallError;
|
|
52
62
|
/**
|
|
53
63
|
* Error thrown when an input guardrail tripwire is triggered.
|
|
54
64
|
*/
|
|
55
|
-
|
|
65
|
+
class InputGuardrailTripwireTriggered extends AgentsError {
|
|
56
66
|
result;
|
|
57
67
|
constructor(message, result, state) {
|
|
58
68
|
super(message, state);
|
|
59
69
|
this.result = result;
|
|
60
70
|
}
|
|
61
71
|
}
|
|
72
|
+
exports.InputGuardrailTripwireTriggered = InputGuardrailTripwireTriggered;
|
|
62
73
|
/**
|
|
63
74
|
* Error thrown when an output guardrail tripwire is triggered.
|
|
64
75
|
*/
|
|
65
|
-
|
|
76
|
+
class OutputGuardrailTripwireTriggered extends AgentsError {
|
|
66
77
|
result;
|
|
67
78
|
constructor(message, result, state) {
|
|
68
79
|
super(message, state);
|
|
69
80
|
this.result = result;
|
|
70
81
|
}
|
|
71
82
|
}
|
|
83
|
+
exports.OutputGuardrailTripwireTriggered = OutputGuardrailTripwireTriggered;
|
|
72
84
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AASA;;GAEG;AACH,MAAsB,WAAY,SAAQ,KAAK;IAC7C,KAAK,CAAkC;IAEvC,YAAY,OAAe,EAAE,KAAsC;QACjE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAPD,kCAOC;AAED;;;GAGG;AACH,MAAa,WAAY,SAAQ,WAAW;CAAG;AAA/C,kCAA+C;AAE/C;;GAEG;AACH,MAAa,qBAAsB,SAAQ,WAAW;CAAG;AAAzD,sDAAyD;AAEzD;;GAEG;AACH,MAAa,kBAAmB,SAAQ,WAAW;CAAG;AAAtD,gDAAsD;AAEtD;;GAEG;AACH,MAAa,SAAU,SAAQ,WAAW;CAAG;AAA7C,8BAA6C;AAE7C;;GAEG;AACH,MAAa,uBAAwB,SAAQ,WAAW;IACtD,KAAK,CAAQ;IACb,YACE,OAAe,EACf,KAAY,EACZ,KAAsC;QAEtC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAVD,0DAUC;AAED;;GAEG;AACH,MAAa,aAAc,SAAQ,WAAW;IAC5C,KAAK,CAAQ;IACb,YACE,OAAe,EACf,KAAY,EACZ,KAAsC;QAEtC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAVD,sCAUC;AAED;;GAEG;AACH,MAAa,+BAAgC,SAAQ,WAAW;IAC9D,MAAM,CAAuB;IAC7B,YACE,OAAe,EACf,MAA4B,EAC5B,KAA0B;QAE1B,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAVD,0EAUC;AAED;;GAEG;AACH,MAAa,gCAGX,SAAQ,WAAW;IACnB,MAAM,CAA4C;IAClD,YACE,OAAe,EACf,MAAiD,EACjD,KAA0B;QAE1B,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAbD,4EAaC"}
|
package/dist/events.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RunAgentUpdatedStreamEvent = exports.RunItemStreamEvent = exports.RunRawModelStreamEvent = void 0;
|
|
1
4
|
/**
|
|
2
5
|
* Streaming event from the LLM. These are `raw` events, i.e. they are directly passed through from
|
|
3
6
|
* the LLM.
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
class RunRawModelStreamEvent {
|
|
6
9
|
data;
|
|
7
10
|
/**
|
|
8
11
|
* The type of the event.
|
|
@@ -15,11 +18,12 @@ export class RunRawModelStreamEvent {
|
|
|
15
18
|
this.data = data;
|
|
16
19
|
}
|
|
17
20
|
}
|
|
21
|
+
exports.RunRawModelStreamEvent = RunRawModelStreamEvent;
|
|
18
22
|
/**
|
|
19
23
|
* Streaming events that wrap a `RunItem`. As the agent processes the LLM response, it will generate
|
|
20
24
|
* these events from new messages, tool calls, tool outputs, handoffs, etc.
|
|
21
25
|
*/
|
|
22
|
-
|
|
26
|
+
class RunItemStreamEvent {
|
|
23
27
|
name;
|
|
24
28
|
item;
|
|
25
29
|
type = 'run_item_stream_event';
|
|
@@ -32,10 +36,11 @@ export class RunItemStreamEvent {
|
|
|
32
36
|
this.item = item;
|
|
33
37
|
}
|
|
34
38
|
}
|
|
39
|
+
exports.RunItemStreamEvent = RunItemStreamEvent;
|
|
35
40
|
/**
|
|
36
41
|
* Event that notifies that there is a new agent running.
|
|
37
42
|
*/
|
|
38
|
-
|
|
43
|
+
class RunAgentUpdatedStreamEvent {
|
|
39
44
|
agent;
|
|
40
45
|
type = 'agent_updated_stream_event';
|
|
41
46
|
/**
|
|
@@ -45,4 +50,5 @@ export class RunAgentUpdatedStreamEvent {
|
|
|
45
50
|
this.agent = agent;
|
|
46
51
|
}
|
|
47
52
|
}
|
|
53
|
+
exports.RunAgentUpdatedStreamEvent = RunAgentUpdatedStreamEvent;
|
|
48
54
|
//# sourceMappingURL=events.js.map
|
package/dist/events.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":";;;AAIA;;;GAGG;AACH,MAAa,sBAAsB;IASd;IARnB;;OAEG;IACa,IAAI,GAAG,wBAAwB,CAAC;IAEhD;;OAEG;IACH,YAAmB,IAAyB;QAAzB,SAAI,GAAJ,IAAI,CAAqB;IAAG,CAAC;CACjD;AAVD,wDAUC;AAcD;;;GAGG;AACH,MAAa,kBAAkB;IAQpB;IACA;IARO,IAAI,GAAG,uBAAuB,CAAC;IAE/C;;;OAGG;IACH,YACS,IAA4B,EAC5B,IAAa;QADb,SAAI,GAAJ,IAAI,CAAwB;QAC5B,SAAI,GAAJ,IAAI,CAAS;IACnB,CAAC;CACL;AAXD,gDAWC;AAED;;GAEG;AACH,MAAa,0BAA0B;IAMlB;IALH,IAAI,GAAG,4BAA4B,CAAC;IAEpD;;OAEG;IACH,YAAmB,KAAsB;QAAtB,UAAK,GAAL,KAAK,CAAiB;IAAG,CAAC;CAC9C;AAPD,gEAOC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeAllTools = removeAllTools;
|
|
4
|
+
const items_1 = require("../items.js");
|
|
2
5
|
const TOOL_TYPES = new Set([
|
|
3
6
|
'function_call',
|
|
4
7
|
'function_call_result',
|
|
@@ -11,7 +14,7 @@ const TOOL_TYPES = new Set([
|
|
|
11
14
|
* @param handoffInputData
|
|
12
15
|
* @returns
|
|
13
16
|
*/
|
|
14
|
-
|
|
17
|
+
function removeAllTools(handoffInputData) {
|
|
15
18
|
const { inputHistory, preHandoffItems, newItems, runContext } = handoffInputData;
|
|
16
19
|
const filteredHistory = Array.isArray(inputHistory)
|
|
17
20
|
? removeToolTypesFromInput(inputHistory)
|
|
@@ -26,10 +29,10 @@ export function removeAllTools(handoffInputData) {
|
|
|
26
29
|
};
|
|
27
30
|
}
|
|
28
31
|
function removeToolsFromItems(items) {
|
|
29
|
-
return items.filter((item) => !(item instanceof RunHandoffCallItem) &&
|
|
30
|
-
!(item instanceof RunHandoffOutputItem) &&
|
|
31
|
-
!(item instanceof RunToolCallItem) &&
|
|
32
|
-
!(item instanceof RunToolCallOutputItem));
|
|
32
|
+
return items.filter((item) => !(item instanceof items_1.RunHandoffCallItem) &&
|
|
33
|
+
!(item instanceof items_1.RunHandoffOutputItem) &&
|
|
34
|
+
!(item instanceof items_1.RunToolCallItem) &&
|
|
35
|
+
!(item instanceof items_1.RunToolCallOutputItem));
|
|
33
36
|
}
|
|
34
37
|
function removeToolTypesFromInput(items) {
|
|
35
38
|
return items.filter((item) => !TOOL_TYPES.has(item.type ?? ''));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handoffFilters.js","sourceRoot":"","sources":["../../src/extensions/handoffFilters.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handoffFilters.js","sourceRoot":"","sources":["../../src/extensions/handoffFilters.ts"],"names":[],"mappings":";;AAuBA,wCAmBC;AAzCD,uCAMkB;AAGlB,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,eAAe;IACf,sBAAsB;IACtB,eAAe;IACf,sBAAsB;IACtB,kBAAkB;CACnB,CAAC,CAAC;AAEH;;;;GAIG;AACH,SAAgB,cAAc,CAC5B,gBAAkC;IAElC,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,UAAU,EAAE,GAC3D,gBAAgB,CAAC;IAEnB,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC;QACjD,CAAC,CAAC,wBAAwB,CAAC,YAAY,CAAC;QACxC,CAAC,CAAC,YAAY,CAAC;IAEjB,MAAM,uBAAuB,GAAG,oBAAoB,CAAC,eAAe,CAAC,CAAC;IACtE,MAAM,gBAAgB,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IAExD,OAAO;QACL,YAAY,EAAE,eAAe;QAC7B,eAAe,EAAE,uBAAuB;QACxC,QAAQ,EAAE,gBAAgB;QAC1B,UAAU;KACX,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAgB;IAC5C,OAAO,KAAK,CAAC,MAAM,CACjB,CAAC,IAAI,EAAE,EAAE,CACP,CAAC,CAAC,IAAI,YAAY,0BAAkB,CAAC;QACrC,CAAC,CAAC,IAAI,YAAY,4BAAoB,CAAC;QACvC,CAAC,CAAC,IAAI,YAAY,uBAAe,CAAC;QAClC,CAAC,CAAC,IAAI,YAAY,6BAAqB,CAAC,CAC3C,CAAC;AACJ,CAAC;AAED,SAAS,wBAAwB,CAAC,KAAuB;IACvD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RECOMMENDED_PROMPT_PREFIX = void 0;
|
|
4
|
+
exports.promptWithHandoffInstructions = promptWithHandoffInstructions;
|
|
1
5
|
/**
|
|
2
6
|
* A recommended prompt prefix for agents that use handoffs. We recommend including this or
|
|
3
7
|
* similar instructions in any agents that use handoffs.
|
|
4
8
|
*/
|
|
5
|
-
|
|
9
|
+
exports.RECOMMENDED_PROMPT_PREFIX = `# System context
|
|
6
10
|
You are part of a multi-agent system called the Agents SDK, designed to make agent coordination and execution easy. Agents uses two primary abstractions: **Agents** and **Handoffs**. An agent encompasses instructions and tools and can hand off a conversation to another agent when appropriate. Handoffs are achieved by calling a handoff function, generally named \`transfer_to_<agent_name>\`. Transfers between agents are handled seamlessly in the background; do not mention or draw attention to these transfers in your conversation with the user.`;
|
|
7
11
|
/**
|
|
8
12
|
* Add recommended instructions to the prompt for agents that use handoffs.
|
|
@@ -10,7 +14,7 @@ You are part of a multi-agent system called the Agents SDK, designed to make age
|
|
|
10
14
|
* @param prompt - The original prompt string.
|
|
11
15
|
* @returns The prompt prefixed with recommended handoff instructions.
|
|
12
16
|
*/
|
|
13
|
-
|
|
14
|
-
return `${RECOMMENDED_PROMPT_PREFIX}\n\n${prompt}`;
|
|
17
|
+
function promptWithHandoffInstructions(prompt) {
|
|
18
|
+
return `${exports.RECOMMENDED_PROMPT_PREFIX}\n\n${prompt}`;
|
|
15
19
|
}
|
|
16
20
|
//# sourceMappingURL=handoffPrompt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handoffPrompt.js","sourceRoot":"","sources":["../../src/extensions/handoffPrompt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handoffPrompt.js","sourceRoot":"","sources":["../../src/extensions/handoffPrompt.ts"],"names":[],"mappings":";;;AAaA,sEAEC;AAfD;;;GAGG;AACU,QAAA,yBAAyB,GAAG;oiBAC2f,CAAC;AAEriB;;;;;GAKG;AACH,SAAgB,6BAA6B,CAAC,MAAc;IAC1D,OAAO,GAAG,iCAAyB,OAAO,MAAM,EAAE,CAAC;AACrD,CAAC"}
|
package/dist/extensions/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeAllTools = exports.promptWithHandoffInstructions = exports.RECOMMENDED_PROMPT_PREFIX = void 0;
|
|
4
|
+
var handoffPrompt_1 = require("./handoffPrompt.js");
|
|
5
|
+
Object.defineProperty(exports, "RECOMMENDED_PROMPT_PREFIX", { enumerable: true, get: function () { return handoffPrompt_1.RECOMMENDED_PROMPT_PREFIX; } });
|
|
6
|
+
Object.defineProperty(exports, "promptWithHandoffInstructions", { enumerable: true, get: function () { return handoffPrompt_1.promptWithHandoffInstructions; } });
|
|
7
|
+
var handoffFilters_1 = require("./handoffFilters.js");
|
|
8
|
+
Object.defineProperty(exports, "removeAllTools", { enumerable: true, get: function () { return handoffFilters_1.removeAllTools; } });
|
|
3
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":";;;AAAA,oDAA2F;AAAlF,0HAAA,yBAAyB,OAAA;AAAE,8HAAA,6BAA6B,OAAA;AACjE,sDAAkD;AAAzC,gHAAA,cAAc,OAAA"}
|
package/dist/guardrail.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineInputGuardrail = defineInputGuardrail;
|
|
4
|
+
exports.defineOutputGuardrail = defineOutputGuardrail;
|
|
1
5
|
/**
|
|
2
6
|
* Defines an input guardrail definition.
|
|
3
7
|
*/
|
|
4
|
-
|
|
8
|
+
function defineInputGuardrail({ name, execute, }) {
|
|
5
9
|
return {
|
|
6
10
|
type: 'input',
|
|
7
11
|
name,
|
|
@@ -17,7 +21,7 @@ export function defineInputGuardrail({ name, execute, }) {
|
|
|
17
21
|
/**
|
|
18
22
|
* Creates an output guardrail definition.
|
|
19
23
|
*/
|
|
20
|
-
|
|
24
|
+
function defineOutputGuardrail({ name, execute, }) {
|
|
21
25
|
return {
|
|
22
26
|
type: 'output',
|
|
23
27
|
name,
|
package/dist/guardrail.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guardrail.js","sourceRoot":"","sources":["../src/guardrail.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"guardrail.js","sourceRoot":"","sources":["../src/guardrail.ts"],"names":[],"mappings":";;AAyHA,oDAeC;AA+GD,sDAwBC;AAzJD;;GAEG;AACH,SAAgB,oBAAoB,CAAC,EACnC,IAAI,EACJ,OAAO,GACkB;IACzB,OAAO;QACL,IAAI,EAAE,OAAO;QACb,IAAI;QACJ,iBAAiB,EAAE,OAAO;QAC1B,KAAK,CAAC,GAAG,CAAC,IAAgC;YACxC,OAAO;gBACL,SAAS,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE;gBAClC,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC;aAC5B,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AA4GD;;GAEG;AACH,SAAgB,qBAAqB,CAEnC,EACA,IAAI,EACJ,OAAO,GAC4B;IAInC,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,IAAI;QACJ,iBAAiB,EAAE,OAAO;QAC1B,KAAK,CAAC,GAAG,CACP,IAA0D;YAE1D,OAAO;gBACL,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE;gBACnC,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC;aAC5B,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/handoff.js
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Handoff = void 0;
|
|
7
|
+
exports.getTransferMessage = getTransferMessage;
|
|
8
|
+
exports.handoff = handoff;
|
|
9
|
+
exports.getHandoff = getHandoff;
|
|
10
|
+
const errors_1 = require("./errors.js");
|
|
11
|
+
const tools_1 = require("./utils/tools.js");
|
|
12
|
+
const tools_2 = require("./utils/tools.js");
|
|
13
|
+
const context_1 = require("./tracing/context.js");
|
|
14
|
+
const logger_1 = __importDefault(require("./logger.js"));
|
|
6
15
|
/**
|
|
7
16
|
* Generates the message that will be given as tool output to the model that requested the handoff.
|
|
8
17
|
*
|
|
9
18
|
* @param agent The agent to transfer to
|
|
10
19
|
* @returns The message that will be given as tool output to the model that requested the handoff
|
|
11
20
|
*/
|
|
12
|
-
|
|
21
|
+
function getTransferMessage(agent) {
|
|
13
22
|
return JSON.stringify({ assistant: agent.name });
|
|
14
23
|
}
|
|
15
24
|
/**
|
|
@@ -19,7 +28,7 @@ export function getTransferMessage(agent) {
|
|
|
19
28
|
* @returns The name of the tool that represents the handoff
|
|
20
29
|
*/
|
|
21
30
|
function defaultHandoffToolName(agent) {
|
|
22
|
-
return `transfer_to_${toFunctionToolName(agent.name)}`;
|
|
31
|
+
return `transfer_to_${(0, tools_1.toFunctionToolName)(agent.name)}`;
|
|
23
32
|
}
|
|
24
33
|
/**
|
|
25
34
|
* Generates the description of the tool that represents the handoff.
|
|
@@ -39,7 +48,7 @@ function defaultHandoffToolDescription(agent) {
|
|
|
39
48
|
* @template TContext The context of the handoff
|
|
40
49
|
* @template TOutput The output type of the handoff
|
|
41
50
|
*/
|
|
42
|
-
|
|
51
|
+
class Handoff {
|
|
43
52
|
/**
|
|
44
53
|
* The name of the tool that represents the handoff.
|
|
45
54
|
*/
|
|
@@ -110,6 +119,7 @@ export class Handoff {
|
|
|
110
119
|
this.agent = agent;
|
|
111
120
|
}
|
|
112
121
|
}
|
|
122
|
+
exports.Handoff = Handoff;
|
|
113
123
|
/**
|
|
114
124
|
* Creates a handoff from an agent. Handoffs are automatically created when you pass an agent
|
|
115
125
|
* into the `handoffs` option of the `Agent` constructor. Alternatively, you can use this function
|
|
@@ -119,24 +129,24 @@ export class Handoff {
|
|
|
119
129
|
* @template TOutput The output type of the handoff
|
|
120
130
|
* @template TInputType The input type of the handoff
|
|
121
131
|
*/
|
|
122
|
-
|
|
132
|
+
function handoff(agent, config = {}) {
|
|
123
133
|
let parser = undefined;
|
|
124
134
|
const hasOnHandoff = !!config.onHandoff;
|
|
125
135
|
const hasInputType = !!config.inputType;
|
|
126
136
|
const hasBothOrNeitherHandoffAndInputType = hasOnHandoff === hasInputType;
|
|
127
137
|
if (!hasBothOrNeitherHandoffAndInputType) {
|
|
128
|
-
throw new UserError('You must provide either both `onHandoff` and `inputType` or neither.');
|
|
138
|
+
throw new errors_1.UserError('You must provide either both `onHandoff` and `inputType` or neither.');
|
|
129
139
|
}
|
|
130
140
|
async function onInvokeHandoff(context, inputJsonString) {
|
|
131
141
|
if (parser) {
|
|
132
142
|
if (!inputJsonString) {
|
|
133
|
-
addErrorToCurrentSpan({
|
|
143
|
+
(0, context_1.addErrorToCurrentSpan)({
|
|
134
144
|
message: `Handoff function expected non empty input but got: ${inputJsonString}`,
|
|
135
145
|
data: {
|
|
136
146
|
details: `input is empty`,
|
|
137
147
|
},
|
|
138
148
|
});
|
|
139
|
-
throw new ModelBehaviorError('Handoff function expected non empty input');
|
|
149
|
+
throw new errors_1.ModelBehaviorError('Handoff function expected non empty input');
|
|
140
150
|
}
|
|
141
151
|
try {
|
|
142
152
|
// verify that it's valid input but we don't care about the result
|
|
@@ -146,14 +156,14 @@ export function handoff(agent, config = {}) {
|
|
|
146
156
|
}
|
|
147
157
|
}
|
|
148
158
|
catch (error) {
|
|
149
|
-
addErrorToCurrentSpan({
|
|
159
|
+
(0, context_1.addErrorToCurrentSpan)({
|
|
150
160
|
message: `Invalid JSON provided`,
|
|
151
161
|
data: {},
|
|
152
162
|
});
|
|
153
|
-
if (!
|
|
154
|
-
|
|
163
|
+
if (!logger_1.default.dontLogToolData) {
|
|
164
|
+
logger_1.default.error(`Invalid JSON when parsing: ${inputJsonString}. Error: ${error}`);
|
|
155
165
|
}
|
|
156
|
-
throw new ModelBehaviorError('Invalid JSON provided');
|
|
166
|
+
throw new errors_1.ModelBehaviorError('Invalid JSON provided');
|
|
157
167
|
}
|
|
158
168
|
}
|
|
159
169
|
else {
|
|
@@ -163,7 +173,7 @@ export function handoff(agent, config = {}) {
|
|
|
163
173
|
}
|
|
164
174
|
const handoff = new Handoff(agent, onInvokeHandoff);
|
|
165
175
|
if (config.inputType) {
|
|
166
|
-
const result = getSchemaAndParserFromInputType(config.inputType, handoff.toolName);
|
|
176
|
+
const result = (0, tools_2.getSchemaAndParserFromInputType)(config.inputType, handoff.toolName);
|
|
167
177
|
handoff.inputJsonSchema = result.schema;
|
|
168
178
|
handoff.strictJsonSchema = true;
|
|
169
179
|
parser = result.parser;
|
|
@@ -186,7 +196,7 @@ export function handoff(agent, config = {}) {
|
|
|
186
196
|
* @template TContext The context of the handoff
|
|
187
197
|
* @template TOutput The output type of the handoff
|
|
188
198
|
*/
|
|
189
|
-
|
|
199
|
+
function getHandoff(agent) {
|
|
190
200
|
if (agent instanceof Handoff) {
|
|
191
201
|
return agent;
|
|
192
202
|
}
|
package/dist/handoff.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handoff.js","sourceRoot":"","sources":["../src/handoff.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handoff.js","sourceRoot":"","sources":["../src/handoff.ts"],"names":[],"mappings":";;;;;;AAmDA,gDAIC;AAmLD,0BAmFC;AASD,gCAQC;AApUD,wCAAyD;AAEzD,4CAAmD;AACnD,4CAAgE;AAChE,kDAA0D;AAC1D,yDAA8B;AA8B9B;;;;;GAKG;AACH,SAAgB,kBAAkB,CAChC,KAA+B;IAE/B,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;AACnD,CAAC;AAED;;;;;GAKG;AACH,SAAS,sBAAsB,CAC7B,KAA+B;IAE/B,OAAO,eAAe,IAAA,0BAAkB,EAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;AACzD,CAAC;AAED;;;;;GAKG;AACH,SAAS,6BAA6B,CAGpC,KAA+B;IAC/B,OAAO,kBAAkB,KAAK,CAAC,IAAI,iCACjC,KAAK,CAAC,kBAAkB,IAAI,EAC9B,EAAE,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,MAAa,OAAO;IAIlB;;OAEG;IACI,QAAQ,CAAS;IAExB;;OAEG;IACI,eAAe,CAAS;IAE/B;;OAEG;IACI,eAAe,GAA0B;QAC9C,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,EAAE;QACd,QAAQ,EAAE,EAAE;QACZ,oBAA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