@@ -12,10 +12,12 @@ import (
1212 "github.com/spf13/viper"
1313 "golang.org/x/sync/errgroup"
1414
15+ "github.com/ai-flowx/flowx/agent"
1516 "github.com/ai-flowx/flowx/config"
1617 "github.com/ai-flowx/flowx/flow"
1718 "github.com/ai-flowx/flowx/gpt"
1819 "github.com/ai-flowx/flowx/memory"
20+ "github.com/ai-flowx/flowx/prompt"
1921 "github.com/ai-flowx/flowx/store"
2022 "github.com/ai-flowx/flowx/tool"
2123)
@@ -46,6 +48,11 @@ var rootCmd = &cobra.Command{
4648 _ , _ = fmt .Fprintln (os .Stderr , err .Error ())
4749 os .Exit (1 )
4850 }
51+ p , err := initPrompt (ctx , & cfg )
52+ if err != nil {
53+ _ , _ = fmt .Fprintln (os .Stderr , err .Error ())
54+ os .Exit (1 )
55+ }
4956 s , err := initStore (ctx , & cfg )
5057 if err != nil {
5158 _ , _ = fmt .Fprintln (os .Stderr , err .Error ())
@@ -61,7 +68,12 @@ var rootCmd = &cobra.Command{
6168 _ , _ = fmt .Fprintln (os .Stderr , err .Error ())
6269 os .Exit (1 )
6370 }
64- f , err := initFlow (ctx , & cfg , g , m , t )
71+ a , err := initAgent (ctx , & cfg , g , p , t )
72+ if err != nil {
73+ _ , _ = fmt .Fprintln (os .Stderr , err .Error ())
74+ os .Exit (1 )
75+ }
76+ f , err := initFlow (ctx , & cfg , g , m , t , a )
6577 if err != nil {
6678 _ , _ = fmt .Fprintln (os .Stderr , err .Error ())
6779 os .Exit (1 )
@@ -116,6 +128,15 @@ func initGpt(ctx context.Context, cfg *config.Config) (gpt.Gpt, error) {
116128 return gpt .New (ctx , c ), nil
117129}
118130
131+ func initPrompt (ctx context.Context , _ * config.Config ) (prompt.Prompt , error ) {
132+ c := prompt .DefaultConfig ()
133+ if c == nil {
134+ return nil , errors .New ("failed to config\n " )
135+ }
136+
137+ return prompt .New (ctx , c ), nil
138+ }
139+
119140func initStore (ctx context.Context , cfg * config.Config ) (store.Store , error ) {
120141 c := store .DefaultConfig ()
121142 if c == nil {
@@ -161,7 +182,21 @@ func initTool(ctx context.Context, cfg *config.Config, _gpt gpt.Gpt) (tool.Tool,
161182 return tool .New (ctx , c ), nil
162183}
163184
164- func initFlow (ctx context.Context , cfg * config.Config , _gpt gpt.Gpt , mem memory.Memory , _tool tool.Tool ) (flow.Flow , error ) {
185+ func initAgent (ctx context.Context , _ * config.Config , _gpt gpt.Gpt , _prompt prompt.Prompt , _tool tool.Tool ) (agent.Agent , error ) {
186+ c := agent .DefaultConfig ()
187+ if c == nil {
188+ return nil , errors .New ("failed to config\n " )
189+ }
190+
191+ c .Gpt = _gpt
192+ c .Prompt = _prompt
193+ c .Tool = _tool
194+
195+ return agent .New (ctx , c ), nil
196+ }
197+
198+ func initFlow (ctx context.Context , cfg * config.Config , _gpt gpt.Gpt , mem memory.Memory ,
199+ _tool tool.Tool , _agent agent.Agent ) (flow.Flow , error ) {
165200 c := flow .DefaultConfig ()
166201 if c == nil {
167202 return nil , errors .New ("failed to config\n " )
@@ -172,6 +207,7 @@ func initFlow(ctx context.Context, cfg *config.Config, _gpt gpt.Gpt, mem memory.
172207 c .Gpt = _gpt
173208 c .Memory = mem
174209 c .Tool = _tool
210+ c .Agent = _agent
175211
176212 return flow .New (ctx , c ), nil
177213}
0 commit comments