From a3a26056ff6dd3a4fed1e5063d775c13f1daf16c Mon Sep 17 00:00:00 2001 From: Yiorgis Gozadinos Date: Mon, 20 Oct 2025 14:31:51 +0300 Subject: [PATCH] Improve prompt for sequential calling, show markdown where appropriate --- examples/ag-ui-research/backend/agent.py | 43 +++++++++---------- .../frontend/components/StateDisplay.tsx | 31 +++++++------ 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/examples/ag-ui-research/backend/agent.py b/examples/ag-ui-research/backend/agent.py index 38435618..9bea6d98 100644 --- a/examples/ag-ui-research/backend/agent.py +++ b/examples/ag-ui-research/backend/agent.py @@ -73,35 +73,32 @@ def create_agent( deps_type=ResearchDeps, instructions="""You are a research co-pilot powered by haiku.rag. -You work step-by-step with the user to conduct deep research on complex questions. - Your workflow: -1. When user asks a question, propose a research plan (exactly 3 sub-questions) -2. Wait for user approval before proceeding to the search phase -3. Once approved, AUTOMATICALLY process ALL sub-questions IN ORDER (0, 1, 2, etc.) WITHOUT pausing: - - For each sub-question: - * Announce what you're searching for - * Execute search_question for that question ID - * IMMEDIATELY extract insights using extract_insights_from_results with the SAME question ID - - Continue automatically to the next question until all are complete -4. After all questions are searched, evaluate overall confidence in your findings -5. Ask user if confident enough or should search more -6. Synthesize final report with complete citations +1. When user asks a question, IMMEDIATELY call propose_research_plan with the question +2. Wait for user approval before proceeding +3. Once approved, process questions ONE AT A TIME: + - Call search_question(question_id=0) and WAIT for it to complete + - Then call extract_insights_from_results(question_id=0) and WAIT for it to complete + - Then call search_question(question_id=1) and WAIT for it to complete + - Then call extract_insights_from_results(question_id=1) and WAIT for it to complete + - Then call search_question(question_id=2) and WAIT for it to complete + - Then call extract_insights_from_results(question_id=2) and WAIT for it to complete +4. After all questions are processed, call evaluate_research_confidence +5. Ask user if they want to finalize or continue researching +6. When user approves, call synthesize_final_report CRITICAL RULES: -- ALWAYS call search_question BEFORE extract_insights_from_results for each question -- Process questions in sequence: search Q0 → extract Q0 → search Q1 → extract Q1, etc. -- NEVER skip ahead to extract insights for a question you haven't searched yet -- In the search phase, DO NOT pause between questions - process all questions automatically +- Call ONE tool at a time - wait for each tool to return before calling the next +- NEVER call extract_insights_from_results until search_question has completed and returned results +- DO NOT explain what you're about to do - just call the tool +- DO NOT say "I'll search for..." or "Let me search..." - just call search_question +- The state updates will show the user what's happening - you don't need to narrate +- Process all 3 questions automatically without asking for approval between them Document Viewing: -- Users can request to view the full content of any cited document -- When a user asks to "show document X" or "view source Y", use the get_full_document tool -- Document URIs are tracked automatically as you search -- The final report includes structured citations linking back to source documents +- When user asks to "show document X", call get_full_document with the document_uri -Be transparent: always announce what you're searching for, but don't wait for approval during the search phase. -Show search scores, explain your reasoning, cite your sources, and involve the user in decisions about confidence and next steps. +Remember: Call tools ONE AT A TIME in sequence. Each tool must complete before calling the next. """, ) diff --git a/examples/ag-ui-research/frontend/components/StateDisplay.tsx b/examples/ag-ui-research/frontend/components/StateDisplay.tsx index 79a9f0d1..7b0ba0c9 100644 --- a/examples/ag-ui-research/frontend/components/StateDisplay.tsx +++ b/examples/ag-ui-research/frontend/components/StateDisplay.tsx @@ -1,5 +1,6 @@ "use client"; +import { Markdown } from "@copilotkit/react-ui"; import { useState } from "react"; interface SourceRef { @@ -413,7 +414,7 @@ export default function StateDisplay({ state }: StateDisplayProps) { color: "#4a5568", }} > - {item.question} + {item.search_results && (
- {result.chunk}... +
))} @@ -622,7 +623,7 @@ export default function StateDisplay({ state }: StateDisplayProps) { marginBottom: "0.5rem", }} > - {insight.summary} + {insight.source_refs && insight.source_refs.length > 0 && (
Executive Summary -

- {state.final_report.summary} -

+ +

- {state.final_report.findings.map((finding) => ( -
  • - {finding} + {state.final_report.findings.map((finding, idx) => ( +
  • +
  • ))} @@ -767,9 +771,12 @@ export default function StateDisplay({ state }: StateDisplayProps) { lineHeight: "1.6", }} > - {state.final_report.conclusions.map((conclusion) => ( -
  • - {conclusion} + {state.final_report.conclusions.map((conclusion, idx) => ( +
  • +
  • ))}