@librechat/agents 1.4.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.
Files changed (143) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/common/enum.cjs +108 -0
  3. package/dist/cjs/common/enum.cjs.map +1 -0
  4. package/dist/cjs/events.cjs +104 -0
  5. package/dist/cjs/events.cjs.map +1 -0
  6. package/dist/cjs/graphs/Graph.cjs +313 -0
  7. package/dist/cjs/graphs/Graph.cjs.map +1 -0
  8. package/dist/cjs/llm/providers.cjs +30 -0
  9. package/dist/cjs/llm/providers.cjs.map +1 -0
  10. package/dist/cjs/main.cjs +59 -0
  11. package/dist/cjs/main.cjs.map +1 -0
  12. package/dist/cjs/messages.cjs +195 -0
  13. package/dist/cjs/messages.cjs.map +1 -0
  14. package/dist/cjs/run.cjs +106 -0
  15. package/dist/cjs/run.cjs.map +1 -0
  16. package/dist/cjs/stream.cjs +133 -0
  17. package/dist/cjs/stream.cjs.map +1 -0
  18. package/dist/cjs/tools/ToolNode.cjs +80 -0
  19. package/dist/cjs/tools/ToolNode.cjs.map +1 -0
  20. package/dist/cjs/utils/graph.cjs +16 -0
  21. package/dist/cjs/utils/graph.cjs.map +1 -0
  22. package/dist/cjs/utils/run.cjs +59 -0
  23. package/dist/cjs/utils/run.cjs.map +1 -0
  24. package/dist/esm/common/enum.mjs +108 -0
  25. package/dist/esm/common/enum.mjs.map +1 -0
  26. package/dist/esm/events.mjs +97 -0
  27. package/dist/esm/events.mjs.map +1 -0
  28. package/dist/esm/graphs/Graph.mjs +310 -0
  29. package/dist/esm/graphs/Graph.mjs.map +1 -0
  30. package/dist/esm/llm/providers.mjs +27 -0
  31. package/dist/esm/llm/providers.mjs.map +1 -0
  32. package/dist/esm/main.mjs +9 -0
  33. package/dist/esm/main.mjs.map +1 -0
  34. package/dist/esm/messages.mjs +190 -0
  35. package/dist/esm/messages.mjs.map +1 -0
  36. package/dist/esm/run.mjs +104 -0
  37. package/dist/esm/run.mjs.map +1 -0
  38. package/dist/esm/stream.mjs +131 -0
  39. package/dist/esm/stream.mjs.map +1 -0
  40. package/dist/esm/tools/ToolNode.mjs +77 -0
  41. package/dist/esm/tools/ToolNode.mjs.map +1 -0
  42. package/dist/esm/utils/graph.mjs +13 -0
  43. package/dist/esm/utils/graph.mjs.map +1 -0
  44. package/dist/esm/utils/run.mjs +57 -0
  45. package/dist/esm/utils/run.mjs.map +1 -0
  46. package/dist/types/common/enum.d.ts +79 -0
  47. package/dist/types/common/index.d.ts +1 -0
  48. package/dist/types/events.d.ts +22 -0
  49. package/dist/types/graphs/Graph.d.ts +86 -0
  50. package/dist/types/graphs/index.d.ts +1 -0
  51. package/dist/types/index.d.ts +8 -0
  52. package/dist/types/llm/providers.d.ts +4 -0
  53. package/dist/types/messages.d.ts +10 -0
  54. package/dist/types/prompts/collab.d.ts +1 -0
  55. package/dist/types/prompts/index.d.ts +2 -0
  56. package/dist/types/prompts/taskmanager.d.ts +41 -0
  57. package/dist/types/run.d.ts +21 -0
  58. package/dist/types/scripts/args.d.ts +6 -0
  59. package/dist/types/scripts/cli.d.ts +1 -0
  60. package/dist/types/scripts/cli2.d.ts +1 -0
  61. package/dist/types/scripts/cli3.d.ts +1 -0
  62. package/dist/types/scripts/cli4.d.ts +1 -0
  63. package/dist/types/scripts/cli5.d.ts +1 -0
  64. package/dist/types/scripts/empty_input.d.ts +1 -0
  65. package/dist/types/stream.d.ts +5 -0
  66. package/dist/types/tools/ToolNode.d.ts +15 -0
  67. package/dist/types/tools/example.d.ts +26 -0
  68. package/dist/types/types/graph.d.ts +108 -0
  69. package/dist/types/types/index.d.ts +5 -0
  70. package/dist/types/types/llm.d.ts +25 -0
  71. package/dist/types/types/run.d.ts +53 -0
  72. package/dist/types/types/stream.d.ts +134 -0
  73. package/dist/types/types/tools.d.ts +24 -0
  74. package/dist/types/utils/graph.d.ts +2 -0
  75. package/dist/types/utils/index.d.ts +2 -0
  76. package/dist/types/utils/llmConfig.d.ts +2 -0
  77. package/dist/types/utils/logging.d.ts +1 -0
  78. package/dist/types/utils/run.d.ts +20 -0
  79. package/package.json +142 -0
  80. package/src/common/enum.ts +121 -0
  81. package/src/common/index.ts +2 -0
  82. package/src/events.ts +110 -0
  83. package/src/graphs/Graph.ts +416 -0
  84. package/src/graphs/index.ts +1 -0
  85. package/src/index.ts +15 -0
  86. package/src/llm/providers.ts +27 -0
  87. package/src/messages.ts +210 -0
  88. package/src/prompts/collab.ts +6 -0
  89. package/src/prompts/index.ts +2 -0
  90. package/src/prompts/taskmanager.ts +61 -0
  91. package/src/proto/CollabGraph.ts +269 -0
  92. package/src/proto/TaskManager.ts +243 -0
  93. package/src/proto/collab.ts +200 -0
  94. package/src/proto/collab_design.ts +184 -0
  95. package/src/proto/collab_design_v2.ts +224 -0
  96. package/src/proto/collab_design_v3.ts +255 -0
  97. package/src/proto/collab_design_v4.ts +220 -0
  98. package/src/proto/collab_design_v5.ts +251 -0
  99. package/src/proto/collab_graph.ts +181 -0
  100. package/src/proto/collab_original.ts +123 -0
  101. package/src/proto/example.ts +93 -0
  102. package/src/proto/example_new.ts +68 -0
  103. package/src/proto/example_old.ts +201 -0
  104. package/src/proto/example_test.ts +152 -0
  105. package/src/proto/example_test_anthropic.ts +100 -0
  106. package/src/proto/log_stream.ts +202 -0
  107. package/src/proto/main_collab_community_event.ts +133 -0
  108. package/src/proto/main_collab_design_v2.ts +96 -0
  109. package/src/proto/main_collab_design_v4.ts +100 -0
  110. package/src/proto/main_collab_design_v5.ts +135 -0
  111. package/src/proto/main_collab_global_analysis.ts +122 -0
  112. package/src/proto/main_collab_hackathon_event.ts +153 -0
  113. package/src/proto/main_collab_space_mission.ts +153 -0
  114. package/src/proto/main_philosophy.ts +210 -0
  115. package/src/proto/original_script.ts +126 -0
  116. package/src/proto/standard.ts +100 -0
  117. package/src/proto/stream.ts +56 -0
  118. package/src/proto/tasks.ts +118 -0
  119. package/src/proto/tools/global_analysis_tools.ts +86 -0
  120. package/src/proto/tools/space_mission_tools.ts +60 -0
  121. package/src/proto/vertexai.ts +54 -0
  122. package/src/run.ts +132 -0
  123. package/src/scripts/args.ts +42 -0
  124. package/src/scripts/cli.ts +166 -0
  125. package/src/scripts/cli2.ts +124 -0
  126. package/src/scripts/cli3.ts +175 -0
  127. package/src/scripts/cli4.ts +182 -0
  128. package/src/scripts/cli5.ts +182 -0
  129. package/src/scripts/empty_input.ts +136 -0
  130. package/src/stream.ts +145 -0
  131. package/src/tools/ToolNode.ts +108 -0
  132. package/src/tools/example.ts +52 -0
  133. package/src/types/graph.ts +126 -0
  134. package/src/types/index.ts +6 -0
  135. package/src/types/llm.ts +38 -0
  136. package/src/types/run.ts +56 -0
  137. package/src/types/stream.ts +174 -0
  138. package/src/types/tools.ts +31 -0
  139. package/src/utils/graph.ts +11 -0
  140. package/src/utils/index.ts +2 -0
  141. package/src/utils/llmConfig.ts +50 -0
  142. package/src/utils/logging.ts +48 -0
  143. package/src/utils/run.ts +91 -0
@@ -0,0 +1,8 @@
1
+ export * from './run';
2
+ export * from './stream';
3
+ export * from './events';
4
+ export * from './messages';
5
+ export * from './graphs';
6
+ export * from './common';
7
+ export * from './utils';
8
+ export type * from './types';
@@ -0,0 +1,4 @@
1
+ import type * as t from '@/types';
2
+ import { Providers } from '@/common';
3
+ export declare const llmProviders: Record<Providers, t.ChatModelConstructor>;
4
+ export declare const getChatModelClass: (provider: Providers) => t.ChatModelConstructor;
@@ -0,0 +1,10 @@
1
+ import { AIMessageChunk, HumanMessage, ToolMessage, AIMessage, BaseMessage } from '@langchain/core/messages';
2
+ import type * as t from '@/types';
3
+ export declare function getConverseOverrideMessage({ userMessage, lastMessageX, lastMessageY }: {
4
+ userMessage: string[];
5
+ lastMessageX: AIMessageChunk;
6
+ lastMessageY: ToolMessage;
7
+ }): HumanMessage;
8
+ export declare function modifyDeltaProperties(obj?: AIMessageChunk): AIMessageChunk | undefined;
9
+ export declare function formatAnthropicMessage(message: AIMessageChunk): AIMessage;
10
+ export declare function convertMessagesToContent(messages: BaseMessage[]): t.MessageContentComplex[];
@@ -0,0 +1 @@
1
+ export declare const supervisorPrompt = "You are a supervisor tasked with managing a conversation between the\nfollowing workers: {members}. Given the following user request,\nrespond with the worker to act next. Each worker will perform a\ntask and respond with their results and status. Multiple workers can work at once, and they can use multiple tools at once. Each worker can run their tools multiple times per task. When finished,\nrespond with FINISH.";
@@ -0,0 +1,2 @@
1
+ export * from './collab';
2
+ export * from './taskmanager';
@@ -0,0 +1,41 @@
1
+ export declare const taskManagerPrompt = "You are a Task Manager responsible for efficiently coordinating a team of specialized workers: {members}. Your PRIMARY and SOLE OBJECTIVE is to fulfill the user's specific request as quickly and effectively as possible.\n\nCRITICAL GUIDELINES:\n1. The user's request is your CHIEF CONCERN. Every action must directly contribute to fulfilling this request.\n2. Aim to complete the entire task in NO MORE THAN 2-3 TURNS, unless explicitly instructed otherwise.\n3. Eliminate all superfluous activity. Each task must be essential to achieving the user's goal.\n4. Assign no more than 5 tasks per turn, and only if absolutely necessary.\n5. Be concise and direct in your task assignments.\n6. End the process IMMEDIATELY once the user's request is fulfilled by setting 'end' to true and assigning no new tasks.\n\nYour responsibilities:\n1. Analyze the user's request and break it down into the minimum necessary subtasks.\n2. Assign these essential tasks to the most appropriate team members based on their skills and tools.\n3. Prioritize tasks to ensure the most efficient path to completion.\n4. Continuously evaluate if the user's request has been fully addressed.\n5. End the process IMMEDIATELY once the user's request is fulfilled.\n\nTask Assignment Guidelines:\n- Assign only the most crucial tasks required to meet the user's needs.\n- Multiple tasks can be assigned to the same team member if it improves efficiency.\n- Always specify the tool to use if applicable.\n- Consider task dependencies to minimize the number of turns.\n\nAfter each round:\n- Critically assess if the user's request has been fully addressed.\n- If more work is genuinely needed, assign only the most essential remaining tasks.\n- If the user's request has been fulfilled or can be fulfilled with the results at hand, set 'end' to true and assign no new tasks.\n\nREMEMBER: Your success is measured by how quickly and effectively you fulfill the user's request, not by the number of tasks assigned or turns taken. Excessive deliberation or unnecessary tasks are counterproductive. Focus solely on the user's needs and conclude the process as soon as those needs are met.";
2
+ export declare const assignTasksFunctionDescription = "Assign the minimum necessary tasks to team members to fulfill the user's request as quickly as possible. Assign up to 5 tasks maximum per turn, only if absolutely necessary. Each task must specify the team member, a concise description, and the tool to use if applicable.";
3
+ export declare const assignTasksFunctionParameters: {
4
+ type: string;
5
+ properties: {
6
+ tasks: {
7
+ type: string;
8
+ items: {
9
+ type: string;
10
+ properties: {
11
+ member: {
12
+ type: string;
13
+ description: string;
14
+ };
15
+ description: {
16
+ type: string;
17
+ description: string;
18
+ };
19
+ tool: {
20
+ type: string;
21
+ description: string;
22
+ };
23
+ };
24
+ required: string[];
25
+ };
26
+ description: string;
27
+ };
28
+ };
29
+ required: string[];
30
+ };
31
+ export declare const endProcessFunctionDescription = "End the process when the user's request has been fulfilled.";
32
+ export declare const endProcessFunctionParameters: {
33
+ type: string;
34
+ properties: {
35
+ reason: {
36
+ type: string;
37
+ description: string;
38
+ };
39
+ };
40
+ required: string[];
41
+ };
@@ -0,0 +1,21 @@
1
+ import type { BaseMessage, MessageContentComplex } from '@langchain/core/messages';
2
+ import type { RunnableConfig } from '@langchain/core/runnables';
3
+ import type { ClientCallbacks, SystemCallbacks } from '@/graphs/Graph';
4
+ import type * as t from '@/types';
5
+ import { Providers } from '@/common';
6
+ export declare class Run<T extends t.BaseGraphState> {
7
+ graphRunnable?: t.CompiledWorkflow<T, Partial<T>, string>;
8
+ private handlerRegistry;
9
+ private Graph;
10
+ provider: Providers | undefined;
11
+ run_id: string | undefined;
12
+ private constructor();
13
+ private createStandardGraph;
14
+ static create<T extends t.BaseGraphState>(config: t.RunConfig): Promise<Run<T>>;
15
+ getRunMessages(): BaseMessage[] | undefined;
16
+ processStream(inputs: t.IState, config: Partial<RunnableConfig> & {
17
+ version: 'v1' | 'v2';
18
+ }, clientCallbacks?: ClientCallbacks): Promise<MessageContentComplex[] | undefined>;
19
+ private createSystemCallback;
20
+ getCallbacks(clientCallbacks: ClientCallbacks): SystemCallbacks;
21
+ }
@@ -0,0 +1,6 @@
1
+ export declare function getArgs(): Promise<{
2
+ userName: string;
3
+ location: string;
4
+ provider: string;
5
+ currentDate: string;
6
+ }>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { Graph } from '@/graphs';
2
+ import type * as t from '@/types';
3
+ export declare class ChatModelStreamHandler implements t.EventHandler {
4
+ handle(event: string, data: t.StreamEventData, metadata?: Record<string, unknown>, graph?: Graph): void;
5
+ }
@@ -0,0 +1,15 @@
1
+ import { END } from '@langchain/langgraph';
2
+ import type { MessagesState } from '@langchain/langgraph/dist/graph/message';
3
+ import type { BaseMessage } from '@langchain/core/messages';
4
+ import type * as t from '@/types';
5
+ import { RunnableCallable } from '@/utils';
6
+ import { GraphNodeKeys } from '@/common';
7
+ export declare class ToolNode<T extends BaseMessage[] | MessagesState> extends RunnableCallable<T, T> {
8
+ tools: t.GenericTool[];
9
+ private toolMap;
10
+ private loadRuntimeTools?;
11
+ handleToolErrors: boolean;
12
+ constructor({ tools, toolMap, name, tags, handleToolErrors, loadRuntimeTools, }: t.ToolNodeConstructorParams);
13
+ private run;
14
+ }
15
+ export declare function toolsCondition(state: BaseMessage[] | MessagesState): GraphNodeKeys.TOOLS | typeof END;
@@ -0,0 +1,26 @@
1
+ import { TavilySearchResults } from '@langchain/community/tools/tavily_search';
2
+ import { DynamicStructuredTool } from '@langchain/core/tools';
3
+ import { z } from 'zod';
4
+ export declare const chartTool: DynamicStructuredTool<z.ZodObject<{
5
+ data: z.ZodArray<z.ZodObject<{
6
+ label: z.ZodString;
7
+ value: z.ZodNumber;
8
+ }, "strip", z.ZodTypeAny, {
9
+ value: number;
10
+ label: string;
11
+ }, {
12
+ value: number;
13
+ label: string;
14
+ }>, "many">;
15
+ }, "strip", z.ZodTypeAny, {
16
+ data: {
17
+ value: number;
18
+ label: string;
19
+ }[];
20
+ }, {
21
+ data: {
22
+ value: number;
23
+ label: string;
24
+ }[];
25
+ }>>;
26
+ export declare const tavilyTool: TavilySearchResults;
@@ -0,0 +1,108 @@
1
+ import type { StateGraphArgs, StateGraph, CompiledStateGraph } from '@langchain/langgraph';
2
+ import type { BaseMessage, AIMessageChunk } from '@langchain/core/messages';
3
+ import type { ChatGenerationChunk } from '@langchain/core/outputs';
4
+ import type { Graph } from '@/graphs';
5
+ import { RunnableConfig } from '@langchain/core/runnables';
6
+ export type BaseGraphState = {
7
+ messages: BaseMessage[];
8
+ };
9
+ export type IState = BaseGraphState;
10
+ export interface EventHandler {
11
+ handle(event: string, data: StreamEventData, metadata?: Record<string, unknown>, graph?: Graph): void;
12
+ }
13
+ export type GraphStateChannels<T extends BaseGraphState> = StateGraphArgs<T>['channels'];
14
+ export type Workflow<T extends BaseGraphState = BaseGraphState, U extends Partial<T> = Partial<T>, N extends string = string> = StateGraph<T, U, N>;
15
+ export type CompiledWorkflow<T extends BaseGraphState = BaseGraphState, U extends Partial<T> = Partial<T>, N extends string = string> = CompiledStateGraph<T, U, N>;
16
+ export type EventStreamCallbackHandlerInput = Parameters<CompiledWorkflow['streamEvents']>[2] extends Omit<infer T, 'autoClose'> ? T : never;
17
+ export type StreamChunk = ChatGenerationChunk & {
18
+ message: AIMessageChunk;
19
+ } | AIMessageChunk;
20
+ /**
21
+ * Data associated with a StreamEvent.
22
+ */
23
+ export type StreamEventData = {
24
+ /**
25
+ * The input passed to the runnable that generated the event.
26
+ * Inputs will sometimes be available at the *START* of the runnable, and
27
+ * sometimes at the *END* of the runnable.
28
+ * If a runnable is able to stream its inputs, then its input by definition
29
+ * won't be known until the *END* of the runnable when it has finished streaming
30
+ * its inputs.
31
+ */
32
+ input?: unknown;
33
+ /**
34
+ * The output of the runnable that generated the event.
35
+ * Outputs will only be available at the *END* of the runnable.
36
+ * For most runnables, this field can be inferred from the `chunk` field,
37
+ * though there might be some exceptions for special cased runnables (e.g., like
38
+ * chat models), which may return more information.
39
+ */
40
+ output?: unknown;
41
+ /**
42
+ * A streaming chunk from the output that generated the event.
43
+ * chunks support addition in general, and adding them up should result
44
+ * in the output of the runnable that generated the event.
45
+ */
46
+ chunk?: StreamChunk;
47
+ /**
48
+ * Runnable config for invoking other runnables within handlers.
49
+ */
50
+ config?: RunnableConfig;
51
+ /**
52
+ * Custom result from the runnable that generated the event.
53
+ */
54
+ result?: unknown;
55
+ };
56
+ /**
57
+ * A streaming event.
58
+ *
59
+ * Schema of a streaming event which is produced from the streamEvents method.
60
+ */
61
+ export type StreamEvent = {
62
+ /**
63
+ * Event names are of the format: on_[runnable_type]_(start|stream|end).
64
+ *
65
+ * Runnable types are one of:
66
+ * - llm - used by non chat models
67
+ * - chat_model - used by chat models
68
+ * - prompt -- e.g., ChatPromptTemplate
69
+ * - tool -- LangChain tools
70
+ * - chain - most Runnables are of this type
71
+ *
72
+ * Further, the events are categorized as one of:
73
+ * - start - when the runnable starts
74
+ * - stream - when the runnable is streaming
75
+ * - end - when the runnable ends
76
+ *
77
+ * start, stream and end are associated with slightly different `data` payload.
78
+ *
79
+ * Please see the documentation for `EventData` for more details.
80
+ */
81
+ event: string;
82
+ /** The name of the runnable that generated the event. */
83
+ name: string;
84
+ /**
85
+ * An randomly generated ID to keep track of the execution of the given runnable.
86
+ *
87
+ * Each child runnable that gets invoked as part of the execution of a parent runnable
88
+ * is assigned its own unique ID.
89
+ */
90
+ run_id: string;
91
+ /**
92
+ * Tags associated with the runnable that generated this event.
93
+ * Tags are always inherited from parent runnables.
94
+ */
95
+ tags?: string[];
96
+ /** Metadata associated with the runnable that generated this event. */
97
+ metadata: Record<string, unknown>;
98
+ /**
99
+ * Event data.
100
+ *
101
+ * The contents of the event data depend on the event type.
102
+ */
103
+ data: StreamEventData;
104
+ };
105
+ export type GraphConfig = {
106
+ provider: string;
107
+ thread_id?: string;
108
+ };
@@ -0,0 +1,5 @@
1
+ export * from './graph';
2
+ export * from './llm';
3
+ export * from './run';
4
+ export * from './stream';
5
+ export * from './tools';
@@ -0,0 +1,25 @@
1
+ import { ChatOpenAI } from '@langchain/openai';
2
+ import { ChatAnthropic } from '@langchain/anthropic';
3
+ import { ChatMistralAI } from '@langchain/mistralai';
4
+ import { ChatBedrockConverse } from '@langchain/aws';
5
+ import { ChatVertexAI } from '@langchain/google-vertexai';
6
+ import { BedrockChat, BedrockChatFields } from '@langchain/community/chat_models/bedrock/web';
7
+ import type { ChatVertexAIInput } from '@langchain/google-vertexai';
8
+ import type { ChatBedrockConverseInput } from '@langchain/aws';
9
+ import type { ChatMistralAIInput } from '@langchain/mistralai';
10
+ import type { AnthropicInput } from '@langchain/anthropic';
11
+ import type { OpenAIInput } from '@langchain/openai';
12
+ import { Providers } from '@/common';
13
+ export type OpenAIClientOptions = Partial<OpenAIInput>;
14
+ export type AnthropicClientOptions = Partial<AnthropicInput>;
15
+ export type MistralAIClientOptions = Partial<ChatMistralAIInput>;
16
+ export type VertexAIClientOptions = Partial<ChatVertexAIInput>;
17
+ export type BedrockClientOptions = Partial<BedrockChatFields>;
18
+ export type BedrockConverseClientOptions = Partial<ChatBedrockConverseInput>;
19
+ export type ClientOptions = OpenAIClientOptions | AnthropicClientOptions | MistralAIClientOptions | VertexAIClientOptions | BedrockClientOptions | BedrockConverseClientOptions;
20
+ export type ChatModel = typeof ChatAnthropic | typeof ChatOpenAI | typeof ChatMistralAI | typeof ChatVertexAI | typeof BedrockChat | typeof ChatBedrockConverse;
21
+ export type LLMConfig = {
22
+ provider: Providers;
23
+ } & ClientOptions;
24
+ export type ChatModelInstance = ChatOpenAI | ChatAnthropic | ChatMistralAI | ChatVertexAI | BedrockChat | ChatBedrockConverse;
25
+ export type ChatModelConstructor = new (config: ClientOptions) => ChatModelInstance;
@@ -0,0 +1,53 @@
1
+ import type * as z from 'zod';
2
+ import type { BaseMessage } from '@langchain/core/messages';
3
+ import type { StructuredTool } from '@langchain/core/tools';
4
+ import type * as e from '@/common/enum';
5
+ import type * as g from '@/types/graph';
6
+ import type * as t from '@/types/tools';
7
+ import type * as l from '@/types/llm';
8
+ export type ZodObjectAny = z.ZodObject<any, any, any, any>;
9
+ export type StandardGraphConfig = {
10
+ runId?: string;
11
+ type?: 'standard';
12
+ provider?: e.Providers;
13
+ instructions?: string;
14
+ llmConfig: l.LLMConfig;
15
+ tools?: t.GenericTool[];
16
+ toolMap?: t.ToolMap;
17
+ additional_instructions?: string;
18
+ clientOptions?: Record<string, unknown>;
19
+ };
20
+ export interface AgentStateChannels {
21
+ messages: BaseMessage[];
22
+ next: string;
23
+ [key: string]: unknown;
24
+ instructions?: string;
25
+ additional_instructions?: string;
26
+ }
27
+ export interface Member {
28
+ name: string;
29
+ systemPrompt: string;
30
+ tools: StructuredTool[];
31
+ llmConfig: l.LLMConfig;
32
+ }
33
+ export type CollaborativeGraphConfig = {
34
+ type: 'collaborative';
35
+ members: Member[];
36
+ supervisorConfig: {
37
+ systemPrompt?: string;
38
+ llmConfig: l.LLMConfig;
39
+ };
40
+ };
41
+ export type TaskManagerGraphConfig = {
42
+ type: 'taskmanager';
43
+ members: Member[];
44
+ supervisorConfig: {
45
+ systemPrompt?: string;
46
+ llmConfig: l.LLMConfig;
47
+ };
48
+ };
49
+ export type RunConfig = {
50
+ graphConfig: StandardGraphConfig | CollaborativeGraphConfig | TaskManagerGraphConfig;
51
+ customHandlers?: Record<string, g.EventHandler>;
52
+ runId?: string;
53
+ };
@@ -0,0 +1,134 @@
1
+ import type { MessageContentImageUrl, MessageContentText, ToolMessage } from '@langchain/core/messages';
2
+ import type { ToolCall, ToolCallChunk } from '@langchain/core/messages/tool';
3
+ import { StepTypes } from '@/common/enum';
4
+ /** Event names are of the format: on_[runnable_type]_(start|stream|end).
5
+
6
+ Runnable types are one of:
7
+
8
+ llm - used by non chat models
9
+ chat_model - used by chat models
10
+ prompt -- e.g., ChatPromptTemplate
11
+ tool -- LangChain tools
12
+ chain - most Runnables are of this type
13
+ Further, the events are categorized as one of:
14
+
15
+ start - when the runnable starts
16
+ stream - when the runnable is streaming
17
+ end - when the runnable ends
18
+ start, stream and end are associated with slightly different data payload.
19
+
20
+ Please see the documentation for EventData for more details. */
21
+ export type EventName = string;
22
+ export type RunStep = {
23
+ type: StepTypes;
24
+ id: string;
25
+ runId?: string;
26
+ index: number;
27
+ stepIndex?: number;
28
+ stepDetails: StepDetails;
29
+ usage: null | {};
30
+ };
31
+ /**
32
+ * Represents a run step delta i.e. any changed fields on a run step during
33
+ * streaming.
34
+ */
35
+ export interface RunStepDeltaEvent {
36
+ /**
37
+ * The identifier of the run step, which can be referenced in API endpoints.
38
+ */
39
+ id: string;
40
+ /**
41
+ * The delta containing the fields that have changed on the run step.
42
+ */
43
+ delta: ToolCallDelta;
44
+ }
45
+ export type StepDetails = MessageCreationDetails | ToolCallsDetails;
46
+ export type StepCompleted = ToolCallCompleted;
47
+ export type MessageCreationDetails = {
48
+ type: StepTypes.MESSAGE_CREATION;
49
+ message_creation: {
50
+ message_id: string;
51
+ };
52
+ };
53
+ export type ToolEndData = {
54
+ input: string | Record<string, unknown>;
55
+ output: ToolMessage;
56
+ };
57
+ export type ProcessedToolCall = {
58
+ name: string;
59
+ args: string | Record<string, unknown>;
60
+ id: string;
61
+ output: string;
62
+ progress: number;
63
+ };
64
+ export type ProcessedContent = {
65
+ type: ContentType;
66
+ text?: string;
67
+ tool_call?: ProcessedToolCall;
68
+ };
69
+ export type ToolCallCompleted = {
70
+ type: 'tool_call';
71
+ tool_call: ProcessedToolCall;
72
+ };
73
+ export type ToolCompleteEvent = ToolCallCompleted & {
74
+ /** The Step Id of the Tool Call */
75
+ id: string;
76
+ /** The content index of the tool call */
77
+ index: number;
78
+ type: 'tool_call';
79
+ };
80
+ export type ToolCallsDetails = {
81
+ type: StepTypes.TOOL_CALLS;
82
+ tool_calls: AgentToolCall[];
83
+ };
84
+ export type ToolCallDelta = {
85
+ type: StepTypes.TOOL_CALLS;
86
+ tool_calls: ToolCallChunk[];
87
+ };
88
+ export type AgentToolCall = {
89
+ id: string;
90
+ type: 'function';
91
+ function: {
92
+ name: string;
93
+ arguments: string | object;
94
+ };
95
+ } | ToolCall;
96
+ export interface ExtendedMessageContent {
97
+ type?: string;
98
+ text?: string;
99
+ input?: string;
100
+ index?: number;
101
+ id?: string;
102
+ name?: string;
103
+ }
104
+ /**
105
+ * Represents a message delta i.e. any changed fields on a message during
106
+ * streaming.
107
+ */
108
+ export interface MessageDeltaEvent {
109
+ /**
110
+ * The identifier of the message, which can be referenced in API endpoints.
111
+ */
112
+ id: string;
113
+ /**
114
+ * The delta containing the fields that have changed on the Message.
115
+ */
116
+ delta: MessageDelta;
117
+ }
118
+ /**
119
+ * The delta containing the fields that have changed on the Message.
120
+ */
121
+ export interface MessageDelta {
122
+ /**
123
+ * The content of the message in array of text and/or images.
124
+ */
125
+ content?: MessageContentComplex[];
126
+ }
127
+ export type ContentType = 'text' | 'image_url' | 'tool_call' | string;
128
+ export type MessageContentComplex = (MessageContentText | MessageContentImageUrl | (Record<string, any> & {
129
+ type?: 'text' | 'image_url' | string;
130
+ }) | (Record<string, any> & {
131
+ type?: never;
132
+ })) & {
133
+ tool_call_ids?: string[];
134
+ };
@@ -0,0 +1,24 @@
1
+ import type { RunnableToolLike } from '@langchain/core/runnables';
2
+ import type { StructuredToolInterface } from '@langchain/core/tools';
3
+ import type { ToolCall } from '@langchain/core/messages/tool';
4
+ /** Replacement type for `import type { ToolCall } from '@langchain/core/messages/tool'` in order to have stringified args typed */
5
+ export type CustomToolCall = {
6
+ name: string;
7
+ args: string | Record<string, any>;
8
+ id?: string;
9
+ type?: 'tool_call';
10
+ };
11
+ export type GenericTool = StructuredToolInterface | RunnableToolLike;
12
+ export type ToolMap = Map<string, GenericTool>;
13
+ export type ToolRefs = {
14
+ tools: GenericTool[];
15
+ toolMap?: ToolMap;
16
+ };
17
+ export type ToolRefGenerator = (tool_calls: ToolCall[]) => ToolRefs;
18
+ export type ToolNodeOptions = {
19
+ name?: string;
20
+ tags?: string[];
21
+ handleToolErrors?: boolean;
22
+ loadRuntimeTools?: ToolRefGenerator;
23
+ };
24
+ export type ToolNodeConstructorParams = ToolRefs & ToolNodeOptions;
@@ -0,0 +1,2 @@
1
+ export declare const resetIfNotEmpty: <T>(value: T, resetValue: T) => T;
2
+ export declare const joinKeys: (args: (string | number | undefined)[]) => string;
@@ -0,0 +1,2 @@
1
+ export * from './graph';
2
+ export * from './run';
@@ -0,0 +1,2 @@
1
+ import type * as t from '@/types';
2
+ export declare function getLLMConfig(provider: string): t.LLMConfig;
@@ -0,0 +1 @@
1
+ export declare function setupLogging(logFileName: string): void;
@@ -0,0 +1,20 @@
1
+ import { CallbackManagerForChainRun } from '@langchain/core/callbacks/manager';
2
+ import { Runnable, RunnableConfig } from '@langchain/core/runnables';
3
+ export interface RunnableCallableArgs extends Partial<any> {
4
+ name?: string;
5
+ func: (...args: any[]) => any;
6
+ tags?: string[];
7
+ trace?: boolean;
8
+ recurse?: boolean;
9
+ }
10
+ export declare class RunnableCallable<I = unknown, O = unknown> extends Runnable<I, O> {
11
+ lc_namespace: string[];
12
+ func: (...args: any[]) => any;
13
+ tags?: string[];
14
+ config?: RunnableConfig;
15
+ trace: boolean;
16
+ recurse: boolean;
17
+ constructor(fields: RunnableCallableArgs);
18
+ protected _tracedInvoke(input: I, config?: Partial<RunnableConfig>, runManager?: CallbackManagerForChainRun): Promise<O>;
19
+ invoke(input: any, options?: Partial<RunnableConfig> | undefined): Promise<any>;
20
+ }