@openai/agents-core 0.2.0 → 0.3.0
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/index.d.ts +3 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/memory/memorySession.d.ts +22 -0
- package/dist/memory/memorySession.js +64 -0
- package/dist/memory/memorySession.js.map +1 -0
- package/dist/memory/memorySession.mjs +60 -0
- package/dist/memory/memorySession.mjs.map +1 -0
- package/dist/memory/session.d.ts +36 -0
- package/dist/memory/session.js +3 -0
- package/dist/memory/session.js.map +1 -0
- package/dist/memory/session.mjs +2 -0
- package/dist/memory/session.mjs.map +1 -0
- package/dist/metadata.js +3 -3
- package/dist/metadata.js.map +1 -1
- package/dist/metadata.mjs +3 -3
- package/dist/metadata.mjs.map +1 -1
- package/dist/run.d.ts +88 -8
- package/dist/run.js +859 -347
- package/dist/run.js.map +1 -1
- package/dist/run.mjs +859 -347
- package/dist/run.mjs.map +1 -1
- package/dist/runImplementation.d.ts +21 -2
- package/dist/runImplementation.js +885 -346
- package/dist/runImplementation.js.map +1 -1
- package/dist/runImplementation.mjs +877 -344
- package/dist/runImplementation.mjs.map +1 -1
- package/dist/runState.d.ts +1360 -226
- package/dist/runState.js +16 -0
- package/dist/runState.js.map +1 -1
- package/dist/runState.mjs +16 -0
- package/dist/runState.mjs.map +1 -1
- package/dist/types/protocol.d.ts +1869 -193
- package/dist/types/protocol.js +1 -0
- package/dist/types/protocol.js.map +1 -1
- package/dist/types/protocol.mjs +1 -0
- package/dist/types/protocol.mjs.map +1 -1
- package/dist/utils/smartString.d.ts +9 -0
- package/dist/utils/smartString.js +15 -0
- package/dist/utils/smartString.js.map +1 -1
- package/dist/utils/smartString.mjs +14 -3
- package/dist/utils/smartString.mjs.map +1 -1
- package/dist/utils/tools.js +59 -20
- package/dist/utils/tools.js.map +1 -1
- package/dist/utils/tools.mjs +59 -20
- package/dist/utils/tools.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export { OPENAI_DEFAULT_MODEL_ENV_VARIABLE_NAME, gpt5ReasoningSettingsRequired,
|
|
|
16
16
|
export { setDefaultModelProvider } from './providers';
|
|
17
17
|
export { RunResult, StreamedRunResult } from './result';
|
|
18
18
|
export { IndividualRunOptions, NonStreamRunOptions, run, RunConfig, Runner, StreamRunOptions, } from './run';
|
|
19
|
+
export type { ModelInputData, CallModelInputFilter, CallModelInputFilterArgs, } from './run';
|
|
19
20
|
export { RunContext } from './runContext';
|
|
20
21
|
export { RunState } from './runState';
|
|
21
22
|
export { HostedTool, ComputerTool, computerTool, HostedMCPTool, hostedMcpTool, FunctionTool, FunctionToolResult, Tool, tool, ToolExecuteArgument, ToolEnabledFunction, } from './tool';
|
|
@@ -24,6 +25,8 @@ export * from './tracing';
|
|
|
24
25
|
export { getGlobalTraceProvider, TraceProvider } from './tracing/provider';
|
|
25
26
|
export type { AgentInputItem, AgentOutputItem, AssistantMessageItem, HostedToolCallItem, ComputerCallResultItem, ComputerUseCallItem, FunctionCallItem, FunctionCallResultItem, JsonSchemaDefinition, ReasoningItem, ResponseStreamEvent, SystemMessageItem, TextOutput, UnknownContext, UnknownItem, UserMessageItem, StreamEvent, StreamEventTextStream, StreamEventResponseCompleted, StreamEventResponseStarted, StreamEventGenericItem, } from './types';
|
|
26
27
|
export { Usage } from './usage';
|
|
28
|
+
export type { Session, SessionInputCallback } from './memory/session';
|
|
29
|
+
export { MemorySession } from './memory/memorySession';
|
|
27
30
|
/**
|
|
28
31
|
* Exporting the whole protocol as an object here. This contains both the types
|
|
29
32
|
* and the zod schemas for parsing the protocol.
|
package/dist/index.js
CHANGED
|
@@ -37,7 +37,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
37
37
|
})();
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.RunContext = exports.Runner = exports.run = exports.StreamedRunResult = exports.RunResult = exports.setDefaultModelProvider = exports.isGpt5Default = exports.getDefaultModelSettings = exports.getDefaultModel = exports.gpt5ReasoningSettingsRequired = exports.OPENAI_DEFAULT_MODEL_ENV_VARIABLE_NAME = exports.createMCPToolStaticFilter = exports.MCPServerSSE = exports.MCPServerStreamableHttp = exports.MCPServerStdio = exports.mcpToFunctionTool = exports.invalidateServerToolsCache = exports.getAllMcpTools = exports.getLogger = exports.AgentHooks = exports.RunToolCallOutputItem = exports.RunToolCallItem = exports.RunToolApprovalItem = exports.RunReasoningItem = exports.RunMessageOutputItem = exports.RunHandoffOutputItem = exports.RunHandoffCallItem = exports.extractAllTextOutput = exports.user = exports.system = exports.assistant = exports.handoff = exports.Handoff = exports.getTransferMessage = exports.getHandoff = exports.defineOutputGuardrail = exports.RunItemStreamEvent = exports.RunRawModelStreamEvent = exports.RunAgentUpdatedStreamEvent = exports.SystemError = exports.UserError = exports.ToolCallError = exports.OutputGuardrailTripwireTriggered = exports.ModelBehaviorError = exports.MaxTurnsExceededError = exports.InputGuardrailTripwireTriggered = exports.GuardrailExecutionError = exports.AgentsError = exports.Agent = exports.RuntimeEventEmitter = void 0;
|
|
40
|
-
exports.protocol = exports.Usage = exports.TraceProvider = exports.getGlobalTraceProvider = exports.tool = exports.hostedMcpTool = exports.computerTool = exports.RunState = void 0;
|
|
40
|
+
exports.protocol = exports.MemorySession = exports.Usage = exports.TraceProvider = exports.getGlobalTraceProvider = exports.tool = exports.hostedMcpTool = exports.computerTool = exports.RunState = void 0;
|
|
41
41
|
const tracing_1 = require("./tracing/index.js");
|
|
42
42
|
const processor_1 = require("./tracing/processor.js");
|
|
43
43
|
var _shims_1 = require("@openai/agents-core/_shims");
|
|
@@ -119,6 +119,8 @@ Object.defineProperty(exports, "getGlobalTraceProvider", { enumerable: true, get
|
|
|
119
119
|
Object.defineProperty(exports, "TraceProvider", { enumerable: true, get: function () { return provider_1.TraceProvider; } });
|
|
120
120
|
var usage_1 = require("./usage.js");
|
|
121
121
|
Object.defineProperty(exports, "Usage", { enumerable: true, get: function () { return usage_1.Usage; } });
|
|
122
|
+
var memorySession_1 = require("./memory/memorySession.js");
|
|
123
|
+
Object.defineProperty(exports, "MemorySession", { enumerable: true, get: function () { return memorySession_1.MemorySession; } });
|
|
122
124
|
/**
|
|
123
125
|
* Exporting the whole protocol as an object here. This contains both the types
|
|
124
126
|
* and the zod schemas for parsing the protocol.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA8C;AAC9C,sDAAuD;AAEvD,qDAAiE;AAAxD,6GAAA,mBAAmB,OAAA;AAC5B,oCAUiB;AATf,8FAAA,KAAK,OAAA;AAWP,sCAUkB;AAThB,qGAAA,WAAW,OAAA;AACX,iHAAA,uBAAuB,OAAA;AACvB,yHAAA,+BAA+B,OAAA;AAC/B,+GAAA,qBAAqB,OAAA;AACrB,4GAAA,kBAAkB,OAAA;AAClB,0HAAA,gCAAgC,OAAA;AAChC,uGAAA,aAAa,OAAA;AACb,mGAAA,SAAS,OAAA;AACT,qGAAA,WAAW,OAAA;AAEb,sCAKkB;AAJhB,oHAAA,0BAA0B,OAAA;AAC1B,gHAAA,sBAAsB,OAAA;AACtB,4GAAA,kBAAkB,OAAA;AAGpB,4CAcqB;AAbnB,kHAAA,qBAAqB,OAAA;AAcvB,wCAOmB;AANjB,qGAAA,UAAU,OAAA;AACV,6GAAA,kBAAkB,OAAA;AAClB,kGAAA,OAAO,OAAA;AACP,kGAAA,OAAO,OAAA;AAIT,gDAA4D;AAAnD,oGAAA,SAAS,OAAA;AAAE,iGAAA,MAAM,OAAA;AAAE,+FAAA,IAAI,OAAA;AAChC,oCAUiB;AATf,6GAAA,oBAAoB,OAAA;AACpB,2GAAA,kBAAkB,OAAA;AAClB,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AAQR,8CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,0CAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,kCAYgB;AATd,oGAAA,YAAY,OAAA;AAEZ,qGAAA,aAAa,OAAA;AAIb,4FAAA,IAAI,OAAA;AAWN,qDAA0B;AAC1B,kDAA2E;AAAlE,kHAAA,sBAAsB,OAAA;AAAE,yGAAA,aAAa,OAAA;AAyB9C,oCAAgC;AAAvB,8FAAA,KAAK,OAAA;AAEd,2DAAuD;AAA9C,8GAAA,aAAa,OAAA;AAEtB;;;GAGG;AACH,gEAA6C;AAE7C;;;;;GAKG;AACH,IAAA,2BAAiB,EAAC,IAAA,4BAAgB,GAAE,CAAC,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -22,6 +22,7 @@ export { computerTool, hostedMcpTool, tool, } from "./tool.mjs";
|
|
|
22
22
|
export * from "./tracing/index.mjs";
|
|
23
23
|
export { getGlobalTraceProvider, TraceProvider } from "./tracing/provider.mjs";
|
|
24
24
|
export { Usage } from "./usage.mjs";
|
|
25
|
+
export { MemorySession } from "./memory/memorySession.mjs";
|
|
25
26
|
export * as protocol from "./types/protocol.mjs";
|
|
26
27
|
/**
|
|
27
28
|
* Add the default processor, which exports traces and spans to the backend in batches. You can
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"OAAO,EAAE,iBAAiB,EAAE;OACrB,EAAE,gBAAgB,EAAE;OAEpB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B;OACzD,EACL,KAAK,GASN;OAEM,EACL,WAAW,EACX,uBAAuB,EACvB,+BAA+B,EAC/B,qBAAqB,EACrB,kBAAkB,EAClB,gCAAgC,EAChC,aAAa,EACb,SAAS,EACT,WAAW,GACZ;OACM,EACL,0BAA0B,EAC1B,sBAAsB,EACtB,kBAAkB,GAEnB;OACM,EACL,qBAAqB,GAatB;OACM,EACL,UAAU,EACV,kBAAkB,EAClB,OAAO,EACP,OAAO,GAGR;OACM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE;OAC3B,EACL,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EAEpB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,qBAAqB,GACtB;OACM,EAAE,UAAU,EAAE;OACd,EAAE,SAAS,EAAE;OACb,EACL,cAAc,EACd,0BAA0B,EAC1B,iBAAiB,EAEjB,cAAc,EACd,uBAAuB,EACvB,YAAY,GAEb;OACM,EAIL,yBAAyB,GAC1B;OAYM,EACL,sCAAsC,EACtC,6BAA6B,EAC7B,eAAe,EACf,uBAAuB,EACvB,aAAa,GACd;OACM,EAAE,uBAAuB,EAAE;OAC3B,EAAE,SAAS,EAAE,iBAAiB,EAAE;OAChC,EAGL,GAAG,EAEH,MAAM,GAEP;
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"OAAO,EAAE,iBAAiB,EAAE;OACrB,EAAE,gBAAgB,EAAE;OAEpB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B;OACzD,EACL,KAAK,GASN;OAEM,EACL,WAAW,EACX,uBAAuB,EACvB,+BAA+B,EAC/B,qBAAqB,EACrB,kBAAkB,EAClB,gCAAgC,EAChC,aAAa,EACb,SAAS,EACT,WAAW,GACZ;OACM,EACL,0BAA0B,EAC1B,sBAAsB,EACtB,kBAAkB,GAEnB;OACM,EACL,qBAAqB,GAatB;OACM,EACL,UAAU,EACV,kBAAkB,EAClB,OAAO,EACP,OAAO,GAGR;OACM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE;OAC3B,EACL,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EAEpB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,qBAAqB,GACtB;OACM,EAAE,UAAU,EAAE;OACd,EAAE,SAAS,EAAE;OACb,EACL,cAAc,EACd,0BAA0B,EAC1B,iBAAiB,EAEjB,cAAc,EACd,uBAAuB,EACvB,YAAY,GAEb;OACM,EAIL,yBAAyB,GAC1B;OAYM,EACL,sCAAsC,EACtC,6BAA6B,EAC7B,eAAe,EACf,uBAAuB,EACvB,aAAa,GACd;OACM,EAAE,uBAAuB,EAAE;OAC3B,EAAE,SAAS,EAAE,iBAAiB,EAAE;OAChC,EAGL,GAAG,EAEH,MAAM,GAEP;OAMM,EAAE,UAAU,EAAE;OACd,EAAE,QAAQ,EAAE;OACZ,EAGL,YAAY,EAEZ,aAAa,EAIb,IAAI,GAGL;;OASM,EAAE,sBAAsB,EAAE,aAAa,EAAE;OAyBzC,EAAE,KAAK,EAAE;OAET,EAAE,aAAa,EAAE;OAMjB,KAAK,QAAQ;AAEpB;;;;;GAKG;AACH,iBAAiB,CAAC,gBAAgB,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AgentInputItem } from '../types';
|
|
2
|
+
import type { Session } from './session';
|
|
3
|
+
import { Logger } from '../logger';
|
|
4
|
+
export type MemorySessionOptions = {
|
|
5
|
+
sessionId?: string;
|
|
6
|
+
initialItems?: AgentInputItem[];
|
|
7
|
+
logger?: Logger;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Simple in-memory session store intended for demos or tests. Not recommended for production use.
|
|
11
|
+
*/
|
|
12
|
+
export declare class MemorySession implements Session {
|
|
13
|
+
private readonly sessionId;
|
|
14
|
+
private readonly logger;
|
|
15
|
+
private items;
|
|
16
|
+
constructor(options?: MemorySessionOptions);
|
|
17
|
+
getSessionId(): Promise<string>;
|
|
18
|
+
getItems(limit?: number): Promise<AgentInputItem[]>;
|
|
19
|
+
addItems(items: AgentInputItem[]): Promise<void>;
|
|
20
|
+
popItem(): Promise<AgentInputItem | undefined>;
|
|
21
|
+
clearSession(): Promise<void>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemorySession = void 0;
|
|
4
|
+
const _shims_1 = require("@openai/agents-core/_shims");
|
|
5
|
+
const logger_1 = require("../logger.js");
|
|
6
|
+
/**
|
|
7
|
+
* Simple in-memory session store intended for demos or tests. Not recommended for production use.
|
|
8
|
+
*/
|
|
9
|
+
class MemorySession {
|
|
10
|
+
sessionId;
|
|
11
|
+
logger;
|
|
12
|
+
items;
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
this.sessionId = options.sessionId ?? (0, _shims_1.randomUUID)();
|
|
15
|
+
this.items = options.initialItems
|
|
16
|
+
? options.initialItems.map(cloneAgentItem)
|
|
17
|
+
: [];
|
|
18
|
+
this.logger = options.logger ?? logger_1.logger;
|
|
19
|
+
}
|
|
20
|
+
async getSessionId() {
|
|
21
|
+
return this.sessionId;
|
|
22
|
+
}
|
|
23
|
+
async getItems(limit) {
|
|
24
|
+
if (limit === undefined) {
|
|
25
|
+
const cloned = this.items.map(cloneAgentItem);
|
|
26
|
+
this.logger.debug(`Getting items from memory session (${this.sessionId}): ${JSON.stringify(cloned)}`);
|
|
27
|
+
return cloned;
|
|
28
|
+
}
|
|
29
|
+
if (limit <= 0) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
const start = Math.max(this.items.length - limit, 0);
|
|
33
|
+
const items = this.items.slice(start).map(cloneAgentItem);
|
|
34
|
+
this.logger.debug(`Getting items from memory session (${this.sessionId}): ${JSON.stringify(items)}`);
|
|
35
|
+
return items;
|
|
36
|
+
}
|
|
37
|
+
async addItems(items) {
|
|
38
|
+
if (items.length === 0) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const cloned = items.map(cloneAgentItem);
|
|
42
|
+
this.logger.debug(`Adding items to memory session (${this.sessionId}): ${JSON.stringify(cloned)}`);
|
|
43
|
+
this.items = [...this.items, ...cloned];
|
|
44
|
+
}
|
|
45
|
+
async popItem() {
|
|
46
|
+
if (this.items.length === 0) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const item = this.items[this.items.length - 1];
|
|
50
|
+
const cloned = cloneAgentItem(item);
|
|
51
|
+
this.logger.debug(`Popping item from memory session (${this.sessionId}): ${JSON.stringify(cloned)}`);
|
|
52
|
+
this.items = this.items.slice(0, -1);
|
|
53
|
+
return cloned;
|
|
54
|
+
}
|
|
55
|
+
async clearSession() {
|
|
56
|
+
this.logger.debug(`Clearing memory session (${this.sessionId})`);
|
|
57
|
+
this.items = [];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.MemorySession = MemorySession;
|
|
61
|
+
function cloneAgentItem(item) {
|
|
62
|
+
return structuredClone(item);
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=memorySession.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memorySession.js","sourceRoot":"","sources":["../../src/memory/memorySession.ts"],"names":[],"mappings":";;;AAAA,uDAAwD;AAIxD,yCAA2C;AAQ3C;;GAEG;AACH,MAAa,aAAa;IACP,SAAS,CAAS;IAClB,MAAM,CAAS;IAExB,KAAK,CAAmB;IAEhC,YAAY,UAAgC,EAAE;QAC5C,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,IAAA,mBAAU,GAAE,CAAC;QACnD,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,YAAY;YAC/B,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC;YAC1C,CAAC,CAAC,EAAE,CAAC;QACP,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,eAAM,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,KAAc;QAC3B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB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ACD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC/C,MAAM,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,qCAAqC,IAAI,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAClF,CAAC;QACF,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACrC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,4BAA4B,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;QACjE,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,CAAC;CACF;AAjED,sCAiEC;AAED,SAAS,cAAc,CAA2B,IAAO;IACvD,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { randomUUID } from '@openai/agents-core/_shims';
|
|
2
|
+
import { logger } from "../logger.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Simple in-memory session store intended for demos or tests. Not recommended for production use.
|
|
5
|
+
*/
|
|
6
|
+
export class MemorySession {
|
|
7
|
+
sessionId;
|
|
8
|
+
logger;
|
|
9
|
+
items;
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
this.sessionId = options.sessionId ?? randomUUID();
|
|
12
|
+
this.items = options.initialItems
|
|
13
|
+
? options.initialItems.map(cloneAgentItem)
|
|
14
|
+
: [];
|
|
15
|
+
this.logger = options.logger ?? logger;
|
|
16
|
+
}
|
|
17
|
+
async getSessionId() {
|
|
18
|
+
return this.sessionId;
|
|
19
|
+
}
|
|
20
|
+
async getItems(limit) {
|
|
21
|
+
if (limit === undefined) {
|
|
22
|
+
const cloned = this.items.map(cloneAgentItem);
|
|
23
|
+
this.logger.debug(`Getting items from memory session (${this.sessionId}): ${JSON.stringify(cloned)}`);
|
|
24
|
+
return cloned;
|
|
25
|
+
}
|
|
26
|
+
if (limit <= 0) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
const start = Math.max(this.items.length - limit, 0);
|
|
30
|
+
const items = this.items.slice(start).map(cloneAgentItem);
|
|
31
|
+
this.logger.debug(`Getting items from memory session (${this.sessionId}): ${JSON.stringify(items)}`);
|
|
32
|
+
return items;
|
|
33
|
+
}
|
|
34
|
+
async addItems(items) {
|
|
35
|
+
if (items.length === 0) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const cloned = items.map(cloneAgentItem);
|
|
39
|
+
this.logger.debug(`Adding items to memory session (${this.sessionId}): ${JSON.stringify(cloned)}`);
|
|
40
|
+
this.items = [...this.items, ...cloned];
|
|
41
|
+
}
|
|
42
|
+
async popItem() {
|
|
43
|
+
if (this.items.length === 0) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const item = this.items[this.items.length - 1];
|
|
47
|
+
const cloned = cloneAgentItem(item);
|
|
48
|
+
this.logger.debug(`Popping item from memory session (${this.sessionId}): ${JSON.stringify(cloned)}`);
|
|
49
|
+
this.items = this.items.slice(0, -1);
|
|
50
|
+
return cloned;
|
|
51
|
+
}
|
|
52
|
+
async clearSession() {
|
|
53
|
+
this.logger.debug(`Clearing memory session (${this.sessionId})`);
|
|
54
|
+
this.items = [];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function cloneAgentItem(item) {
|
|
58
|
+
return structuredClone(item);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=memorySession.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memorySession.mjs","sourceRoot":"","sources":["../../src/memory/memorySession.ts"],"names":[],"mappings":"OAAO,EAAE,UAAU,EAA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ACvD,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { AgentInputItem } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* A function that combines session history with new input items before the model call.
|
|
4
|
+
*/
|
|
5
|
+
export type SessionInputCallback = (historyItems: AgentInputItem[], newItems: AgentInputItem[]) => AgentInputItem[] | Promise<AgentInputItem[]>;
|
|
6
|
+
/**
|
|
7
|
+
* Interface representing a persistent session store for conversation history.
|
|
8
|
+
*/
|
|
9
|
+
export interface Session {
|
|
10
|
+
/**
|
|
11
|
+
* Ensure and return the identifier for this session.
|
|
12
|
+
*/
|
|
13
|
+
getSessionId(): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Retrieve items from the conversation history.
|
|
16
|
+
*
|
|
17
|
+
* @param limit - The maximum number of items to return. When provided the most
|
|
18
|
+
* recent {@link limit} items should be returned in chronological order.
|
|
19
|
+
*/
|
|
20
|
+
getItems(limit?: number): Promise<AgentInputItem[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Append new items to the conversation history.
|
|
23
|
+
*
|
|
24
|
+
* @param items - Items to add to the session history.
|
|
25
|
+
*/
|
|
26
|
+
addItems(items: AgentInputItem[]): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Remove and return the most recent item from the conversation history if it
|
|
29
|
+
* exists.
|
|
30
|
+
*/
|
|
31
|
+
popItem(): Promise<AgentInputItem | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* Remove all items that belong to the session and reset its state.
|
|
34
|
+
*/
|
|
35
|
+
clearSession(): Promise<void>;
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/memory/session.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.mjs","sourceRoot":"","sources":["../../src/memory/session.ts"],"names":[],"mappings":""}
|
package/dist/metadata.js
CHANGED
|
@@ -4,10 +4,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.METADATA = void 0;
|
|
5
5
|
exports.METADATA = {
|
|
6
6
|
"name": "@openai/agents-core",
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.3.0",
|
|
8
8
|
"versions": {
|
|
9
|
-
"@openai/agents-core": "0.
|
|
10
|
-
"openai": "^
|
|
9
|
+
"@openai/agents-core": "0.3.0",
|
|
10
|
+
"openai": "^6"
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
13
|
exports.default = exports.METADATA;
|
package/dist/metadata.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":";AACA,uCAAuC;;;AAE1B,QAAA,QAAQ,GAAG;IACtB,MAAM,EAAE,qBAAqB;IAC7B,SAAS,EAAE,OAAO;IAClB,UAAU,EAAE;QACV,qBAAqB,EAAE,OAAO;QAC9B,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":";AACA,uCAAuC;;;AAE1B,QAAA,QAAQ,GAAG;IACtB,MAAM,EAAE,qBAAqB;IAC7B,SAAS,EAAE,OAAO;IAClB,UAAU,EAAE;QACV,qBAAqB,EAAE,OAAO;QAC9B,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,kBAAe,gBAAQ,CAAC"}
|
package/dist/metadata.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// This file is automatically generated
|
|
2
2
|
export const METADATA = {
|
|
3
3
|
"name": "@openai/agents-core",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"versions": {
|
|
6
|
-
"@openai/agents-core": "0.
|
|
7
|
-
"openai": "^
|
|
6
|
+
"@openai/agents-core": "0.3.0",
|
|
7
|
+
"openai": "^6"
|
|
8
8
|
}
|
|
9
9
|
};
|
|
10
10
|
export default METADATA;
|
package/dist/metadata.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.mjs","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AACA,uCAAuC;AAEvC,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,MAAM,EAAE,qBAAqB;IAC7B,SAAS,EAAE,OAAO;IAClB,UAAU,EAAE;QACV,qBAAqB,EAAE,OAAO;QAC9B,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"metadata.mjs","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AACA,uCAAuC;AAEvC,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,MAAM,EAAE,qBAAqB;IAC7B,SAAS,EAAE,OAAO;IAClB,UAAU,EAAE;QACV,qBAAqB,EAAE,OAAO;QAC9B,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
package/dist/run.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Agent, AgentOutputType } from './agent';
|
|
2
2
|
import { InputGuardrail, OutputGuardrail } from './guardrail';
|
|
3
3
|
import { HandoffInputFilter } from './handoff';
|
|
4
|
-
import { Model, ModelProvider, ModelSettings } from './model';
|
|
4
|
+
import { Model, ModelProvider, ModelSettings, ModelTracing } from './model';
|
|
5
5
|
import { RunContext } from './runContext';
|
|
6
6
|
import { AgentInputItem } from './types';
|
|
7
7
|
import { RunResult, StreamedRunResult } from './result';
|
|
8
8
|
import { RunHooks } from './lifecycle';
|
|
9
9
|
import { RunItem } from './items';
|
|
10
10
|
import { RunState } from './runState';
|
|
11
|
+
import type { Session, SessionInputCallback } from './memory/session';
|
|
11
12
|
/**
|
|
12
13
|
* Configures settings for the entire agent run.
|
|
13
14
|
*/
|
|
@@ -68,36 +69,74 @@ export type RunConfig = {
|
|
|
68
69
|
* An optional dictionary of additional metadata to include with the trace.
|
|
69
70
|
*/
|
|
70
71
|
traceMetadata?: Record<string, string>;
|
|
72
|
+
/**
|
|
73
|
+
* Customizes how session history is combined with the current turn's input.
|
|
74
|
+
* When omitted, history items are appended before the new input.
|
|
75
|
+
*/
|
|
76
|
+
sessionInputCallback?: SessionInputCallback;
|
|
77
|
+
/**
|
|
78
|
+
* Invoked immediately before calling the model, allowing callers to edit the
|
|
79
|
+
* system instructions or input items that will be sent to the model.
|
|
80
|
+
*/
|
|
81
|
+
callModelInputFilter?: CallModelInputFilter;
|
|
71
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* Common run options shared between streaming and non-streaming execution pathways.
|
|
85
|
+
*/
|
|
72
86
|
type SharedRunOptions<TContext = undefined> = {
|
|
73
87
|
context?: TContext | RunContext<TContext>;
|
|
74
88
|
maxTurns?: number;
|
|
75
89
|
signal?: AbortSignal;
|
|
76
90
|
previousResponseId?: string;
|
|
77
91
|
conversationId?: string;
|
|
92
|
+
session?: Session;
|
|
93
|
+
sessionInputCallback?: SessionInputCallback;
|
|
94
|
+
callModelInputFilter?: CallModelInputFilter;
|
|
78
95
|
};
|
|
96
|
+
/**
|
|
97
|
+
* Options for runs that stream incremental events as the model responds.
|
|
98
|
+
*/
|
|
79
99
|
export type StreamRunOptions<TContext = undefined> = SharedRunOptions<TContext> & {
|
|
80
100
|
/**
|
|
81
101
|
* Whether to stream the run. If true, the run will emit events as the model responds.
|
|
82
102
|
*/
|
|
83
103
|
stream: true;
|
|
84
104
|
};
|
|
105
|
+
/**
|
|
106
|
+
* Options for runs that collect the full model response before returning.
|
|
107
|
+
*/
|
|
85
108
|
export type NonStreamRunOptions<TContext = undefined> = SharedRunOptions<TContext> & {
|
|
86
109
|
/**
|
|
87
|
-
*
|
|
110
|
+
* Run to completion without streaming incremental events; leave undefined or set to `false`.
|
|
88
111
|
*/
|
|
89
112
|
stream?: false;
|
|
90
113
|
};
|
|
114
|
+
/**
|
|
115
|
+
* Options polymorphic over streaming or non-streaming execution modes.
|
|
116
|
+
*/
|
|
91
117
|
export type IndividualRunOptions<TContext = undefined> = StreamRunOptions<TContext> | NonStreamRunOptions<TContext>;
|
|
92
|
-
export declare function getTurnInput(originalInput: string | AgentInputItem[], generatedItems: RunItem[]): AgentInputItem[];
|
|
93
118
|
/**
|
|
94
|
-
*
|
|
119
|
+
* Executes an agent workflow with the shared default `Runner` instance.
|
|
120
|
+
*
|
|
121
|
+
* @param agent - The entry agent to invoke.
|
|
122
|
+
* @param input - A string utterance, structured input items, or a resumed `RunState`.
|
|
123
|
+
* @param options - Controls streaming mode, context, session handling, and turn limits.
|
|
124
|
+
* @returns A `RunResult` when `stream` is false, otherwise a `StreamedRunResult`.
|
|
125
|
+
*/
|
|
126
|
+
export declare function run<TAgent extends Agent<any, any>, TContext = undefined>(agent: TAgent, input: string | AgentInputItem[] | RunState<TContext, TAgent>, options?: NonStreamRunOptions<TContext>): Promise<RunResult<TContext, TAgent>>;
|
|
127
|
+
export declare function run<TAgent extends Agent<any, any>, TContext = undefined>(agent: TAgent, input: string | AgentInputItem[] | RunState<TContext, TAgent>, options?: StreamRunOptions<TContext>): Promise<StreamedRunResult<TContext, TAgent>>;
|
|
128
|
+
/**
|
|
129
|
+
* Orchestrates agent execution, including guardrails, tool calls, session persistence, and
|
|
130
|
+
* tracing. Reuse a `Runner` instance when you want consistent configuration across multiple runs.
|
|
95
131
|
*/
|
|
96
132
|
export declare class Runner extends RunHooks<any, AgentOutputType<unknown>> {
|
|
97
133
|
#private;
|
|
98
134
|
readonly config: RunConfig;
|
|
99
|
-
|
|
100
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Creates a runner with optional defaults that apply to every subsequent run invocation.
|
|
137
|
+
*
|
|
138
|
+
* @param config - Overrides for models, guardrails, tracing, or session behavior.
|
|
139
|
+
*/
|
|
101
140
|
constructor(config?: Partial<RunConfig>);
|
|
102
141
|
/**
|
|
103
142
|
* Run a workflow starting at the given agent. The agent will run in a loop until a final
|
|
@@ -123,8 +162,49 @@ export declare class Runner extends RunHooks<any, AgentOutputType<unknown>> {
|
|
|
123
162
|
*/
|
|
124
163
|
run<TAgent extends Agent<any, any>, TContext = undefined>(agent: TAgent, input: string | AgentInputItem[] | RunState<TContext, TAgent>, options?: NonStreamRunOptions<TContext>): Promise<RunResult<TContext, TAgent>>;
|
|
125
164
|
run<TAgent extends Agent<any, any>, TContext = undefined>(agent: TAgent, input: string | AgentInputItem[] | RunState<TContext, TAgent>, options?: StreamRunOptions<TContext>): Promise<StreamedRunResult<TContext, TAgent>>;
|
|
165
|
+
private readonly inputGuardrailDefs;
|
|
166
|
+
private readonly outputGuardrailDefs;
|
|
126
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Mutable view of the instructions + input items that the model will receive.
|
|
170
|
+
* Filters always see a copy so they can edit without side effects.
|
|
171
|
+
*/
|
|
172
|
+
export type ModelInputData = {
|
|
173
|
+
input: AgentInputItem[];
|
|
174
|
+
instructions?: string;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Shape of the payload given to `callModelInputFilter`. Mirrored in the Python SDK so filters can
|
|
178
|
+
* share the same implementation across languages.
|
|
179
|
+
*/
|
|
180
|
+
export type CallModelInputFilterArgs<TContext = unknown> = {
|
|
181
|
+
modelData: ModelInputData;
|
|
182
|
+
agent: Agent<TContext, AgentOutputType>;
|
|
183
|
+
context: TContext | undefined;
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Hook invoked immediately before a model call is issued, allowing callers to adjust the
|
|
187
|
+
* instructions or input array. Returning a new array enables redaction, truncation, or
|
|
188
|
+
* augmentation of the payload that will be sent to the provider.
|
|
189
|
+
*/
|
|
190
|
+
export type CallModelInputFilter<TContext = unknown> = (args: CallModelInputFilterArgs<TContext>) => ModelInputData | Promise<ModelInputData>;
|
|
191
|
+
/**
|
|
192
|
+
* Constructs the model input array for the current turn by combining the original turn input with
|
|
193
|
+
* any new run items (excluding tool approval placeholders). This helps ensure that repeated calls
|
|
194
|
+
* to the Responses API only send newly generated content.
|
|
195
|
+
*
|
|
196
|
+
* See: https://platform.openai.com/docs/guides/conversation-state?api-mode=responses.
|
|
197
|
+
*/
|
|
198
|
+
export declare function getTurnInput(originalInput: string | AgentInputItem[], generatedItems: RunItem[]): AgentInputItem[];
|
|
199
|
+
/**
|
|
200
|
+
* Resolves the effective model for the next turn by giving precedence to the agent-specific
|
|
201
|
+
* configuration when present, otherwise falling back to the runner-level default.
|
|
202
|
+
*/
|
|
127
203
|
export declare function selectModel(agentModel: string | Model, runConfigModel: string | Model | undefined): string | Model;
|
|
128
|
-
|
|
129
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Normalizes tracing configuration into the format expected by model providers.
|
|
206
|
+
* Returns `false` to disable tracing, `true` to include full payload data, or
|
|
207
|
+
* `'enabled_without_data'` to omit sensitive content while still emitting spans.
|
|
208
|
+
*/
|
|
209
|
+
export declare function getTracing(tracingDisabled: boolean, traceIncludeSensitiveData: boolean): ModelTracing;
|
|
130
210
|
export {};
|