Skip to content

Commit c1775f3

Browse files
committed
fix(showcase): apply FixedAGUIChatWorkflow to all llamaindex HITL agents
PR CopilotKit#4464 only applied the upstream bug fixes to hitl_in_chat_agent.py. The same three bugs (duplicate tool-call rendering, missing parent_message_id, incorrect tool-result message roles) affect the hitl_in_app_agent and the main agent router. Switch both to use FixedAGUIChatWorkflow via workflow_factory so all llamaindex demo features get the corrected AG-UI event stream.
1 parent bafd9f9 commit c1775f3

2 files changed

Lines changed: 58 additions & 29 deletions

File tree

showcase/integrations/llamaindex/src/agents/agent.py

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
scenarios (agentic-chat, tool-rendering, hitl, gen-ui-tool-based) through
77
a single endpoint since LlamaIndex's get_ag_ui_workflow_router builds
88
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.
914
"""
1015

1116
import json
@@ -15,6 +20,8 @@
1520
from llama_index.llms.openai import OpenAI
1621
from llama_index.protocols.ag_ui.router import get_ag_ui_workflow_router
1722

23+
from agents.hitl_in_chat_agent import FixedAGUIChatWorkflow
24+
1825
# Import shared tool implementations
1926
from tools import (
2027
get_weather_impl,
@@ -166,29 +173,38 @@ async def generate_a2ui(
166173
if os.environ.get("OPENAI_BASE_URL"):
167174
_openai_kwargs["api_base"] = os.environ["OPENAI_BASE_URL"]
168175

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+
169208
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,
194210
)

showcase/integrations/llamaindex/src/agents/hitl_in_app_agent.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
request.
1111
1212
Mirrors `langgraph-python/src/agents/hitl_in_app.py`.
13+
14+
NOTE: Uses FixedAGUIChatWorkflow from hitl_in_chat_agent to fix three
15+
upstream library bugs (duplicate tool-call rendering, missing
16+
parent_message_id, and incorrect tool-result message roles). See
17+
hitl_in_chat_agent.py module docstring for details.
1318
"""
1419

1520
from __future__ import annotations
@@ -19,6 +24,8 @@
1924
from llama_index.llms.openai import OpenAI
2025
from llama_index.protocols.ag_ui.router import get_ag_ui_workflow_router
2126

27+
from agents.hitl_in_chat_agent import FixedAGUIChatWorkflow
28+
2229
_openai_kwargs = {}
2330
if os.environ.get("OPENAI_BASE_URL"):
2431
_openai_kwargs["api_base"] = os.environ["OPENAI_BASE_URL"]
@@ -54,10 +61,16 @@
5461
)
5562

5663

64+
async def _workflow_factory():
65+
return FixedAGUIChatWorkflow(
66+
llm=OpenAI(model="gpt-4o-mini", **_openai_kwargs),
67+
frontend_tools=[],
68+
backend_tools=[],
69+
system_prompt=SYSTEM_PROMPT,
70+
initial_state={},
71+
)
72+
73+
5774
hitl_in_app_router = get_ag_ui_workflow_router(
58-
llm=OpenAI(model="gpt-4o-mini", **_openai_kwargs),
59-
frontend_tools=[],
60-
backend_tools=[],
61-
system_prompt=SYSTEM_PROMPT,
62-
initial_state={},
75+
workflow_factory=_workflow_factory,
6376
)

0 commit comments

Comments
 (0)