-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathtypes.ts
118 lines (107 loc) · 3.46 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import type { Runnable } from "@langchain/core/runnables";
import { BaseOutputParser } from "@langchain/core/output_parsers";
import type { AgentAction, AgentFinish } from "@langchain/core/agents";
import type { BaseMessage } from "@langchain/core/messages";
import type { ChainValues } from "@langchain/core/utils/types";
import { SerializedLLMChain } from "../chains/serde.js";
import { LLMChain } from "../chains/llm_chain.js";
/**
* Interface defining the input for creating an agent. It includes the
* LLMChain instance, an optional output parser, and an optional list of
* allowed tools.
*/
export interface AgentInput {
llmChain: LLMChain;
outputParser: AgentActionOutputParser | undefined;
allowedTools?: string[];
}
/**
* Interface defining the input for creating a single action agent
* that uses runnables.
*/
export interface RunnableSingleActionAgentInput {
runnable: Runnable<
ChainValues & {
agent_scratchpad?: string | BaseMessage[];
stop?: string[];
},
AgentAction | AgentFinish
>;
streamRunnable?: boolean;
defaultRunName?: string;
}
/**
* Interface defining the input for creating a multi-action agent that uses
* runnables. It includes the Runnable instance, and an optional list of
* stop strings.
*/
export interface RunnableMultiActionAgentInput {
runnable: Runnable<
ChainValues & {
agent_scratchpad?: string | BaseMessage[];
stop?: string[];
},
AgentAction[] | AgentAction | AgentFinish
>;
streamRunnable?: boolean;
defaultRunName?: string;
stop?: string[];
}
/** @deprecated Renamed to RunnableMultiActionAgentInput. */
export interface RunnableAgentInput extends RunnableMultiActionAgentInput {}
/**
* Abstract class representing an output parser specifically for agent
* actions and finishes in LangChain. It extends the `BaseOutputParser`
* class.
*/
export abstract class AgentActionOutputParser extends BaseOutputParser<
AgentAction | AgentFinish
> {}
/**
* Abstract class representing an output parser specifically for agents
* that return multiple actions.
*/
export abstract class AgentMultiActionOutputParser extends BaseOutputParser<
AgentAction[] | AgentFinish
> {}
/**
* Type representing the stopping method for an agent. It can be either
* 'force' or 'generate'.
*/
export type StoppingMethod = "force" | "generate";
/**
* Generic type representing a serialized agent in LangChain. It includes
* the type of the agent, the serialized form of the LLMChain, and
* additional properties specific to the agent type.
*/
export type SerializedAgentT<
TType extends string = string,
FromLLMInput extends Record<string, unknown> = Record<string, unknown>,
ConstructorInput extends AgentInput = AgentInput
> = {
_type: TType;
llm_chain?: SerializedLLMChain;
} & (
| ({ load_from_llm_and_tools: true } & FromLLMInput)
| ({ load_from_llm_and_tools?: false } & ConstructorInput)
);
export type SerializedFromLLMAndTools = {
suffix?: string;
prefix?: string;
input_variables?: string[];
};
/**
* Type representing a serialized ZeroShotAgent in LangChain. It extends
* the `SerializedAgentT` type and includes additional properties specific
* to the ZeroShotAgent.
*/
export type SerializedZeroShotAgent = SerializedAgentT<
"zero-shot-react-description",
SerializedFromLLMAndTools,
AgentInput
>;
/**
* Type representing a serialized agent in LangChain. It is currently
* synonymous with `SerializedZeroShotAgent`.
*/
export type SerializedAgent = SerializedZeroShotAgent;