-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathworkflows.ts
More file actions
85 lines (77 loc) · 2.15 KB
/
workflows.ts
File metadata and controls
85 lines (77 loc) · 2.15 KB
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
// Test script for the simplified proxy approach
import 'dotenv/config';
import {Langbase} from 'langbase';
// Create Langbase instance
const langbase = new Langbase({
apiKey: process.env.LANGBASE_API_KEY!,
});
async function main() {
// Create a workflow with debug mode enabled
const workflow = langbase.workflow({
name: 'simplified-proxy-test',
debug: true, // Enable debug logging
});
try {
// STEP 1: Call langbase.agent.run but don't return its result directly
const step1Result = await workflow.step({
id: 'call-but-return-custom',
run: async () => {
// Return custom result instead
return {
customField: 'Custom result from simplified proxy',
timestamp: new Date().toISOString(),
};
},
});
// STEP 2: Return agent.run result directly
const step2Result = await workflow.step({
id: 'return-agent-run-directly',
run: async () => {
// Call Langbase API and return the result directly
return langbase.agent.run({
model: 'openai:gpt-4o-mini',
apiKey: process.env.OPENAI_API_KEY!,
instructions: 'Be brief and concise.',
input: 'What is 2+2?',
stream: false,
});
},
});
// STEP 3: Make multiple Langbase calls in one step
const step3Result = await workflow.step({
id: 'multiple-calls',
run: async () => {
// First call
const call1 = await langbase.agent.run({
model: 'openai:gpt-4o-mini',
apiKey: process.env.OPENAI_API_KEY!,
instructions: 'Be brief.',
input: 'First proxy test',
stream: false,
});
// Second call with different method
const call2 = await langbase.agent.run({
model: 'openai:gpt-4o-mini',
apiKey: process.env.OPENAI_API_KEY!,
instructions: 'Be brief.',
input: 'Second proxy test',
stream: false,
});
// Return combined result
return {
summary: 'Multiple calls completed with simplified proxy',
calls: 2,
firstOutput: call1.output,
secondOutput: call2.output,
};
},
});
} catch (error) {
console.error('❌ Workflow error:', error);
} finally {
// End the workflow to show trace report
workflow.end();
}
}
// Run the test
main().catch(console.error);