|
6 | 6 | scenarios (agentic-chat, tool-rendering, hitl, gen-ui-tool-based) through |
7 | 7 | a single endpoint since LlamaIndex's get_ag_ui_workflow_router builds |
8 | 8 | the full AG-UI protocol surface automatically. |
| 9 | +
|
| 10 | +NOTE: Uses FixedAGUIChatWorkflow from hitl_in_chat_agent to fix three |
| 11 | +upstream library bugs (duplicate tool-call rendering, missing |
| 12 | +parent_message_id, and incorrect tool-result message roles). See |
| 13 | +hitl_in_chat_agent.py module docstring for details. |
9 | 14 | """ |
10 | 15 |
|
11 | 16 | import json |
|
15 | 20 | from llama_index.llms.openai import OpenAI |
16 | 21 | from llama_index.protocols.ag_ui.router import get_ag_ui_workflow_router |
17 | 22 |
|
| 23 | +from agents.hitl_in_chat_agent import FixedAGUIChatWorkflow |
| 24 | + |
18 | 25 | # Import shared tool implementations |
19 | 26 | from tools import ( |
20 | 27 | get_weather_impl, |
@@ -166,29 +173,38 @@ async def generate_a2ui( |
166 | 173 | if os.environ.get("OPENAI_BASE_URL"): |
167 | 174 | _openai_kwargs["api_base"] = os.environ["OPENAI_BASE_URL"] |
168 | 175 |
|
| 176 | +_AGENT_SYSTEM_PROMPT = ( |
| 177 | + "You are a polished, professional demo assistant for CopilotKit. " |
| 178 | + "Keep responses brief and clear -- 1 to 2 sentences max.\n\n" |
| 179 | + "You can:\n" |
| 180 | + "- Chat naturally with the user\n" |
| 181 | + "- Change the UI background when asked (via frontend tool)\n" |
| 182 | + "- Query data and render charts (via query_data tool)\n" |
| 183 | + "- Get weather information (via get_weather tool)\n" |
| 184 | + "- Schedule meetings with the user (via schedule_meeting tool)\n" |
| 185 | + "- Manage sales pipeline todos (via manage_sales_todos / get_sales_todos tools)\n" |
| 186 | + "- Search flights and display rich A2UI cards (via search_flights tool)\n" |
| 187 | + "- Generate dynamic A2UI dashboards from conversation context (via generate_a2ui tool)\n" |
| 188 | + "- Generate step-by-step plans for user review (human-in-the-loop)\n" |
| 189 | + "- Book calls with people (via book_call frontend tool)\n" |
| 190 | + "When asked about weather, always use the get_weather tool. " |
| 191 | + "When asked about financial data or charts, use query_data first. " |
| 192 | + "When asked to book a call, use the book_call tool with topic and name." |
| 193 | +) |
| 194 | + |
| 195 | + |
| 196 | +async def _agent_workflow_factory(): |
| 197 | + return FixedAGUIChatWorkflow( |
| 198 | + llm=OpenAI(model="gpt-4.1", **_openai_kwargs), |
| 199 | + frontend_tools=[change_background, generate_haiku, generate_task_steps, book_call], |
| 200 | + backend_tools=[get_weather, query_data, manage_sales_todos, get_sales_todos_tool, schedule_meeting, search_flights, generate_a2ui], |
| 201 | + system_prompt=_AGENT_SYSTEM_PROMPT, |
| 202 | + initial_state={ |
| 203 | + "todos": [], |
| 204 | + }, |
| 205 | + ) |
| 206 | + |
| 207 | + |
169 | 208 | agent_router = get_ag_ui_workflow_router( |
170 | | - llm=OpenAI(model="gpt-4.1", **_openai_kwargs), |
171 | | - frontend_tools=[change_background, generate_haiku, generate_task_steps, book_call], |
172 | | - backend_tools=[get_weather, query_data, manage_sales_todos, get_sales_todos_tool, schedule_meeting, search_flights, generate_a2ui], |
173 | | - system_prompt=( |
174 | | - "You are a polished, professional demo assistant for CopilotKit. " |
175 | | - "Keep responses brief and clear -- 1 to 2 sentences max.\n\n" |
176 | | - "You can:\n" |
177 | | - "- Chat naturally with the user\n" |
178 | | - "- Change the UI background when asked (via frontend tool)\n" |
179 | | - "- Query data and render charts (via query_data tool)\n" |
180 | | - "- Get weather information (via get_weather tool)\n" |
181 | | - "- Schedule meetings with the user (via schedule_meeting tool)\n" |
182 | | - "- Manage sales pipeline todos (via manage_sales_todos / get_sales_todos tools)\n" |
183 | | - "- Search flights and display rich A2UI cards (via search_flights tool)\n" |
184 | | - "- Generate dynamic A2UI dashboards from conversation context (via generate_a2ui tool)\n" |
185 | | - "- Generate step-by-step plans for user review (human-in-the-loop)\n" |
186 | | - "- Book calls with people (via book_call frontend tool)\n" |
187 | | - "When asked about weather, always use the get_weather tool. " |
188 | | - "When asked about financial data or charts, use query_data first. " |
189 | | - "When asked to book a call, use the book_call tool with topic and name." |
190 | | - ), |
191 | | - initial_state={ |
192 | | - "todos": [], |
193 | | - }, |
| 209 | + workflow_factory=_agent_workflow_factory, |
194 | 210 | ) |
0 commit comments