33from app .index import get_index
44from llama_index .core .agent .workflow import AgentWorkflow
55from llama_index .core .settings import Settings
6- from llama_index .llms .openai import OpenAI
76from llama_index .server .api .models import ChatRequest
87from llama_index .server .tools .index import get_query_engine_tool
8+ from llama_index .server .tools .index .citation import (
9+ CITATION_SYSTEM_PROMPT ,
10+ enable_citation ,
11+ )
912
1013
1114def create_workflow (chat_request : Optional [ChatRequest ] = None ) -> AgentWorkflow :
@@ -14,9 +17,16 @@ def create_workflow(chat_request: Optional[ChatRequest] = None) -> AgentWorkflow
1417 raise RuntimeError (
1518 "Index not found! Please run `uv run generate` to index the data first."
1619 )
17- query_tool = get_query_engine_tool (index = index )
20+ # Create a query tool with citations enabled
21+ query_tool = enable_citation (get_query_engine_tool (index = index ))
22+
23+ # Define the system prompt for the agent
24+ # Append the citation system prompt to the system prompt
25+ system_prompt = """You are a helpful assistant"""
26+ system_prompt += CITATION_SYSTEM_PROMPT
27+
1828 return AgentWorkflow .from_tools_or_functions (
1929 tools_or_functions = [query_tool ],
20- llm = Settings .llm or OpenAI ( model = "gpt-4o-mini" ) ,
21- system_prompt = "You are a helpful assistant." ,
30+ llm = Settings .llm ,
31+ system_prompt = system_prompt ,
2232 )
0 commit comments