@aigne/core 0.4.205 → 0.4.206

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.
Files changed (48) hide show
  1. package/lib/cjs/agent.js +27 -1
  2. package/lib/cjs/definitions/data-type-schema.js +2 -2
  3. package/lib/cjs/function-agent.js +34 -29
  4. package/lib/cjs/function-runner.js +6 -4
  5. package/lib/cjs/index.js +1 -1
  6. package/lib/cjs/llm-agent.js +22 -54
  7. package/lib/cjs/llm-decision-agent.js +8 -12
  8. package/lib/cjs/llm-model.js +2 -2
  9. package/lib/cjs/local-function-agent.js +7 -21
  10. package/lib/cjs/pipeline-agent.js +9 -19
  11. package/lib/cjs/runnable.js +1 -0
  12. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  13. package/lib/cjs/utils/index.js +5 -2
  14. package/lib/cjs/utils/stream-utils.js +35 -13
  15. package/lib/esm/agent.js +29 -3
  16. package/lib/esm/definitions/data-type-schema.js +2 -2
  17. package/lib/esm/function-agent.js +33 -28
  18. package/lib/esm/function-runner.js +6 -4
  19. package/lib/esm/index.js +1 -1
  20. package/lib/esm/llm-agent.js +22 -53
  21. package/lib/esm/llm-decision-agent.js +8 -11
  22. package/lib/esm/llm-model.js +2 -2
  23. package/lib/esm/local-function-agent.js +7 -20
  24. package/lib/esm/pipeline-agent.js +9 -18
  25. package/lib/esm/runnable.js +1 -0
  26. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  27. package/lib/esm/utils/index.js +5 -2
  28. package/lib/esm/utils/stream-utils.js +33 -13
  29. package/lib/types/agent.d.ts +8 -9
  30. package/lib/types/context.d.ts +2 -0
  31. package/lib/types/definitions/data-type-schema.d.ts +7 -5
  32. package/lib/types/{data-type.d.ts → definitions/data-type.d.ts} +2 -2
  33. package/lib/types/function-agent.d.ts +33 -20
  34. package/lib/types/function-runner.d.ts +20 -7
  35. package/lib/types/index.d.ts +1 -1
  36. package/lib/types/llm-agent.d.ts +27 -30
  37. package/lib/types/llm-decision-agent.d.ts +15 -22
  38. package/lib/types/llm-model.d.ts +2 -2
  39. package/lib/types/local-function-agent.d.ts +31 -34
  40. package/lib/types/pipeline-agent.d.ts +21 -55
  41. package/lib/types/runnable.d.ts +1 -1
  42. package/lib/types/tsconfig.tsbuildinfo +1 -1
  43. package/lib/types/utils/index.d.ts +5 -2
  44. package/lib/types/utils/stream-utils.d.ts +5 -3
  45. package/lib/types/utils/union.d.ts +1 -2
  46. package/package.json +3 -2
  47. /package/lib/cjs/{data-type.js → definitions/data-type.js} +0 -0
  48. /package/lib/esm/{data-type.js → definitions/data-type.js} +0 -0
@@ -1,4 +1,7 @@
1
- export * from './ordered-map';
2
1
  export * from './is-non-nullable';
3
- export * from './stream-utils';
4
2
  export * from './mustache-utils';
3
+ export * from './nullable';
4
+ export * from './omit';
5
+ export * from './ordered-map';
6
+ export * from './stream-utils';
7
+ export * from './union';
@@ -28,24 +28,41 @@ export async function runnableResponseStreamToObject(stream) {
28
28
  * @returns The runnable output stream or object
29
29
  */
30
30
  export async function extractOutputsFromRunnableOutput(output, resolve) {
31
- if (!(output instanceof ReadableStream)) {
32
- await resolve(output);
33
- return output;
31
+ if (output instanceof ReadableStream || isAsyncGenerator(output)) {
32
+ return new ReadableStream({
33
+ async start(controller) {
34
+ try {
35
+ const result = {};
36
+ let $text = '';
37
+ for await (const value of output) {
38
+ if (isRunnableResponseDelta(value)) {
39
+ controller.enqueue(value);
40
+ $text += value.$text || '';
41
+ Object.assign(result, value.delta);
42
+ }
43
+ }
44
+ Object.assign(result, { $text: result.$text || $text || undefined });
45
+ await resolve(result);
46
+ }
47
+ catch (error) {
48
+ controller.error(error);
49
+ }
50
+ finally {
51
+ controller.close();
52
+ }
53
+ },
54
+ });
34
55
  }
56
+ await resolve(output);
57
+ return output;
58
+ }
59
+ export function asyncGeneratorToReadableStream(generator) {
35
60
  return new ReadableStream({
36
61
  async start(controller) {
37
62
  try {
38
- const result = {};
39
- let $text = '';
40
- for await (const value of output) {
41
- if (isRunnableResponseDelta(value)) {
42
- $text += value.$text || '';
43
- Object.assign(result, value.delta);
44
- }
63
+ for await (const value of generator) {
64
+ controller.enqueue(value);
45
65
  }
46
- Object.assign(result, { $text: result.$text || $text || undefined });
47
- controller.enqueue({ $text: result.$text, delta: result });
48
- await resolve(result);
49
66
  }
50
67
  catch (error) {
51
68
  controller.error(error);
@@ -56,3 +73,6 @@ export async function extractOutputsFromRunnableOutput(output, resolve) {
56
73
  },
57
74
  });
58
75
  }
76
+ export function isAsyncGenerator(value) {
77
+ return Symbol.asyncIterator in value;
78
+ }
@@ -1,9 +1,9 @@
1
1
  import { Context, ContextState } from './context';
2
2
  import { MemoryItemWithScore, MemoryMessage } from './memorable';
3
- import { RunOptions, Runnable, RunnableResponse, RunnableResponseStream } from './runnable';
3
+ import { RunOptions, Runnable, RunnableResponse, RunnableResponseChunk, RunnableResponseStream } from './runnable';
4
4
  export interface AgentProcessOptions<Memories extends {
5
5
  [name: string]: MemoryItemWithScore[];
6
- }> extends RunOptions {
6
+ }> {
7
7
  memories: Memories;
8
8
  }
9
9
  export declare abstract class Agent<I extends {
@@ -32,11 +32,10 @@ export declare abstract class Agent<I extends {
32
32
  run(input: I, options?: RunOptions & {
33
33
  stream?: false;
34
34
  }): Promise<O>;
35
- abstract process(input: I, options: AgentProcessOptions<Memories> & {
36
- stream: true;
37
- }): Promise<RunnableResponseStream<O>>;
38
- abstract process(input: I, options: AgentProcessOptions<Memories> & {
39
- stream?: false;
40
- }): Promise<O>;
41
- abstract process(input: I, options: AgentProcessOptions<Memories>): Promise<RunnableResponse<O>>;
35
+ /**
36
+ * Hook that is called before the agent result is returned.
37
+ * @param _result The agent result.
38
+ */
39
+ protected onResult(_result: O): Promise<void>;
40
+ abstract process(input: I, options: AgentProcessOptions<Memories>): Promise<RunnableResponse<O> | AsyncGenerator<RunnableResponseChunk<O>, void>> | AsyncGenerator<RunnableResponseChunk<O>, void>;
42
41
  }
@@ -6,4 +6,6 @@ export interface ContextState {
6
6
  export interface Context<State extends ContextState = ContextState> {
7
7
  state: State;
8
8
  resolve<T extends Runnable>(id: string | RunnableDefinition): Promise<T>;
9
+ register<R extends Array<RunnableDefinition | Runnable> = []>(...definition: R): void;
10
+ resolveDependency<T>(token: string | symbol): T;
9
11
  }
@@ -1,6 +1,6 @@
1
- import { DataType } from '../data-type';
2
1
  import { OrderedRecord } from '../utils';
3
2
  import { MakeNullablePropertyOptional } from '../utils/nullable';
3
+ import { DataType } from './data-type';
4
4
  export declare function schemaToDataType(dataType: {
5
5
  [name: string]: DataTypeSchema;
6
6
  }): OrderedRecord<DataType>;
@@ -20,17 +20,19 @@ export interface DataTypeSchemaBoolean extends DataTypeSchemaBase {
20
20
  }
21
21
  export interface DataTypeSchemaObject extends DataTypeSchemaBase {
22
22
  type: 'object';
23
- properties: {
23
+ properties?: {
24
24
  [key: string]: DataTypeSchema;
25
25
  };
26
26
  }
27
27
  export interface DataTypeSchemaArray extends DataTypeSchemaBase {
28
28
  type: 'array';
29
- items: DataTypeSchema;
29
+ items?: DataTypeSchema;
30
30
  }
31
31
  type SchemaTypeInner<T extends DataTypeSchema> = T extends DataTypeSchemaString ? string : T extends DataTypeSchemaNumber ? number : T extends DataTypeSchemaBoolean ? boolean : T extends DataTypeSchemaObject ? MakeNullablePropertyOptional<{
32
- [K in keyof T['properties']]: SchemaType<T['properties'][K]>;
33
- }> : T extends DataTypeSchemaArray ? SchemaType<T['items']>[] : never;
32
+ [K in keyof T['properties']]: SchemaType<NonNullable<T['properties']>[K]>;
33
+ }> : T extends DataTypeSchemaArray ? T['items'] extends null | undefined ? SchemaType<{
34
+ type: 'object';
35
+ }>[] : NonNullable<T['items']>[] : never;
34
36
  export type SchemaType<T extends DataTypeSchema> = T['required'] extends true ? SchemaTypeInner<T> : SchemaTypeInner<T> | undefined | null;
35
37
  export type SchemaMapType<T extends Record<string, DataTypeSchema>> = SchemaType<{
36
38
  type: 'object';
@@ -1,5 +1,5 @@
1
- import { OmitPropsFromUnion } from './utils/omit';
2
- import { OrderedRecord } from './utils/ordered-map';
1
+ import { OmitPropsFromUnion } from '../utils/omit';
2
+ import { OrderedRecord } from '../utils/ordered-map';
3
3
  export type DataType = DataTypeString | DataTypeNumber | DataTypeBoolean | DataTypeObject | DataTypeArray;
4
4
  export interface DataTypeBase {
5
5
  id: string;
@@ -1,34 +1,47 @@
1
+ import { Agent, AgentProcessOptions } from './agent';
2
+ import type { Context, ContextState } from './context';
1
3
  import { DataTypeSchema, SchemaMapType } from './definitions/data-type-schema';
4
+ import { CreateRunnableMemory } from './definitions/memory';
2
5
  import { FunctionRunner } from './function-runner';
3
- import { RunOptions, Runnable, RunnableDefinition, RunnableResponseStream } from './runnable';
4
- export declare class FunctionAgent<I extends {} = {}, O extends {} = {}> extends Runnable<I, O> {
6
+ import { MemorableSearchOutput, MemoryItemWithScore } from './memorable';
7
+ import { RunnableDefinition } from './runnable';
8
+ export declare class FunctionAgent<I extends {
9
+ [name: string]: any;
10
+ } = {}, O extends {
11
+ [name: string]: any;
12
+ } = {}, Memories extends {
13
+ [name: string]: MemoryItemWithScore[];
14
+ } = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
5
15
  definition: FunctionAgentDefinition;
6
- runner?: FunctionRunner | undefined;
7
- static create<I extends {
8
- [name: string]: DataTypeSchema;
9
- }, O extends {
10
- [name: string]: DataTypeSchema;
11
- }>(options: Parameters<typeof createFunctionAgentDefinition<I, O>>[0]): FunctionAgent<SchemaMapType<I>, SchemaMapType<O>>;
12
- constructor(definition: FunctionAgentDefinition, runner?: FunctionRunner | undefined);
13
- run(input: I, options: RunOptions & {
14
- stream: true;
15
- }): Promise<RunnableResponseStream<O>>;
16
- run(input: I, options?: RunOptions & {
17
- stream?: false;
18
- }): Promise<O>;
16
+ runner?: FunctionRunner<I, O, Memories, State> | undefined;
17
+ static create: typeof create;
18
+ constructor(definition: FunctionAgentDefinition, context?: Context<State>, runner?: FunctionRunner<I, O, Memories, State> | undefined);
19
+ process(input: I, options: AgentProcessOptions<Memories>): Promise<import("./runnable").RunnableResponseStream<O>>;
19
20
  }
20
- export declare function createFunctionAgentDefinition<I extends {
21
+ export interface CreateFunctionAgentOptions<I extends {
21
22
  [name: string]: DataTypeSchema;
22
23
  }, O extends {
23
24
  [name: string]: DataTypeSchema;
24
- }>(options: {
25
- id?: string;
25
+ }, Memories extends {
26
+ [name: string]: CreateRunnableMemory<I>;
27
+ }, State extends ContextState> {
28
+ context?: Context<State>;
26
29
  name?: string;
27
30
  inputs: I;
28
31
  outputs: O;
29
- language: string;
32
+ memories?: Memories;
33
+ language?: string;
30
34
  code: string;
31
- }): FunctionAgentDefinition;
35
+ }
36
+ export declare function create<I extends {
37
+ [name: string]: DataTypeSchema;
38
+ }, O extends {
39
+ [name: string]: DataTypeSchema;
40
+ }, Memories extends {
41
+ [name: string]: CreateRunnableMemory<I>;
42
+ }, State extends ContextState>({ context, ...options }: CreateFunctionAgentOptions<I, O, Memories, State>): FunctionAgent<SchemaMapType<I>, SchemaMapType<O>, {
43
+ [name in keyof Memories]: MemorableSearchOutput<Memories[name]['memory']>;
44
+ }, State>;
32
45
  export interface FunctionAgentDefinition extends RunnableDefinition {
33
46
  type: 'function_agent';
34
47
  language?: string;
@@ -1,12 +1,25 @@
1
- import { Context } from './context';
2
- import { Runnable } from './runnable';
3
- export interface FunctionRunnerInputs {
1
+ import { Agent } from './agent';
2
+ import { Context, ContextState } from './context';
3
+ import { MemoryItemWithScore } from './memorable';
4
+ export interface FunctionRunnerInput<I extends {
5
+ [name: string]: any;
6
+ } = {}, Memories extends {
7
+ [name: string]: MemoryItemWithScore[];
8
+ } = {}, State extends ContextState = ContextState> {
4
9
  name: string;
5
- language: string;
10
+ language?: string;
6
11
  code: string;
7
- arguments?: object;
12
+ input: I;
13
+ memories: Memories;
14
+ context: Pick<Context<State>, 'state'>;
8
15
  }
9
- export type FunctionRunnerOutputs = object;
10
- export declare abstract class FunctionRunner extends Runnable<FunctionRunnerInputs, FunctionRunnerOutputs> {
16
+ export type FunctionRunnerOutput<O> = O;
17
+ export declare abstract class FunctionRunner<I extends {
18
+ [name: string]: any;
19
+ } = {}, O extends {
20
+ [name: string]: any;
21
+ } = {}, Memories extends {
22
+ [name: string]: MemoryItemWithScore[];
23
+ } = {}, State extends ContextState = ContextState> extends Agent<FunctionRunnerInput<I, Memories, State>, FunctionRunnerOutput<O>> {
11
24
  constructor(context?: Context);
12
25
  }
@@ -1,6 +1,6 @@
1
1
  export * from './utils';
2
2
  export * from './constants';
3
- export * from './data-type';
3
+ export * from './definitions/data-type';
4
4
  export * from './definitions/data-type-schema';
5
5
  export * from './context';
6
6
  export * from './runnable';
@@ -1,10 +1,10 @@
1
1
  import { Agent, AgentProcessOptions } from './agent';
2
- import type { Context } from './context';
2
+ import type { Context, ContextState } from './context';
3
3
  import { DataTypeSchema, SchemaMapType } from './definitions/data-type-schema';
4
4
  import { CreateRunnableMemory } from './definitions/memory';
5
5
  import { LLMModel, LLMModelInputMessage, LLMModelInputs } from './llm-model';
6
6
  import { MemorableSearchOutput, MemoryItemWithScore } from './memorable';
7
- import { RunnableDefinition, RunnableResponseStream } from './runnable';
7
+ import { RunnableDefinition } from './runnable';
8
8
  import { OrderedRecord } from './utils/ordered-map';
9
9
  export declare class LLMAgent<I extends {
10
10
  [name: string]: any;
@@ -12,28 +12,29 @@ export declare class LLMAgent<I extends {
12
12
  [name: string]: any;
13
13
  } = {}, Memories extends {
14
14
  [name: string]: MemoryItemWithScore[];
15
- } = {}> extends Agent<I, O, Memories> {
15
+ } = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
16
16
  definition: LLMAgentDefinition;
17
17
  model?: LLMModel | undefined;
18
- static create<I extends {
19
- [name: string]: DataTypeSchema;
20
- }, O extends {
21
- [name: string]: DataTypeSchema;
22
- }, Memories extends {
23
- [name: string]: CreateRunnableMemory<I>;
24
- }>(options: Parameters<typeof createLLMAgentDefinition<I, O, Memories>>[0]): LLMAgent<SchemaMapType<I>, SchemaMapType<O>, {
25
- [name in keyof Memories]: MemorableSearchOutput<Memories[name]['memory']>;
26
- }>;
27
- constructor(definition: LLMAgentDefinition, context?: Context, model?: LLMModel | undefined);
28
- process(input: I, options: AgentProcessOptions<Memories> & {
29
- stream: true;
30
- }): Promise<RunnableResponseStream<O>>;
31
- process(input: I, options: AgentProcessOptions<Memories> & {
32
- stream?: false;
33
- }): Promise<O>;
18
+ static create: typeof create;
19
+ constructor(definition: LLMAgentDefinition, context?: Context<State>, model?: LLMModel | undefined);
20
+ process(input: I, options: AgentProcessOptions<Memories>): AsyncGenerator<{
21
+ $text: string | undefined;
22
+ delta?: undefined;
23
+ } | {
24
+ delta: any;
25
+ $text?: undefined;
26
+ }, void, unknown>;
34
27
  private runWithStructuredOutput;
35
28
  private runWithTextOutput;
36
29
  }
30
+ export interface LLMAgentDefinition extends RunnableDefinition {
31
+ type: 'llm_agent';
32
+ primaryMemoryId?: string;
33
+ messages?: OrderedRecord<LLMModelInputMessage & {
34
+ id: string;
35
+ }>;
36
+ modelOptions?: LLMModelInputs['modelOptions'];
37
+ }
37
38
  /**
38
39
  * Options to create LLMAgent.
39
40
  */
@@ -43,7 +44,8 @@ export interface CreateLLMAgentOptions<I extends {
43
44
  [name: string]: DataTypeSchema;
44
45
  }, Memories extends {
45
46
  [name: string]: CreateRunnableMemory<I>;
46
- }> {
47
+ }, State extends ContextState> {
48
+ context?: Context<State>;
47
49
  /**
48
50
  * Agent name, used to identify the agent.
49
51
  */
@@ -74,7 +76,7 @@ export interface CreateLLMAgentOptions<I extends {
74
76
  * @param options Options to create LLMAgent.
75
77
  * @returns LLMAgent definition.
76
78
  */
77
- export declare function createLLMAgentDefinition<I extends {
79
+ declare function create<I extends {
78
80
  [name: string]: DataTypeSchema;
79
81
  }, O extends {
80
82
  [name: string]: DataTypeSchema;
@@ -88,12 +90,7 @@ export declare function createLLMAgentDefinition<I extends {
88
90
  */
89
91
  primary?: boolean;
90
92
  };
91
- }>(options: CreateLLMAgentOptions<I, O, Memories>): LLMAgentDefinition;
92
- export interface LLMAgentDefinition extends RunnableDefinition {
93
- type: 'llm_agent';
94
- primaryMemoryId?: string;
95
- messages?: OrderedRecord<LLMModelInputMessage & {
96
- id: string;
97
- }>;
98
- modelOptions?: LLMModelInputs['modelOptions'];
99
- }
93
+ }, State extends ContextState>({ context, ...options }: CreateLLMAgentOptions<I, O, Memories, State>): LLMAgent<SchemaMapType<I>, SchemaMapType<O>, {
94
+ [name in keyof Memories]: MemorableSearchOutput<Memories[name]['memory']>;
95
+ }, State>;
96
+ export {};
@@ -4,11 +4,11 @@ import { DataTypeSchema } from './definitions/data-type-schema';
4
4
  import { CreateRunnableMemory } from './definitions/memory';
5
5
  import { CreateLLMAgentOptions, LLMAgentDefinition } from './llm-agent';
6
6
  import { LLMModel } from './llm-model';
7
- import { MemoryItemWithScore } from './memorable';
8
- import { Runnable, RunnableDefinition, RunnableResponseStream } from './runnable';
7
+ import { MemorableSearchOutput, MemoryItemWithScore } from './memorable';
8
+ import { Runnable, RunnableDefinition } from './runnable';
9
9
  import { OrderedRecord } from './utils';
10
10
  import { ExtractRunnableInputType, ExtractRunnableOutputType } from './utils/runnable-type';
11
- import { ObjectUnionToIntersection } from './utils/union';
11
+ import { UnionToIntersection } from './utils/union';
12
12
  export declare class LLMDecisionAgent<I extends {
13
13
  [name: string]: any;
14
14
  } = {}, O extends {
@@ -18,20 +18,9 @@ export declare class LLMDecisionAgent<I extends {
18
18
  } = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
19
19
  definition: LLMDecisionAgentDefinition;
20
20
  model?: LLMModel | undefined;
21
- static create<Case extends DecisionAgentCaseParameter, I extends ObjectUnionToIntersection<ExtractRunnableInputType<Case['runnable']>, {
22
- [name: string]: DataTypeSchema;
23
- }>, O extends ObjectUnionToIntersection<ExtractRunnableOutputType<Case['runnable']>, {
24
- [name: string]: DataTypeSchema;
25
- }>, Memories extends {
26
- [name: string]: CreateRunnableMemory<I>;
27
- }>(options: Parameters<typeof createLLMDecisionAgentDefinition<Case, I, O, Memories>>[0]): LLMDecisionAgent<ObjectUnionToIntersection<ExtractRunnableInputType<Case['runnable']>>, ExtractRunnableOutputType<Case['runnable']>>;
21
+ static create: typeof create;
28
22
  constructor(definition: LLMDecisionAgentDefinition, context?: Context<State>, model?: LLMModel | undefined);
29
- process(input: I, options: AgentProcessOptions<Memories> & {
30
- stream: true;
31
- }): Promise<RunnableResponseStream<O>>;
32
- process(input: I, options: AgentProcessOptions<Memories> & {
33
- stream?: false;
34
- }): Promise<O>;
23
+ process(input: I, options: AgentProcessOptions<Memories>): Promise<import("./runnable").RunnableResponse<O>>;
35
24
  }
36
25
  export interface DecisionAgentCaseParameter<R extends Runnable = Runnable> {
37
26
  description?: string;
@@ -40,20 +29,21 @@ export interface DecisionAgentCaseParameter<R extends Runnable = Runnable> {
40
29
  /**
41
30
  * Options to create LLMDecisionAgent.
42
31
  */
43
- export interface CreateLLMDecisionAgentOptions<Case extends DecisionAgentCaseParameter, I extends ObjectUnionToIntersection<ExtractRunnableInputType<Case['runnable']>, {
32
+ export interface CreateLLMDecisionAgentOptions<Case extends DecisionAgentCaseParameter, I extends UnionToIntersection<ExtractRunnableInputType<Case['runnable']>, {
44
33
  [name: string]: DataTypeSchema;
45
- }>, O extends ObjectUnionToIntersection<ExtractRunnableOutputType<Case['runnable']>, {
34
+ }>, O extends UnionToIntersection<ExtractRunnableOutputType<Case['runnable']>, {
46
35
  [name: string]: DataTypeSchema;
47
36
  }>, Memories extends {
48
37
  [name: string]: CreateRunnableMemory<I>;
49
- }> extends Pick<CreateLLMAgentOptions<I, O, Memories>, 'name' | 'memories' | 'messages' | 'modelOptions'> {
38
+ }, State extends ContextState> extends Pick<CreateLLMAgentOptions<I, O, Memories, State>, 'name' | 'memories' | 'messages' | 'modelOptions'> {
39
+ context: Context<State>;
50
40
  cases: {
51
41
  [name: string]: Case;
52
42
  };
53
43
  }
54
- export declare function createLLMDecisionAgentDefinition<Case extends DecisionAgentCaseParameter, I extends ObjectUnionToIntersection<ExtractRunnableInputType<Case['runnable']>, {
44
+ declare function create<Case extends DecisionAgentCaseParameter, I extends UnionToIntersection<ExtractRunnableInputType<Case['runnable']>, {
55
45
  [name: string]: DataTypeSchema;
56
- }>, O extends ObjectUnionToIntersection<ExtractRunnableOutputType<Case['runnable']>, {
46
+ }>, O extends UnionToIntersection<ExtractRunnableOutputType<Case['runnable']>, {
57
47
  [name: string]: DataTypeSchema;
58
48
  }>, Memories extends {
59
49
  [name: string]: CreateRunnableMemory<I> & {
@@ -65,7 +55,9 @@ export declare function createLLMDecisionAgentDefinition<Case extends DecisionAg
65
55
  */
66
56
  primary?: boolean;
67
57
  };
68
- }>(options: CreateLLMDecisionAgentOptions<Case, I, O, Memories>): LLMDecisionAgentDefinition;
58
+ }, State extends ContextState>({ context, ...options }: CreateLLMDecisionAgentOptions<Case, I, O, Memories, State>): LLMDecisionAgent<UnionToIntersection<ExtractRunnableInputType<Case['runnable']>, {}>, ExtractRunnableOutputType<Case['runnable']>, {
59
+ [name in keyof Memories]: MemorableSearchOutput<Memories[name]['memory']>;
60
+ }, State>;
69
61
  export interface LLMDecisionAgentDefinition extends RunnableDefinition, Pick<LLMAgentDefinition, 'modelOptions' | 'messages' | 'primaryMemoryId'> {
70
62
  type: 'llm_decision_agent';
71
63
  cases?: OrderedRecord<LLMDecisionCase>;
@@ -78,3 +70,4 @@ export interface LLMDecisionCase {
78
70
  id?: string;
79
71
  };
80
72
  }
73
+ export {};
@@ -1,5 +1,5 @@
1
+ import { Agent } from './agent';
1
2
  import { Context } from './context';
2
- import { Runnable } from './runnable';
3
3
  export type Role = 'system' | 'user' | 'assistant' | 'tool';
4
4
  export interface LLMModelInputs {
5
5
  messages: LLMModelInputMessage[];
@@ -71,7 +71,7 @@ export interface LLMModelOutputs {
71
71
  };
72
72
  }[];
73
73
  }
74
- export declare abstract class LLMModel extends Runnable<LLMModelInputs, LLMModelOutputs> {
74
+ export declare abstract class LLMModel extends Agent<LLMModelInputs, LLMModelOutputs> {
75
75
  constructor(context?: Context);
76
76
  }
77
77
  export interface LLMModelConfiguration {
@@ -3,7 +3,7 @@ import type { Context, ContextState } from './context';
3
3
  import { DataTypeSchema, SchemaMapType } from './definitions/data-type-schema';
4
4
  import { CreateRunnableMemory } from './definitions/memory';
5
5
  import { MemorableSearchOutput, MemoryItemWithScore } from './memorable';
6
- import { RunnableDefinition, RunnableResponse, RunnableResponseStream } from './runnable';
6
+ import { RunnableDefinition, RunnableResponse, RunnableResponseChunk } from './runnable';
7
7
  export declare class LocalFunctionAgent<I extends {
8
8
  [name: string]: any;
9
9
  } = {}, O extends {
@@ -12,22 +12,31 @@ export declare class LocalFunctionAgent<I extends {
12
12
  [name: string]: MemoryItemWithScore[];
13
13
  } = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
14
14
  definition: LocalFunctionAgentDefinition<I, O, Memories, State>;
15
- static create<I extends {
16
- [name: string]: DataTypeSchema;
17
- }, O extends {
18
- [name: string]: DataTypeSchema;
19
- }, Memories extends {
20
- [name: string]: CreateRunnableMemory<I>;
21
- }, State extends ContextState = ContextState>(options: Parameters<typeof createLocalFunctionAgentDefinition<I, O, Memories, State>>[0]): LocalFunctionAgent<SchemaMapType<I>, SchemaMapType<O>, {
22
- [name in keyof Memories]: MemorableSearchOutput<Memories[name]['memory']>;
23
- }, State>;
15
+ static create: typeof create;
24
16
  constructor(definition: LocalFunctionAgentDefinition<I, O, Memories, State>, context?: Context<State>);
25
- process(input: I, options: AgentProcessOptions<Memories> & {
26
- stream: true;
27
- }): Promise<RunnableResponseStream<O>>;
28
- process(input: I, options: AgentProcessOptions<Memories> & {
29
- stream?: false;
30
- }): Promise<O>;
17
+ process(input: I, options: AgentProcessOptions<Memories>): Promise<AsyncGenerator<RunnableResponseChunk<O>, void, any> | RunnableResponse<O>>;
18
+ }
19
+ export interface LocalFunctionAgentDefinition<I extends {
20
+ [name: string]: any;
21
+ }, O extends {
22
+ [name: string]: any;
23
+ }, Memories extends {
24
+ [name: string]: MemoryItemWithScore[];
25
+ }, State extends ContextState> extends RunnableDefinition {
26
+ type: 'local_function_agent';
27
+ function?: LocalFunctionFuncType<I, O, Memories, State>;
28
+ }
29
+ export interface LocalFunctionFuncType<I extends {
30
+ [name: string]: any;
31
+ }, O extends {
32
+ [name: string]: any;
33
+ }, Memories extends {
34
+ [name: string]: MemoryItemWithScore[];
35
+ }, State extends ContextState> {
36
+ (input: I, options: {
37
+ memories: Memories;
38
+ context: Context<State>;
39
+ }): Promise<RunnableResponse<O> | AsyncGenerator<RunnableResponseChunk<O>, void>> | AsyncGenerator<RunnableResponseChunk<O>, void>;
31
40
  }
32
41
  export interface CreateLocalFunctionAgentOptions<I extends {
33
42
  [name: string]: DataTypeSchema;
@@ -35,7 +44,8 @@ export interface CreateLocalFunctionAgentOptions<I extends {
35
44
  [name: string]: DataTypeSchema;
36
45
  }, Memories extends {
37
46
  [name: string]: CreateRunnableMemory<I>;
38
- }, State extends ContextState = ContextState> {
47
+ }, State extends ContextState> {
48
+ context?: Context<State>;
39
49
  name?: string;
40
50
  inputs: I;
41
51
  outputs: O;
@@ -44,26 +54,13 @@ export interface CreateLocalFunctionAgentOptions<I extends {
44
54
  [key in keyof Memories]: MemorableSearchOutput<Memories[key]['memory']>;
45
55
  }, State>;
46
56
  }
47
- export declare function createLocalFunctionAgentDefinition<I extends {
57
+ declare function create<I extends {
48
58
  [name: string]: DataTypeSchema;
49
59
  }, O extends {
50
60
  [name: string]: DataTypeSchema;
51
61
  }, Memories extends {
52
62
  [name: string]: CreateRunnableMemory<I>;
53
- }, State extends ContextState = ContextState>(options: CreateLocalFunctionAgentOptions<I, O, Memories, State>): LocalFunctionAgentDefinition<SchemaMapType<I>, SchemaMapType<O>, {
54
- [key in keyof Memories]: MemorableSearchOutput<Memories[key]['memory']>;
63
+ }, State extends ContextState>({ context, ...options }: CreateLocalFunctionAgentOptions<I, O, Memories, State>): LocalFunctionAgent<SchemaMapType<I>, SchemaMapType<O>, {
64
+ [name in keyof Memories]: MemorableSearchOutput<Memories[name]['memory']>;
55
65
  }, State>;
56
- export interface LocalFunctionFuncType<I extends {} = {}, O extends {} = {}, Memories extends {
57
- [name: string]: MemoryItemWithScore[];
58
- } = {}, State extends ContextState = ContextState> {
59
- (input: I, options: {
60
- memories: Memories;
61
- context: Context<State>;
62
- }): Promise<RunnableResponse<O>>;
63
- }
64
- export interface LocalFunctionAgentDefinition<I extends {} = {}, O extends {} = {}, Memories extends {
65
- [name: string]: MemoryItemWithScore[];
66
- } = {}, State extends ContextState = ContextState> extends RunnableDefinition {
67
- type: 'local_function_agent';
68
- function?: LocalFunctionFuncType<I, O, Memories, State>;
69
- }
66
+ export {};