@vibe-agent-toolkit/runtime-langchain 0.1.2-rc.4

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/README.md ADDED
@@ -0,0 +1,307 @@
1
+ # @vibe-agent-toolkit/runtime-langchain
2
+
3
+ LangChain.js runtime adapter for VAT (Vibe Agent Toolkit) agents.
4
+
5
+ Converts VAT archetype agents to LangChain primitives, enabling portability across LLM providers (OpenAI, Anthropic, etc.) while maintaining type safety and agent semantics.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @vibe-agent-toolkit/runtime-langchain langchain @langchain/core
11
+ # or
12
+ bun add @vibe-agent-toolkit/runtime-langchain langchain @langchain/core
13
+ ```
14
+
15
+ You'll also need an LLM provider package:
16
+ ```bash
17
+ npm install @langchain/openai # For OpenAI
18
+ npm install @langchain/anthropic # For Anthropic Claude
19
+ ```
20
+
21
+ ## Supported Archetypes
22
+
23
+ ### Conversational Assistant → Async Function with History
24
+
25
+ Converts multi-turn conversational VAT agents to stateful async functions that manage conversation history and session state.
26
+
27
+ **Use cases:** Chatbots, advisory systems, interactive assistants, context-aware conversations.
28
+
29
+ #### Example: Breed Advisor
30
+
31
+ ```typescript
32
+ import { ChatOpenAI } from '@langchain/openai';
33
+ import { breedAdvisorAgent, BreedAdvisorInputSchema, BreedAdvisorOutputSchema } from '@vibe-agent-toolkit/vat-example-cat-agents';
34
+ import { convertConversationalAssistantToFunction } from '@vibe-agent-toolkit/runtime-langchain';
35
+
36
+ // Convert VAT agent to conversational function
37
+ const chat = convertConversationalAssistantToFunction({
38
+ agent: breedAdvisorAgent,
39
+ inputSchema: BreedAdvisorInputSchema,
40
+ outputSchema: BreedAdvisorOutputSchema,
41
+ llmConfig: {
42
+ model: new ChatOpenAI({ model: 'gpt-4o' }),
43
+ temperature: 0.7,
44
+ },
45
+ });
46
+
47
+ // First turn
48
+ let result = await chat({
49
+ message: 'I need help finding a cat breed',
50
+ });
51
+ console.log(result.output.reply);
52
+
53
+ // Second turn (pass session to maintain history)
54
+ result = await chat(
55
+ {
56
+ message: 'I love classical music',
57
+ sessionState: { profile: result.output.updatedProfile },
58
+ },
59
+ result.session
60
+ );
61
+ console.log(result.output.reply);
62
+
63
+ // Continue conversation with accumulated context
64
+ result = await chat(
65
+ {
66
+ message: 'I live in an apartment with kids',
67
+ sessionState: { profile: result.output.updatedProfile },
68
+ },
69
+ result.session
70
+ );
71
+
72
+ // Get recommendations
73
+ if (result.output.recommendations) {
74
+ console.log('Recommended breeds:', result.output.recommendations);
75
+ }
76
+ ```
77
+
78
+ ### Pure Function Tools → `DynamicStructuredTool`
79
+
80
+ Converts synchronous, deterministic VAT agents to LangChain tools that can be called by LLMs.
81
+
82
+ **Use cases:** Validation, transformation, computation, structured data operations.
83
+
84
+ #### Example: Haiku Validator
85
+
86
+ ```typescript
87
+ import { ChatOpenAI } from '@langchain/openai';
88
+ import { createToolCallingAgent, AgentExecutor } from 'langchain/agents';
89
+ import { ChatPromptTemplate } from '@langchain/core/prompts';
90
+ import { haikuValidatorAgent, HaikuSchema, HaikuValidationResultSchema } from '@vibe-agent-toolkit/vat-example-cat-agents';
91
+ import { convertPureFunctionToTool } from '@vibe-agent-toolkit/runtime-langchain';
92
+
93
+ // Convert VAT agent to LangChain tool
94
+ const { tool } = convertPureFunctionToTool(
95
+ haikuValidatorAgent,
96
+ HaikuSchema,
97
+ HaikuValidationResultSchema
98
+ );
99
+
100
+ // Use with LangChain agent
101
+ const llm = new ChatOpenAI({ model: 'gpt-4o-mini' });
102
+ const prompt = ChatPromptTemplate.fromMessages([
103
+ ['system', 'You are a helpful assistant'],
104
+ ['human', '{input}'],
105
+ ['placeholder', '{agent_scratchpad}'],
106
+ ]);
107
+
108
+ const agent = await createToolCallingAgent({
109
+ llm,
110
+ tools: [tool],
111
+ prompt,
112
+ });
113
+
114
+ const executor = new AgentExecutor({ agent, tools: [tool] });
115
+ const result = await executor.invoke({
116
+ input: 'Write a haiku about an orange cat and validate it'
117
+ });
118
+ ```
119
+
120
+ ### LLM Analyzer → Async Function
121
+
122
+ Converts LLM-powered VAT agents to executable async functions that work with any LangChain chat model.
123
+
124
+ **Use cases:** Content generation, analysis, transformation, structured output from LLMs.
125
+
126
+ #### Example: Name Generator
127
+
128
+ ```typescript
129
+ import { ChatOpenAI } from '@langchain/openai';
130
+ import { nameGeneratorAgent, NameGeneratorInputSchema, NameSuggestionSchema } from '@vibe-agent-toolkit/vat-example-cat-agents';
131
+ import { convertLLMAnalyzerToFunction } from '@vibe-agent-toolkit/runtime-langchain';
132
+
133
+ // Convert VAT agent to executable function
134
+ const generateName = convertLLMAnalyzerToFunction(
135
+ nameGeneratorAgent,
136
+ NameGeneratorInputSchema,
137
+ NameSuggestionSchema,
138
+ {
139
+ model: new ChatOpenAI({ model: 'gpt-4o-mini' }),
140
+ temperature: 0.9,
141
+ }
142
+ );
143
+
144
+ // Execute directly
145
+ const result = await generateName({
146
+ characteristics: {
147
+ physical: { furColor: 'Orange' },
148
+ behavioral: { personality: ['Distinguished'] },
149
+ description: 'A noble orange cat',
150
+ },
151
+ });
152
+
153
+ console.log(result.name); // "Sir Whiskersworth III"
154
+ console.log(result.reasoning); // "This name captures..."
155
+ ```
156
+
157
+ ## Provider-Agnostic Architecture
158
+
159
+ The same VAT agent code works with any LangChain-supported LLM provider:
160
+
161
+ ```typescript
162
+ import { ChatOpenAI } from '@langchain/openai';
163
+ import { ChatAnthropic } from '@langchain/anthropic';
164
+ import { convertLLMAnalyzerToFunction } from '@vibe-agent-toolkit/runtime-langchain';
165
+
166
+ // OpenAI
167
+ const generateNameOpenAI = convertLLMAnalyzerToFunction(
168
+ nameGeneratorAgent,
169
+ NameGeneratorInputSchema,
170
+ NameSuggestionSchema,
171
+ { model: new ChatOpenAI({ model: 'gpt-4o-mini' }) }
172
+ );
173
+
174
+ // Anthropic
175
+ const generateNameAnthropic = convertLLMAnalyzerToFunction(
176
+ nameGeneratorAgent,
177
+ NameGeneratorInputSchema,
178
+ NameSuggestionSchema,
179
+ { model: new ChatAnthropic({ model: 'claude-sonnet-4-5-20250929' }) }
180
+ );
181
+
182
+ // Same agent, different providers
183
+ const [openaiResult, anthropicResult] = await Promise.all([
184
+ generateNameOpenAI(input),
185
+ generateNameAnthropic(input),
186
+ ]);
187
+ ```
188
+
189
+ ## API Reference
190
+
191
+ ### `convertPureFunctionToTool()`
192
+
193
+ Converts a VAT Pure Function agent to a LangChain `DynamicStructuredTool`.
194
+
195
+ **Parameters:**
196
+ - `agent: PureFunctionAgent<TInput, TOutput>` - The VAT agent to convert
197
+ - `inputSchema: z.ZodType<TInput>` - Zod schema for input validation
198
+ - `outputSchema: z.ZodType<TOutput>` - Zod schema for output validation
199
+
200
+ **Returns:** Object with:
201
+ - `tool: DynamicStructuredTool` - LangChain tool ready for agent use
202
+ - `metadata: { name, description, version, archetype }` - Agent metadata
203
+ - `inputSchema: z.ZodType<TInput>` - Original input schema
204
+ - `outputSchema: z.ZodType<TOutput>` - Original output schema
205
+
206
+ ### `convertPureFunctionsToTools()`
207
+
208
+ Batch converts multiple pure function agents to LangChain tools.
209
+
210
+ **Parameters:**
211
+ - `configs: Record<string, ToolConversionConfig>` - Map of tool names to conversion configs
212
+
213
+ **Returns:** `Record<string, { tool: DynamicStructuredTool, metadata }>` - Map of converted tools
214
+
215
+ ### `convertLLMAnalyzerToFunction()`
216
+
217
+ Converts a VAT LLM Analyzer agent to an executable async function.
218
+
219
+ **Parameters:**
220
+ - `agent: Agent<TInput, TOutput>` - The VAT agent to convert
221
+ - `inputSchema: z.ZodType<TInput>` - Zod schema for input validation
222
+ - `outputSchema: z.ZodType<TOutput>` - Zod schema for output validation
223
+ - `llmConfig: LangChainLLMConfig` - LangChain LLM configuration
224
+
225
+ **Returns:** `(input: TInput) => Promise<TOutput>` - Executable async function
226
+
227
+ ### `convertLLMAnalyzersToFunctions()`
228
+
229
+ Batch converts multiple LLM Analyzer agents with shared LLM config.
230
+
231
+ **Parameters:**
232
+ - `configs: Record<string, LLMAnalyzerConversionConfig>` - Map of function names to conversion configs
233
+ - `llmConfig: LangChainLLMConfig` - Shared LangChain LLM configuration
234
+
235
+ **Returns:** `Record<string, (input: any) => Promise<any>>` - Map of executable functions
236
+
237
+ ### `convertConversationalAssistantToFunction()`
238
+
239
+ Converts a VAT Conversational Assistant agent to a stateful async function with conversation history management.
240
+
241
+ **Parameters:**
242
+ - `config: ConversationalAssistantConfig<TInput, TOutput, TState>` - Configuration object containing:
243
+ - `agent: Agent<TInput, TOutput>` - The VAT agent to convert
244
+ - `inputSchema: z.ZodType<TInput>` - Zod schema for input validation
245
+ - `outputSchema: z.ZodType<TOutput>` - Zod schema for output validation
246
+ - `llmConfig: LangChainLLMConfig` - LangChain LLM configuration
247
+ - `initialState?: TState` - Optional initial session state
248
+ - `systemPrompt?: string` - Optional system prompt override
249
+
250
+ **Returns:** `(input: TInput, session?: ConversationalSession<TState>) => Promise<ConversationalResult<TOutput, TState>>`
251
+
252
+ The returned function accepts:
253
+ - `input` - User input for this turn
254
+ - `session` - Optional session from previous turn (for conversation continuity)
255
+
256
+ And returns:
257
+ - `output` - Agent's validated output
258
+ - `session` - Updated session to pass to next turn (includes history and state)
259
+
260
+ ### `convertConversationalAssistantsToFunctions()`
261
+
262
+ Batch converts multiple Conversational Assistant agents with shared LLM config.
263
+
264
+ **Parameters:**
265
+ - `configs: Record<string, ConversationalAssistantConversionConfig>` - Map of function names to conversion configs
266
+ - `llmConfig: LangChainLLMConfig` - Shared LangChain LLM configuration
267
+
268
+ **Returns:** `Record<string, (input: any, session?: ConversationalSession) => Promise<ConversationalResult<any>>>` - Map of executable functions
269
+
270
+ ## Type Definitions
271
+
272
+ ### `LangChainLLMConfig`
273
+
274
+ ```typescript
275
+ interface LangChainLLMConfig {
276
+ model: BaseChatModel; // LangChain chat model instance
277
+ temperature?: number; // 0-1, default 0.7
278
+ maxTokens?: number; // Maximum tokens to generate
279
+ additionalSettings?: Record<string, unknown>; // Provider-specific settings
280
+ }
281
+ ```
282
+
283
+ ### `ConversationalSession<TState>`
284
+
285
+ ```typescript
286
+ interface ConversationalSession<TState = Record<string, unknown>> {
287
+ history: Message[]; // Conversation history (system/user/assistant messages)
288
+ state: TState; // Session-specific state (e.g., user profile)
289
+ }
290
+ ```
291
+
292
+ ### `ConversationalResult<TOutput, TState>`
293
+
294
+ ```typescript
295
+ interface ConversationalResult<TOutput, TState = Record<string, unknown>> {
296
+ output: TOutput; // Agent's validated output
297
+ session: ConversationalSession<TState>; // Updated session for next turn
298
+ }
299
+ ```
300
+
301
+ ## Examples
302
+
303
+ See [@vibe-agent-toolkit/vat-example-cat-agents](../vat-example-cat-agents) for complete agent examples that work with this adapter.
304
+
305
+ ## License
306
+
307
+ MIT
@@ -0,0 +1,121 @@
1
+ import type { Agent, Message } from '@vibe-agent-toolkit/agent-runtime';
2
+ import type { z } from 'zod';
3
+ import type { LangChainLLMConfig } from '../types.js';
4
+ /**
5
+ * Session state for conversational assistants
6
+ */
7
+ export interface ConversationalSession<TState = Record<string, unknown>> {
8
+ /** Conversation history */
9
+ history: Message[];
10
+ /** Session-specific state (e.g., user profile, preferences) */
11
+ state: TState;
12
+ }
13
+ /**
14
+ * Configuration for conversational assistant conversion
15
+ */
16
+ export interface ConversationalAssistantConfig<TInput, TOutput, TState = Record<string, unknown>> {
17
+ /** The VAT conversational assistant agent */
18
+ agent: Agent<TInput, TOutput>;
19
+ /** Zod schema for validating inputs */
20
+ inputSchema: z.ZodType<TInput>;
21
+ /** Zod schema for validating outputs */
22
+ outputSchema: z.ZodType<TOutput>;
23
+ /** LangChain LLM configuration */
24
+ llmConfig: LangChainLLMConfig;
25
+ /** Initial session state (optional) */
26
+ initialState?: TState;
27
+ /** System prompt (overrides agent's system prompt if provided) */
28
+ systemPrompt?: string;
29
+ }
30
+ /**
31
+ * Result from a conversational turn
32
+ */
33
+ export interface ConversationalResult<TOutput, TState = Record<string, unknown>> {
34
+ /** The agent's output */
35
+ output: TOutput;
36
+ /** Updated session to pass to next turn */
37
+ session: ConversationalSession<TState>;
38
+ }
39
+ /**
40
+ * Converts a VAT Conversational Assistant agent to an executable function with LangChain
41
+ *
42
+ * The returned function manages conversation history and session state across turns,
43
+ * providing a stateful conversational interface backed by LangChain models.
44
+ *
45
+ * @param config - Configuration including agent, schemas, and LLM settings
46
+ * @returns Async function that executes the agent with conversation context
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * import { ChatOpenAI } from '@langchain/openai';
51
+ * import { breedAdvisorAgent } from '@vibe-agent-toolkit/vat-example-cat-agents';
52
+ * import { convertConversationalAssistantToFunction } from '@vibe-agent-toolkit/runtime-langchain';
53
+ *
54
+ * const chat = convertConversationalAssistantToFunction({
55
+ * agent: breedAdvisorAgent,
56
+ * inputSchema: BreedAdvisorInputSchema,
57
+ * outputSchema: BreedAdvisorOutputSchema,
58
+ * llmConfig: {
59
+ * model: new ChatOpenAI({ modelName: 'gpt-4o' }),
60
+ * temperature: 0.7,
61
+ * },
62
+ * });
63
+ *
64
+ * // First turn
65
+ * let result = await chat({ message: 'I need help finding a cat breed' });
66
+ * console.log(result.output.reply);
67
+ *
68
+ * // Second turn (pass session)
69
+ * result = await chat(
70
+ * { message: 'I love classical music', sessionState: result.session.state },
71
+ * result.session
72
+ * );
73
+ * console.log(result.output.reply);
74
+ * ```
75
+ */
76
+ export declare function convertConversationalAssistantToFunction<TInput, TOutput, TState = Record<string, unknown>>(config: ConversationalAssistantConfig<TInput, TOutput, TState>): (input: TInput, session?: ConversationalSession<TState>) => Promise<ConversationalResult<TOutput, TState>>;
77
+ /**
78
+ * Batch configuration for conversational assistant conversions
79
+ */
80
+ export interface ConversationalAssistantConversionConfigs {
81
+ [key: string]: {
82
+ agent: Agent<unknown, unknown>;
83
+ inputSchema: z.ZodType<unknown>;
84
+ outputSchema: z.ZodType<unknown>;
85
+ };
86
+ }
87
+ /**
88
+ * Batch converts multiple VAT Conversational Assistant agents to executable functions
89
+ *
90
+ * @param configs - Map of function names to conversion configurations
91
+ * @param llmConfig - Shared LangChain LLM configuration for all agents
92
+ * @returns Map of function names to executable async functions
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * import { ChatOpenAI } from '@langchain/openai';
97
+ *
98
+ * const assistants = convertConversationalAssistantsToFunctions(
99
+ * {
100
+ * breedAdvisor: {
101
+ * agent: breedAdvisorAgent,
102
+ * inputSchema: BreedAdvisorInputSchema,
103
+ * outputSchema: BreedAdvisorOutputSchema,
104
+ * },
105
+ * petCareAdvisor: {
106
+ * agent: petCareAdvisorAgent,
107
+ * inputSchema: PetCareInputSchema,
108
+ * outputSchema: PetCareOutputSchema,
109
+ * },
110
+ * },
111
+ * {
112
+ * model: new ChatOpenAI({ modelName: 'gpt-4o' }),
113
+ * temperature: 0.7,
114
+ * }
115
+ * );
116
+ *
117
+ * const result = await assistants.breedAdvisor({ message: 'Hello' });
118
+ * ```
119
+ */
120
+ export declare function convertConversationalAssistantsToFunctions(configs: ConversationalAssistantConversionConfigs, llmConfig: LangChainLLMConfig): Record<string, (input: unknown, session?: ConversationalSession) => Promise<ConversationalResult<unknown>>>;
121
+ //# sourceMappingURL=conversational-assistant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversational-assistant.d.ts","sourceRoot":"","sources":["../../src/adapters/conversational-assistant.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAyB,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC/F,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,qBAAqB,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACrE,2BAA2B;IAC3B,OAAO,EAAE,OAAO,EAAE,CAAC;IAEnB,+DAA+D;IAC/D,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,6BAA6B,CAAC,MAAM,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C,CAAC;QAChC,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;KAClC,CAAC;CACH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,0CAA0C,CACxD,OAAO,EAAE,wCAAwC,EACjD,SAAS,EAAE,kBAAkB,GAC5B,MAAM,CACP,MAAM,EACN,CACE,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,qBAAqB,KAC5B,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAC5C,CAmBA"}
@@ -0,0 +1,151 @@
1
+ import { HumanMessage, SystemMessage, AIMessage } from '@langchain/core/messages';
2
+ /**
3
+ * Converts a VAT Conversational Assistant agent to an executable function with LangChain
4
+ *
5
+ * The returned function manages conversation history and session state across turns,
6
+ * providing a stateful conversational interface backed by LangChain models.
7
+ *
8
+ * @param config - Configuration including agent, schemas, and LLM settings
9
+ * @returns Async function that executes the agent with conversation context
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { ChatOpenAI } from '@langchain/openai';
14
+ * import { breedAdvisorAgent } from '@vibe-agent-toolkit/vat-example-cat-agents';
15
+ * import { convertConversationalAssistantToFunction } from '@vibe-agent-toolkit/runtime-langchain';
16
+ *
17
+ * const chat = convertConversationalAssistantToFunction({
18
+ * agent: breedAdvisorAgent,
19
+ * inputSchema: BreedAdvisorInputSchema,
20
+ * outputSchema: BreedAdvisorOutputSchema,
21
+ * llmConfig: {
22
+ * model: new ChatOpenAI({ modelName: 'gpt-4o' }),
23
+ * temperature: 0.7,
24
+ * },
25
+ * });
26
+ *
27
+ * // First turn
28
+ * let result = await chat({ message: 'I need help finding a cat breed' });
29
+ * console.log(result.output.reply);
30
+ *
31
+ * // Second turn (pass session)
32
+ * result = await chat(
33
+ * { message: 'I love classical music', sessionState: result.session.state },
34
+ * result.session
35
+ * );
36
+ * console.log(result.output.reply);
37
+ * ```
38
+ */
39
+ export function convertConversationalAssistantToFunction(config) {
40
+ const { agent, inputSchema, outputSchema, llmConfig, systemPrompt } = config;
41
+ return async (input, session) => {
42
+ // Validate input
43
+ const validatedInput = inputSchema.parse(input);
44
+ // Initialize or continue session
45
+ const currentSession = session ?? {
46
+ history: [],
47
+ state: (config.initialState ?? {}),
48
+ };
49
+ // Add system prompt to history if this is the first turn
50
+ if (currentSession.history.length === 0) {
51
+ const metadataPrompt = agent.manifest['metadata']?.['systemPrompt'];
52
+ const prompt = systemPrompt ??
53
+ (typeof metadataPrompt === 'string'
54
+ ? metadataPrompt
55
+ : metadataPrompt?.gathering);
56
+ if (typeof prompt === 'string') {
57
+ currentSession.history.push({
58
+ role: 'system',
59
+ content: prompt,
60
+ });
61
+ }
62
+ }
63
+ // Create conversational context
64
+ const context = {
65
+ mockable: false,
66
+ history: [...currentSession.history],
67
+ addToHistory: (role, content) => {
68
+ context.history.push({ role, content });
69
+ },
70
+ callLLM: async (messages) => {
71
+ // Convert VAT messages to LangChain messages
72
+ const langchainMessages = messages.map((msg) => {
73
+ switch (msg.role) {
74
+ case 'system':
75
+ return new SystemMessage(msg.content);
76
+ case 'user':
77
+ return new HumanMessage(msg.content);
78
+ case 'assistant':
79
+ return new AIMessage(msg.content);
80
+ default:
81
+ throw new Error(`Unknown message role: ${msg.role}`);
82
+ }
83
+ });
84
+ // Call LangChain model
85
+ // Note: LangChain models configure temperature/maxTokens at initialization,
86
+ // not per-invocation. Model configuration should be passed when creating the model.
87
+ const response = await llmConfig.model.invoke(langchainMessages);
88
+ return response.content.toString();
89
+ },
90
+ };
91
+ // Execute the agent
92
+ const output = await agent.execute(validatedInput, context);
93
+ // Validate output
94
+ const validatedOutput = outputSchema.parse(output);
95
+ // Update session with new history
96
+ const updatedSession = {
97
+ history: context.history,
98
+ state: currentSession.state,
99
+ };
100
+ return {
101
+ output: validatedOutput,
102
+ session: updatedSession,
103
+ };
104
+ };
105
+ }
106
+ /**
107
+ * Batch converts multiple VAT Conversational Assistant agents to executable functions
108
+ *
109
+ * @param configs - Map of function names to conversion configurations
110
+ * @param llmConfig - Shared LangChain LLM configuration for all agents
111
+ * @returns Map of function names to executable async functions
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * import { ChatOpenAI } from '@langchain/openai';
116
+ *
117
+ * const assistants = convertConversationalAssistantsToFunctions(
118
+ * {
119
+ * breedAdvisor: {
120
+ * agent: breedAdvisorAgent,
121
+ * inputSchema: BreedAdvisorInputSchema,
122
+ * outputSchema: BreedAdvisorOutputSchema,
123
+ * },
124
+ * petCareAdvisor: {
125
+ * agent: petCareAdvisorAgent,
126
+ * inputSchema: PetCareInputSchema,
127
+ * outputSchema: PetCareOutputSchema,
128
+ * },
129
+ * },
130
+ * {
131
+ * model: new ChatOpenAI({ modelName: 'gpt-4o' }),
132
+ * temperature: 0.7,
133
+ * }
134
+ * );
135
+ *
136
+ * const result = await assistants.breedAdvisor({ message: 'Hello' });
137
+ * ```
138
+ */
139
+ export function convertConversationalAssistantsToFunctions(configs, llmConfig) {
140
+ const result = {};
141
+ for (const [name, config] of Object.entries(configs)) {
142
+ result[name] = convertConversationalAssistantToFunction({
143
+ agent: config.agent,
144
+ inputSchema: config.inputSchema,
145
+ outputSchema: config.outputSchema,
146
+ llmConfig,
147
+ });
148
+ }
149
+ return result;
150
+ }
151
+ //# sourceMappingURL=conversational-assistant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversational-assistant.js","sourceRoot":"","sources":["../../src/adapters/conversational-assistant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAmDlF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,UAAU,wCAAwC,CAKtD,MAA8D;IAK9D,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;IAE7E,OAAO,KAAK,EACV,KAAa,EACb,OAAuC,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AAG,wCAAwC,CAAC;YACtD,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,75 @@
1
+ import { type Agent } from '@vibe-agent-toolkit/agent-runtime';
2
+ import type { z } from 'zod';
3
+ import type { LangChainLLMConfig, LLMAnalyzerConversionConfigs } from '../types.js';
4
+ /**
5
+ * Converts a VAT LLM Analyzer agent to an executable async function with LangChain
6
+ *
7
+ * @param agent - The VAT LLM analyzer agent to convert
8
+ * @param inputSchema - Zod schema for validating inputs
9
+ * @param outputSchema - Zod schema for validating outputs
10
+ * @param llmConfig - LangChain LLM configuration
11
+ * @returns Async function that executes the agent with LangChain model
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { ChatOpenAI } from '@langchain/openai';
16
+ * import { nameGeneratorAgent } from '@vibe-agent-toolkit/vat-example-cat-agents';
17
+ * import { convertLLMAnalyzerToFunction } from '@vibe-agent-toolkit/runtime-langchain';
18
+ *
19
+ * const generateName = convertLLMAnalyzerToFunction(
20
+ * nameGeneratorAgent,
21
+ * NameGeneratorInputSchema,
22
+ * NameSuggestionSchema,
23
+ * {
24
+ * model: new ChatOpenAI({ modelName: 'gpt-4o-mini' }),
25
+ * temperature: 0.9,
26
+ * }
27
+ * );
28
+ *
29
+ * const result = await generateName({
30
+ * characteristics: {
31
+ * physical: { furColor: 'Orange' },
32
+ * behavioral: { personality: ['Distinguished'] },
33
+ * description: 'A noble cat',
34
+ * },
35
+ * });
36
+ * console.log(result.name); // "Sir Whiskersworth III"
37
+ * ```
38
+ */
39
+ export declare function convertLLMAnalyzerToFunction<TInput, TOutput>(agent: Agent<TInput, TOutput>, inputSchema: z.ZodType<TInput>, outputSchema: z.ZodType<TOutput>, llmConfig: LangChainLLMConfig): (input: TInput) => Promise<TOutput>;
40
+ /**
41
+ * Batch converts multiple VAT LLM Analyzer agents to executable functions
42
+ *
43
+ * @param configs - Map of function names to conversion configurations
44
+ * @param llmConfig - Shared LangChain LLM configuration for all agents
45
+ * @returns Map of function names to executable async functions
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * import { ChatOpenAI } from '@langchain/openai';
50
+ *
51
+ * const functions = convertLLMAnalyzersToFunctions(
52
+ * {
53
+ * generateName: {
54
+ * agent: nameGeneratorAgent,
55
+ * inputSchema: NameGeneratorInputSchema,
56
+ * outputSchema: NameSuggestionSchema,
57
+ * },
58
+ * generateHaiku: {
59
+ * agent: haikuGeneratorAgent,
60
+ * inputSchema: HaikuGeneratorInputSchema,
61
+ * outputSchema: HaikuSchema,
62
+ * },
63
+ * },
64
+ * {
65
+ * model: new ChatOpenAI({ modelName: 'gpt-4o-mini' }),
66
+ * temperature: 0.8,
67
+ * }
68
+ * );
69
+ *
70
+ * const name = await functions.generateName(catInput);
71
+ * const haiku = await functions.generateHaiku(catInput);
72
+ * ```
73
+ */
74
+ export declare function convertLLMAnalyzersToFunctions(configs: LLMAnalyzerConversionConfigs, llmConfig: LangChainLLMConfig): Record<string, (input: unknown) => Promise<unknown>>;
75
+ //# sourceMappingURL=llm-analyzer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm-analyzer.d.ts","sourceRoot":"","sources":["../../src/adapters/llm-analyzer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAEpF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,OAAO,EAC1D,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAC9B,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAChC,SAAS,EAAE,kBAAkB,GAC5B,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAmCrC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,4BAA4B,EACrC,SAAS,EAAE,kBAAkB,GAC5B,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,CAStD"}
@@ -0,0 +1,107 @@
1
+ import { batchConvert } from '@vibe-agent-toolkit/agent-runtime';
2
+ /**
3
+ * Converts a VAT LLM Analyzer agent to an executable async function with LangChain
4
+ *
5
+ * @param agent - The VAT LLM analyzer agent to convert
6
+ * @param inputSchema - Zod schema for validating inputs
7
+ * @param outputSchema - Zod schema for validating outputs
8
+ * @param llmConfig - LangChain LLM configuration
9
+ * @returns Async function that executes the agent with LangChain model
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { ChatOpenAI } from '@langchain/openai';
14
+ * import { nameGeneratorAgent } from '@vibe-agent-toolkit/vat-example-cat-agents';
15
+ * import { convertLLMAnalyzerToFunction } from '@vibe-agent-toolkit/runtime-langchain';
16
+ *
17
+ * const generateName = convertLLMAnalyzerToFunction(
18
+ * nameGeneratorAgent,
19
+ * NameGeneratorInputSchema,
20
+ * NameSuggestionSchema,
21
+ * {
22
+ * model: new ChatOpenAI({ modelName: 'gpt-4o-mini' }),
23
+ * temperature: 0.9,
24
+ * }
25
+ * );
26
+ *
27
+ * const result = await generateName({
28
+ * characteristics: {
29
+ * physical: { furColor: 'Orange' },
30
+ * behavioral: { personality: ['Distinguished'] },
31
+ * description: 'A noble cat',
32
+ * },
33
+ * });
34
+ * console.log(result.name); // "Sir Whiskersworth III"
35
+ * ```
36
+ */
37
+ export function convertLLMAnalyzerToFunction(agent, inputSchema, outputSchema, llmConfig) {
38
+ // Create callLLM function that uses LangChain model
39
+ const callLLM = async (prompt) => {
40
+ const response = await llmConfig.model.invoke(prompt);
41
+ return response.content.toString();
42
+ };
43
+ // Return wrapped function
44
+ return async (input) => {
45
+ // Validate input
46
+ const validatedInput = inputSchema.parse(input);
47
+ // Extract model name from LangChain model
48
+ let modelName;
49
+ if ('modelName' in llmConfig.model && typeof llmConfig.model.modelName === 'string') {
50
+ modelName = llmConfig.model.modelName;
51
+ }
52
+ else if ('model' in llmConfig.model && typeof llmConfig.model.model === 'string') {
53
+ modelName = llmConfig.model.model;
54
+ }
55
+ else {
56
+ modelName = 'unknown';
57
+ }
58
+ // Execute the agent with mock mode disabled (real LLM call)
59
+ const context = {
60
+ mockable: false,
61
+ model: modelName,
62
+ temperature: llmConfig.temperature ?? 0.7,
63
+ callLLM,
64
+ };
65
+ const output = await agent.execute(validatedInput, context);
66
+ // Validate output
67
+ return outputSchema.parse(output);
68
+ };
69
+ }
70
+ /**
71
+ * Batch converts multiple VAT LLM Analyzer agents to executable functions
72
+ *
73
+ * @param configs - Map of function names to conversion configurations
74
+ * @param llmConfig - Shared LangChain LLM configuration for all agents
75
+ * @returns Map of function names to executable async functions
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * import { ChatOpenAI } from '@langchain/openai';
80
+ *
81
+ * const functions = convertLLMAnalyzersToFunctions(
82
+ * {
83
+ * generateName: {
84
+ * agent: nameGeneratorAgent,
85
+ * inputSchema: NameGeneratorInputSchema,
86
+ * outputSchema: NameSuggestionSchema,
87
+ * },
88
+ * generateHaiku: {
89
+ * agent: haikuGeneratorAgent,
90
+ * inputSchema: HaikuGeneratorInputSchema,
91
+ * outputSchema: HaikuSchema,
92
+ * },
93
+ * },
94
+ * {
95
+ * model: new ChatOpenAI({ modelName: 'gpt-4o-mini' }),
96
+ * temperature: 0.8,
97
+ * }
98
+ * );
99
+ *
100
+ * const name = await functions.generateName(catInput);
101
+ * const haiku = await functions.generateHaiku(catInput);
102
+ * ```
103
+ */
104
+ export function convertLLMAnalyzersToFunctions(configs, llmConfig) {
105
+ return batchConvert(configs, (config) => convertLLMAnalyzerToFunction(config.agent, config.inputSchema, config.outputSchema, llmConfig));
106
+ }
107
+ //# sourceMappingURL=llm-analyzer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm-analyzer.js","sourceRoot":"","sources":["../../src/adapters/llm-analyzer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAc,MAAM,mCAAmC,CAAC;AAK7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,4BAA4B,CAC1C,KAA6B,EAC7B,WAA8B,EAC9B,YAAgC,EAChC,SAA6B;IAE7B,oDAAoD;IACpD,MAAM,OAAO,GAAG,KAAK,EAAE,MAAc,EAAmB,EAAE;QACxD,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACtD,OAAO,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACrC,CAAC,CAAC;IAEF,0BAA0B;IAC1B,OAAO,KAAK,EAAE,KAAa,EAAoB,EAAE;QAC/C,iBAAiB;QACjB,MAAM,cAAc,GAAG,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAEhD,0CAA0C;QAC1C,IAAI,SAAiB,CAAC;QACtB,IAAI,WAAW,IAAI,SAAS,CAAC,KAAK,IAAI,OAAO,SAAS,CAAC,KAAK,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;YACpF,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC;QACxC,CAAC;aAAM,IAAI,OAAO,IAAI,SAAS,CAAC,KAAK,IAAI,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YACnF,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC;QACpC,CAAC;aAAM,CAAC;YACN,SAAS,GAAG,SAAS,CAAC;QACxB,CAAC;QAED,4DAA4D;QAC5D,MAAM,OAAO,GAAG;YACd,QAAQ,EAAE,KAAK;YACf,KAAK,EAAE,SAAS;YAChB,WAAW,EAAE,SAAS,CAAC,WAAW,IAAI,GAAG;YACzC,OAAO;SACR,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;QAE5D,kBAAkB;QAClB,OAAO,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,8BAA8B,CAC5C,OAAqC,EACrC,SAA6B;IAE7B,OAAO,YAAY,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CACtC,4BAA4B,CAC1B,MAAM,CAAC,KAAgC,EACvC,MAAM,CAAC,WAAW,EAClB,MAAM,CAAC,YAAY,EACnB,SAAS,CACV,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,76 @@
1
+ import { DynamicStructuredTool } from '@langchain/core/tools';
2
+ import { type PureFunctionAgent, type ToolConversionConfigs } from '@vibe-agent-toolkit/agent-runtime';
3
+ import type { z } from 'zod';
4
+ /**
5
+ * Converts a VAT Pure Function agent to a LangChain DynamicStructuredTool
6
+ *
7
+ * @param agent - The VAT pure function agent to convert
8
+ * @param inputSchema - Zod schema for validating inputs
9
+ * @param outputSchema - Zod schema for validating outputs
10
+ * @returns LangChain tool with metadata
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { ChatOpenAI } from '@langchain/openai';
15
+ * import { haikuValidatorAgent } from '@vibe-agent-toolkit/vat-example-cat-agents';
16
+ * import { convertPureFunctionToTool } from '@vibe-agent-toolkit/runtime-langchain';
17
+ *
18
+ * const tool = convertPureFunctionToTool(
19
+ * haikuValidatorAgent,
20
+ * HaikuSchema,
21
+ * HaikuValidationResultSchema
22
+ * );
23
+ *
24
+ * // Use with LangChain agent
25
+ * const llm = new ChatOpenAI({ model: 'gpt-4' });
26
+ * const agent = createToolCallingAgent({ llm, tools: [tool.tool] });
27
+ * ```
28
+ */
29
+ export declare function convertPureFunctionToTool<TInput, TOutput>(agent: PureFunctionAgent<TInput, TOutput>, inputSchema: z.ZodType<TInput>, outputSchema: z.ZodType<TOutput>): {
30
+ tool: DynamicStructuredTool;
31
+ metadata: {
32
+ name: string;
33
+ description: string;
34
+ version: string;
35
+ archetype: string;
36
+ };
37
+ inputSchema: z.ZodType<TInput>;
38
+ outputSchema: z.ZodType<TOutput>;
39
+ };
40
+ /**
41
+ * Batch converts multiple VAT Pure Function agents to LangChain tools
42
+ *
43
+ * @param configs - Map of tool names to conversion configurations
44
+ * @returns Map of tool names to LangChain DynamicStructuredTools
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * const tools = convertPureFunctionsToTools({
49
+ * validateHaiku: {
50
+ * agent: haikuValidatorAgent,
51
+ * inputSchema: HaikuSchema,
52
+ * outputSchema: HaikuValidationResultSchema,
53
+ * },
54
+ * validateName: {
55
+ * agent: nameValidatorAgent,
56
+ * inputSchema: NameSchema,
57
+ * outputSchema: NameValidationResultSchema,
58
+ * },
59
+ * });
60
+ *
61
+ * // Use all tools with LangChain agent
62
+ * const llm = new ChatOpenAI({ model: 'gpt-4' });
63
+ * const toolArray = Object.values(tools).map(t => t.tool);
64
+ * const agent = createToolCallingAgent({ llm, tools: toolArray });
65
+ * ```
66
+ */
67
+ export declare function convertPureFunctionsToTools(configs: ToolConversionConfigs): Record<string, {
68
+ tool: DynamicStructuredTool;
69
+ metadata: {
70
+ name: string;
71
+ description: string;
72
+ version: string;
73
+ archetype: string;
74
+ };
75
+ }>;
76
+ //# sourceMappingURL=pure-function.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pure-function.d.ts","sourceRoot":"","sources":["../../src/adapters/pure-function.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC3B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,OAAO,EACvD,KAAK,EAAE,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,EACzC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAC9B,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,GAC/B;IACD,IAAI,EAAE,qBAAqB,CAAC;IAC5B,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/B,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;CAClC,CAgCA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,qBAAqB,GAC7B,MAAM,CACP,MAAM,EACN;IACE,IAAI,EAAE,qBAAqB,CAAC;IAC5B,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CACrF,CACF,CASA"}
@@ -0,0 +1,90 @@
1
+ import { DynamicStructuredTool } from '@langchain/core/tools';
2
+ import { batchConvert, } from '@vibe-agent-toolkit/agent-runtime';
3
+ /**
4
+ * Converts a VAT Pure Function agent to a LangChain DynamicStructuredTool
5
+ *
6
+ * @param agent - The VAT pure function agent to convert
7
+ * @param inputSchema - Zod schema for validating inputs
8
+ * @param outputSchema - Zod schema for validating outputs
9
+ * @returns LangChain tool with metadata
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { ChatOpenAI } from '@langchain/openai';
14
+ * import { haikuValidatorAgent } from '@vibe-agent-toolkit/vat-example-cat-agents';
15
+ * import { convertPureFunctionToTool } from '@vibe-agent-toolkit/runtime-langchain';
16
+ *
17
+ * const tool = convertPureFunctionToTool(
18
+ * haikuValidatorAgent,
19
+ * HaikuSchema,
20
+ * HaikuValidationResultSchema
21
+ * );
22
+ *
23
+ * // Use with LangChain agent
24
+ * const llm = new ChatOpenAI({ model: 'gpt-4' });
25
+ * const agent = createToolCallingAgent({ llm, tools: [tool.tool] });
26
+ * ```
27
+ */
28
+ export function convertPureFunctionToTool(agent, inputSchema, outputSchema) {
29
+ const { manifest } = agent;
30
+ // Create LangChain DynamicStructuredTool
31
+ const tool = new DynamicStructuredTool({
32
+ name: manifest.name,
33
+ description: manifest.description,
34
+ schema: inputSchema,
35
+ func: async (input) => {
36
+ // Execute the agent - returns output directly (unwrapped)
37
+ // The agent's execute wrapper validates input/output schemas and throws on error
38
+ const output = agent.execute(input);
39
+ // Validate the output with schema (redundant but explicit)
40
+ const validated = outputSchema.parse(output);
41
+ // LangChain tools must return string or object that can be JSON stringified
42
+ return JSON.stringify(validated);
43
+ },
44
+ });
45
+ return {
46
+ tool,
47
+ metadata: {
48
+ name: manifest.name,
49
+ description: manifest.description,
50
+ version: manifest.version,
51
+ archetype: manifest.archetype,
52
+ },
53
+ inputSchema,
54
+ outputSchema,
55
+ };
56
+ }
57
+ /**
58
+ * Batch converts multiple VAT Pure Function agents to LangChain tools
59
+ *
60
+ * @param configs - Map of tool names to conversion configurations
61
+ * @returns Map of tool names to LangChain DynamicStructuredTools
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const tools = convertPureFunctionsToTools({
66
+ * validateHaiku: {
67
+ * agent: haikuValidatorAgent,
68
+ * inputSchema: HaikuSchema,
69
+ * outputSchema: HaikuValidationResultSchema,
70
+ * },
71
+ * validateName: {
72
+ * agent: nameValidatorAgent,
73
+ * inputSchema: NameSchema,
74
+ * outputSchema: NameValidationResultSchema,
75
+ * },
76
+ * });
77
+ *
78
+ * // Use all tools with LangChain agent
79
+ * const llm = new ChatOpenAI({ model: 'gpt-4' });
80
+ * const toolArray = Object.values(tools).map(t => t.tool);
81
+ * const agent = createToolCallingAgent({ llm, tools: toolArray });
82
+ * ```
83
+ */
84
+ export function convertPureFunctionsToTools(configs) {
85
+ return batchConvert(configs, (config) => {
86
+ const { tool, metadata } = convertPureFunctionToTool(config.agent, config.inputSchema, config.outputSchema);
87
+ return { tool, metadata };
88
+ });
89
+ }
90
+ //# sourceMappingURL=pure-function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pure-function.js","sourceRoot":"","sources":["../../src/adapters/pure-function.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EACL,YAAY,GAGb,MAAM,mCAAmC,CAAC;AAG3C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,yBAAyB,CACvC,KAAyC,EACzC,WAA8B,EAC9B,YAAgC;IAYhC,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAE3B,yCAAyC;IACzC,MAAM,IAAI,GAAG,IAAI,qBAAqB,CAAC;QACrC,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,MAAM,EAAE,WAAW;QACnB,IAAI,EAAE,KAAK,EAAE,KAAa,EAAE,EAAE;YAC5B,0DAA0D;YAC1D,iFAAiF;YACjF,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAEpC,2DAA2D;YAC3D,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAE7C,4EAA4E;YAC5E,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QACnC,CAAC;KACF,CAAC,CAAC;IAEH,OAAO;QACL,IAAI;QACJ,QAAQ,EAAE;YACR,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,WAAW,EAAE,QAAQ,CAAC,WAAW;YACjC,OAAO,EAAE,QAAQ,CAAC,OAAO;YACzB,SAAS,EAAE,QAAQ,CAAC,SAAS;SAC9B;QACD,WAAW;QACX,YAAY;KACb,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,2BAA2B,CACzC,OAA8B;IAQ9B,OAAO,YAAY,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE;QACtC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,yBAAyB,CAClD,MAAM,CAAC,KAA4C,EACnD,MAAM,CAAC,WAAW,EAClB,MAAM,CAAC,YAAY,CACpB,CAAC;QACF,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './adapters/pure-function.js';
2
+ export * from './adapters/llm-analyzer.js';
3
+ export * from './adapters/conversational-assistant.js';
4
+ export * from './types.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC;AAGvD,cAAc,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ // Adapters
2
+ export * from './adapters/pure-function.js';
3
+ export * from './adapters/llm-analyzer.js';
4
+ export * from './adapters/conversational-assistant.js';
5
+ // Types
6
+ export * from './types.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,WAAW;AACX,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC;AAEvD,QAAQ;AACR,cAAc,YAAY,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
2
+ /**
3
+ * LangChain LLM configuration for VAT agents
4
+ */
5
+ export interface LangChainLLMConfig {
6
+ /**
7
+ * LangChain chat model instance (e.g., ChatOpenAI, ChatAnthropic)
8
+ */
9
+ model: BaseChatModel;
10
+ /**
11
+ * Temperature for text generation (0-1)
12
+ * Higher values make output more random, lower values more deterministic
13
+ */
14
+ temperature?: number;
15
+ /**
16
+ * Maximum tokens to generate
17
+ */
18
+ maxTokens?: number;
19
+ /**
20
+ * Additional model-specific settings
21
+ */
22
+ additionalSettings?: Record<string, unknown>;
23
+ }
24
+ export type { LLMAnalyzerConversionConfig, LLMAnalyzerConversionConfigs, ToolConversionConfig, ToolConversionConfigs, } from '@vibe-agent-toolkit/agent-runtime';
25
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAEjF;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,KAAK,EAAE,aAAa,CAAC;IAErB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC9C;AAGD,YAAY,EACV,2BAA2B,EAC3B,4BAA4B,EAC5B,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,mCAAmC,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@vibe-agent-toolkit/runtime-langchain",
3
+ "version": "0.1.2-rc.4",
4
+ "description": "LangChain.js runtime adapter for VAT agents",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "default": "./dist/index.js"
10
+ }
11
+ },
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "demo": "tsx examples/demo.ts",
18
+ "test": "vitest run",
19
+ "test:watch": "vitest",
20
+ "test:llm-regression": "RUN_LLM_TESTS=true bun test test/llm-regression.test.ts",
21
+ "typecheck": "tsc --noEmit"
22
+ },
23
+ "dependencies": {
24
+ "@langchain/core": "^0.3.29",
25
+ "@vibe-agent-toolkit/agent-runtime": "0.1.2-rc.4",
26
+ "langchain": "^0.3.11",
27
+ "zod": "^3.24.1",
28
+ "zod-to-json-schema": "^3.24.1"
29
+ },
30
+ "devDependencies": {
31
+ "@langchain/anthropic": "^0.3.11",
32
+ "@langchain/openai": "^0.3.16",
33
+ "@types/node": "^22.10.5",
34
+ "@vibe-agent-toolkit/dev-tools": "0.1.2-rc.4",
35
+ "@vibe-agent-toolkit/vat-example-cat-agents": "0.1.2-rc.4",
36
+ "tsx": "^4.19.2",
37
+ "typescript": "^5.7.3",
38
+ "vitest": "^2.1.8"
39
+ },
40
+ "keywords": [
41
+ "ai-agent",
42
+ "langchain",
43
+ "vibe-agent-toolkit",
44
+ "runtime-adapter"
45
+ ],
46
+ "author": "Jeff Dutton",
47
+ "license": "MIT",
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "https://github.com/jdutton/vibe-agent-toolkit.git",
51
+ "directory": "packages/runtime-langchain"
52
+ }
53
+ }