Generate the final answer based on all collected knowledge
| 287 | return "explore" |
| 288 | |
| 289 | class DraftAnswer(Node): |
| 290 | """Generate the final answer based on all collected knowledge""" |
| 291 | |
| 292 | def prep(self, shared): |
| 293 | # Use reasoning from AgentDecision |
| 294 | decision_reasoning = shared.get("decision_reasoning", "") |
| 295 | useful_indices = shared.get("useful_visited_indices", []) |
| 296 | |
| 297 | knowledge_base = "" |
| 298 | if useful_indices: |
| 299 | # Only use most relevant pages |
| 300 | for url_idx in useful_indices: |
| 301 | url = shared["all_discovered_urls"][url_idx] |
| 302 | content = shared["url_content"][url_idx] |
| 303 | knowledge_base += f"\n--- URL {url_idx}: {url} ---\n{content}\n" |
| 304 | |
| 305 | return { |
| 306 | "user_question": shared["user_question"], |
| 307 | "conversation_history": shared.get("conversation_history", []), |
| 308 | "instruction": shared.get("instruction", "Provide helpful and accurate answers."), |
| 309 | "knowledge_base": knowledge_base, |
| 310 | "useful_indices": useful_indices, |
| 311 | "decision_reasoning": decision_reasoning |
| 312 | } |
| 313 | |
| 314 | def exec(self, prep_data): |
| 315 | """Generate comprehensive answer based on collected knowledge""" |
| 316 | user_question = prep_data["user_question"] |
| 317 | conversation_history = prep_data["conversation_history"] |
| 318 | instruction = prep_data["instruction"] |
| 319 | knowledge_base = prep_data["knowledge_base"] |
| 320 | useful_indices = prep_data["useful_indices"] |
| 321 | decision_reasoning = prep_data["decision_reasoning"] |
| 322 | |
| 323 | if not useful_indices and not knowledge_base: |
| 324 | content_header = "Content from initial pages (WARNING: No specific pages were found to be relevant):" |
| 325 | else: |
| 326 | content_header = "Content from most useful pages:" |
| 327 | |
| 328 | # Format conversation history for the prompt |
| 329 | history_str = "" |
| 330 | if conversation_history: |
| 331 | history_str += "CONVERSATION HISTORY:\n" |
| 332 | for turn in conversation_history: |
| 333 | history_str += f"User: {turn['user']}\nBot: {turn['bot']}\n" |
| 334 | history_str += "\n" |
| 335 | |
| 336 | answer_prompt = f"""Based on the following website content, answer this question: {user_question} |
| 337 | |
| 338 | {history_str}INSTRUCTION: {instruction} |
| 339 | |
| 340 | Agent Decision Reasoning: |
| 341 | {decision_reasoning} |
| 342 | |
| 343 | {content_header} |
| 344 | {knowledge_base} |
| 345 | |
| 346 | Response Instructions: |
no outgoing calls
no test coverage detected