@@ -4,7 +4,7 @@ import { Memory } from "@mastra/memory";
4
4
import { LibSQLStore } from "@mastra/libsql" ;
5
5
import { DynamoDBStore } from "@mastra/dynamodb" ;
6
6
7
- import { Mastra } from "@mastra/core" ;
7
+ import { createStep , createWorkflow , Mastra } from "@mastra/core" ;
8
8
import { createTool } from "@mastra/core" ;
9
9
import { z } from "zod" ;
10
10
@@ -13,17 +13,63 @@ import { z } from "zod";
13
13
function getStorage ( ) : LibSQLStore | DynamoDBStore {
14
14
if ( process . env . DYNAMODB_TABLE_NAME ) {
15
15
return new DynamoDBStore ( {
16
- name : "dynamodb" ,
17
- config : {
18
- tableName : process . env . DYNAMODB_TABLE_NAME
19
- } ,
20
- } ) ;
16
+ name : "dynamodb" ,
17
+ config : {
18
+ tableName : process . env . DYNAMODB_TABLE_NAME
19
+ } ,
20
+ } ) ;
21
21
} else {
22
22
return new LibSQLStore ( { url : "file::memory:" } ) ;
23
23
}
24
24
}
25
25
26
+ export const weatherInfo = createTool ( {
27
+ id : "Get Weather Information" ,
28
+ description : `Fetches the current weather information for a given city` ,
29
+ inputSchema : z . object ( {
30
+ city : z . string ( ) ,
31
+ } ) ,
32
+ outputSchema : z . object ( {
33
+ text : z . string ( ) ,
34
+ } ) ,
35
+ execute : async ( { writer } ) => {
36
+ const step = createStep ( {
37
+ id : "weather-info" ,
38
+ inputSchema : z . object ( { } ) ,
39
+ outputSchema : z . object ( {
40
+ text : z . string ( ) ,
41
+ } ) ,
42
+ execute : async ( ) => {
43
+ return {
44
+ text : "70 degrees"
45
+ }
46
+ }
47
+ } )
48
+
49
+ const workflow = createWorkflow ( {
50
+ id : "weather-info" ,
51
+ inputSchema : z . object ( { } ) ,
52
+ outputSchema : z . object ( { } ) ,
53
+ steps : [ step ] ,
54
+ } ) . then ( step ) . commit ( ) ;
26
55
56
+ const run = await workflow . createRunAsync ( )
57
+
58
+ const stream = run . streamVNext ( )
59
+
60
+ for await ( const chunk of stream ) {
61
+ console . log ( 'WORKFLOW CHUNK' , chunk )
62
+ if ( 'payload' in chunk ) {
63
+ await writer ! . write ( {
64
+ type : `${ chunk . from } -${ chunk . type } ` ,
65
+ payload : chunk . payload ,
66
+ } )
67
+ }
68
+ }
69
+
70
+ return await stream . result as any ;
71
+ } ,
72
+ } ) ;
27
73
28
74
export const mastra = new Mastra ( {
29
75
agents : {
@@ -38,10 +84,11 @@ export const mastra = new Mastra({
38
84
- If giving a location with multiple parts (e.g. "New York, NY"), use the most relevant part (e.g. "New York")
39
85
- Include relevant details like humidity, wind conditions, and precipitation
40
86
- Keep responses concise but informative
41
-
42
- Use the weatherTool to fetch current weather data.
43
- ` ,
87
+ ` ,
44
88
model : openai ( "gpt-4o" ) ,
89
+ tools : {
90
+ weatherInfo
91
+ } ,
45
92
memory : new Memory ( {
46
93
storage : getStorage ( ) ,
47
94
options : {
0 commit comments