11package com .copilotkit .showcase .springai ;
22
3- import com .agui .spring .ai .SpringAIAgent ;
43import com .copilotkit .showcase .springai .model .SalesTodo ;
54import com .copilotkit .showcase .springai .tools .WeatherRequest ;
65import com .copilotkit .showcase .springai .tools .WeatherTool ;
1817import org .springframework .context .annotation .Bean ;
1918import org .springframework .context .annotation .Configuration ;
2019
21- import java .util .ArrayList ;
2220import java .util .List ;
2321
2422@ Configuration
@@ -32,82 +30,86 @@ public ChatMemory chatMemory() {
3230 .build ();
3331 }
3432
33+ /**
34+ * Main agentic chat agent. Uses {@link StreamingToolAgent} which streams
35+ * text via {@code .stream()} for real-time delivery and falls back to
36+ * {@code .call()} when tool execution is needed. This replaces the stock
37+ * AG-UI {@code SpringAIAgent} which used {@code .stream()} exclusively
38+ * and never executed tool callbacks (Spring AI streaming does not
39+ * auto-execute tools).
40+ */
3541 @ Bean
36- public SpringAIAgent agent (ChatModel chatModel , ChatMemory chatMemory ) {
42+ public StreamingToolAgent agent (ChatModel chatModel , ChatMemory chatMemory ) {
3743 // Shared mutable todos list between get/manage tools
3844 var salesTodosTool = new GetSalesTodosTool ();
3945 List <SalesTodo > sharedTodos = salesTodosTool .getTodos ();
4046 var manageSalesTodosTool = new ManageSalesTodosTool (sharedTodos );
4147
42- try {
43- return SpringAIAgent .builder ()
44- .agentId ("agentic_chat" )
45- .chatModel (chatModel )
46- .chatMemory (chatMemory )
47- .systemMessage ("""
48- You are a helpful assistant for the CopilotKit showcase.
49- You can check the weather using the get_weather tool.
50- You can query financial/business data using the query_data tool.
51- You can schedule meetings using the schedule_meeting tool.
52- You can manage the sales pipeline using get_sales_todos and manage_sales_todos tools.
53- You can search for flights using the search_flights tool.
54- You can generate dynamic UI using the generate_a2ui tool.
55- For other tools (change_background, generate_haiku, generate_task_steps,
56- pieChart, barChart, scheduleTime, toggleTheme),
57- these are provided by the frontend — use them when relevant to the user's request.
58- When asked to plan or create steps, use the generate_task_steps tool.
59- When asked about weather, use the get_weather tool.
60- When asked about data, charts, or analytics, use the query_data tool.
61- When asked to schedule a meeting, use the schedule_meeting tool.
62- When asked about the sales pipeline or deals, use get_sales_todos first.
63- When asked to search for flights, use the search_flights tool.
64- Keep responses concise and helpful.
65- """ )
66- .toolCallback (
67- FunctionToolCallback .builder ("get_weather" , new WeatherTool ())
68- .description ("Get current weather for a location" )
69- .inputType (WeatherRequest .class )
70- .build ()
71- )
72- .toolCallback (
73- FunctionToolCallback .builder ("query_data" , new QueryDataTool ())
74- .description ("Query financial data for charts and analytics" )
75- .inputType (QueryDataTool .Request .class )
76- .build ()
77- )
78- .toolCallback (
79- FunctionToolCallback .builder ("schedule_meeting" , new ScheduleMeetingTool ())
80- .description ("Schedule a meeting with a given reason and duration" )
81- .inputType (ScheduleMeetingTool .Request .class )
82- .build ()
83- )
84- .toolCallback (
85- FunctionToolCallback .builder ("get_sales_todos" , salesTodosTool )
86- .description ("Get the current sales pipeline todos" )
87- .inputType (GetSalesTodosTool .Request .class )
88- .build ()
89- )
90- .toolCallback (
91- FunctionToolCallback .builder ("manage_sales_todos" , manageSalesTodosTool )
92- .description ("Update the sales pipeline with a new set of todos" )
93- .inputType (ManageSalesTodosTool .Request .class )
94- .build ()
95- )
96- .toolCallback (
97- FunctionToolCallback .builder ("search_flights" , new SearchFlightsTool ())
98- .description ("Search for available flights between two cities" )
99- .inputType (SearchFlightsTool .Request .class )
100- .build ()
101- )
102- .toolCallback (
103- FunctionToolCallback .builder ("generate_a2ui" , new GenerateA2uiTool (chatModel ))
104- .description ("Generate dynamic A2UI components using a secondary LLM call" )
105- .inputType (GenerateA2uiTool .Request .class )
106- .build ()
107- )
108- .build ();
109- } catch (Exception e ) {
110- throw new RuntimeException ("Failed to build SpringAIAgent" , e );
111- }
48+ return StreamingToolAgent .builder ()
49+ .agentId ("agentic_chat" )
50+ .chatModel (chatModel )
51+ .chatMemory (chatMemory )
52+ .systemMessage ("""
53+ You are a helpful assistant for the CopilotKit showcase.
54+ You can check the weather using the get_weather tool.
55+ You can query financial/business data using the query_data tool.
56+ You can schedule meetings using the schedule_meeting tool.
57+ You can manage the sales pipeline using get_sales_todos and manage_sales_todos tools.
58+ You can search for flights using the search_flights tool.
59+ You can generate dynamic UI using the generate_a2ui tool.
60+ For other tools (change_background, generate_haiku, generate_task_steps,
61+ pieChart, barChart, scheduleTime, toggleTheme),
62+ these are provided by the frontend — use them when relevant to the user's request.
63+ When asked to plan or create steps, use the generate_task_steps tool.
64+ When asked about weather, use the get_weather tool.
65+ When asked about data, charts, or analytics, use the query_data tool.
66+ When asked to schedule a meeting, use the schedule_meeting tool.
67+ When asked about the sales pipeline or deals, use get_sales_todos first.
68+ When asked to search for flights, use the search_flights tool.
69+ Keep responses concise and helpful.
70+ """ )
71+ .toolCallback (
72+ FunctionToolCallback .builder ("get_weather" , new WeatherTool ())
73+ .description ("Get current weather for a location" )
74+ .inputType (WeatherRequest .class )
75+ .build ()
76+ )
77+ .toolCallback (
78+ FunctionToolCallback .builder ("query_data" , new QueryDataTool ())
79+ .description ("Query financial data for charts and analytics" )
80+ .inputType (QueryDataTool .Request .class )
81+ .build ()
82+ )
83+ .toolCallback (
84+ FunctionToolCallback .builder ("schedule_meeting" , new ScheduleMeetingTool ())
85+ .description ("Schedule a meeting with a given reason and duration" )
86+ .inputType (ScheduleMeetingTool .Request .class )
87+ .build ()
88+ )
89+ .toolCallback (
90+ FunctionToolCallback .builder ("get_sales_todos" , salesTodosTool )
91+ .description ("Get the current sales pipeline todos" )
92+ .inputType (GetSalesTodosTool .Request .class )
93+ .build ()
94+ )
95+ .toolCallback (
96+ FunctionToolCallback .builder ("manage_sales_todos" , manageSalesTodosTool )
97+ .description ("Update the sales pipeline with a new set of todos" )
98+ .inputType (ManageSalesTodosTool .Request .class )
99+ .build ()
100+ )
101+ .toolCallback (
102+ FunctionToolCallback .builder ("search_flights" , new SearchFlightsTool ())
103+ .description ("Search for available flights between two cities" )
104+ .inputType (SearchFlightsTool .Request .class )
105+ .build ()
106+ )
107+ .toolCallback (
108+ FunctionToolCallback .builder ("generate_a2ui" , new GenerateA2uiTool (chatModel ))
109+ .description ("Generate dynamic A2UI components using a secondary LLM call" )
110+ .inputType (GenerateA2uiTool .Request .class )
111+ .build ()
112+ )
113+ .build ();
112114 }
113115}
0 commit comments