From cecc42e53f364d279c31106963160152e0532e6b Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman Date: Sun, 16 Nov 2025 18:17:13 -0500 Subject: [PATCH] Fix: Got scientific paper writer going thropugh the stages. --- examples/scientific_paper_writer.yaml | 342 +++++++++++++++++++++++--- 1 file changed, 301 insertions(+), 41 deletions(-) diff --git a/examples/scientific_paper_writer.yaml b/examples/scientific_paper_writer.yaml index 53de1b3a..f5c1eb20 100644 --- a/examples/scientific_paper_writer.yaml +++ b/examples/scientific_paper_writer.yaml @@ -151,18 +151,12 @@ agents: result = "Already at the final stage." else: result = f"Error: Current stage '{current_stage}' is invalid." - + if target_stage: - # Special handling when leaving vetting stage - if current_stage == 'vetting' and target_stage != 'vetting': - vetting_sources = context.get('vetting_sources', []) - if vetting_sources: - result = f"Advanced to stage: {target_stage}. Vetting sources preserved ({len(vetting_sources)} sources). Please provide your input for this stage." - else: - result = f"Advanced to stage: {target_stage}. No vetting sources found. Please provide your input for this stage." - else: - result = f"Advanced to stage: {target_stage}. Please provide your input for this stage." + # Update the stage context['writing_stage'] = target_stage + # Trigger the stage flow immediately by routing to it with empty input + result = f"GOTO_{target_stage.upper()}:" elif command == '!accept': if context.get('writing_stage') == 'core_content': @@ -344,10 +338,11 @@ agents: provider: openai model: gpt-3.5-turbo system_prompt: | - You are an assistant helping to define a scientific paper. The user has been asked the topic of their paper and - is responding. If their answer isn't clear, then ask clarifying questions until it is clear. Once you get a clear - response then reply with only the string "SET_TOPIC: " followed by a one sentence summary of the topic the user - desires. + You are an assistant helping to define a scientific paper. If the user has not yet provided a topic, ask them + "What topic would you like to write about?" If the user's answer isn't clear, ask clarifying questions until + it is clear. Once you get a clear response then reply with only the string "SET_TOPIC: " followed by a one + sentence summary of the topic the user desires. Do not include any other text in your response when you provide + the SET_TOPIC response, just the string "SET_TOPIC: " followed by the one sentence summary. ask_length: type: llm @@ -355,12 +350,13 @@ agents: provider: openai model: gpt-3.5-turbo system_prompt: | - The topic has just been set. Now, please ask for the desired length of the paper, the user may specify this - however they like, such as pages, paragraphs, or total number of words. If the user doesnt give an answer - sufficiently detailed for you to answer with an approximate desired word count, then ask clarifying questions - until this is clear. Once it is clear enough for you to give an approximate desired word cound then reply with - only the string "SET_LENGTH: " followed by an integer number (using digits not words) indicating the approximate - desired word count; this response must not have any words other than "SET_LENGTH:" and then a numerical number. + The topic has just been set. If the user has not yet provided information about the desired length, ask them + "What length would you like for this paper? You can specify in pages, paragraphs, or word count." If the user + doesnt give an answer sufficiently detailed for you to answer with an approximate desired word count, then ask + clarifying questions until this is clear. Once it is clear enough for you to give an approximate desired word + count then reply with only the string "SET_LENGTH: " followed by an integer number (using digits not words) + indicating the approximate desired word count; this response must not have any words other than "SET_LENGTH:" + and then a numerical number. ask_audience: type: llm @@ -368,11 +364,11 @@ agents: provider: openai model: gpt-3.5-turbo system_prompt: | - The length has just been set. Now, please ask who the target audience is (e.g., general public, experts). If the - user doesnt give an answer sufficiently detailed for you to answer with an intended audience, then ask - clarifying questions until this is clear. Once it is clear enough for you to give the intended audience then - reply with only the string "SET_AUDIENCE: " followed by a short summary of who the intended audience is for this - paper. + The length has just been set. If the user has not yet provided information about the target audience, ask them + "Who is the target audience for this paper? (e.g., general public, experts, academics, etc.)" If the user + doesnt give an answer sufficiently detailed for you to answer with an intended audience, then ask clarifying + questions until this is clear. Once it is clear enough for you to give the intended audience then reply with + only the string "SET_AUDIENCE: " followed by a short summary of who the intended audience is for this paper. ask_publication: type: llm @@ -380,12 +376,13 @@ agents: provider: openai model: gpt-3.5-turbo system_prompt: | - The audience has just been set. Now, please ask if they plan to submit it to a specific publication. If the - user doesnt give an answer sufficiently detailed for you to answer with an intended publication, then ask - clarifying questions until this is clear, or it is determined it wont be published to a publication. Once it is - clear enough for you to give the intended publication then reply with only the string "SET_PUBLICATION: " followed by - the name of the publication, or if no publication will be submitted to then reply with just the string - "SET_PUBLICATION: none" and nothing else. + The audience has just been set. If the user has not yet provided information about publication plans, ask them + "Do you plan to submit this paper to a specific publication or journal?" If the user doesnt give an answer + sufficiently detailed for you to answer with an intended publication, then ask clarifying questions until this + is clear, or it is determined it wont be published to a publication. Once it is clear enough for you to give + the intended publication then reply with only the string "SET_PUBLICATION: " followed by the name of the + publication, or if no publication will be submitted to then reply with just the string "SET_PUBLICATION: none" + and nothing else. ask_format: type: llm @@ -393,14 +390,15 @@ agents: provider: openai model: gpt-3.5-turbo system_prompt: | - The intended publication has just been set. Now, ask what format the paper should be in. - Currently, only 'latex' is supported. If they provide any other answer, you MUST state that the format is not + The intended publication has just been set. If the user has not yet provided information about the desired + format, ask them "What format would you like for this paper? (Note: Currently only 'latex' is supported.)" + Currently, only 'latex' is supported. If they provide any other answer, you MUST state that the format is not supported and that only 'latex' is available. Only accept 'latex' as a valid answer. - Example user input: "markdown" - Your response: "That format isn't supported yet. The only supported formats are: latex." - - If the user doesnt give an answer sufficiently detailed for you to determine their desired format, then ask - clarifying questions until this is clear. Once it is clear enough for you to give the intended format then reply + + If the user doesnt give an answer sufficiently detailed for you to determine their desired format, then ask + clarifying questions until this is clear. Once it is clear enough for you to give the intended format then reply with only the string "SET_FORMAT: " followed by the desired format, which should be latex. ask_other: @@ -409,11 +407,12 @@ agents: provider: openai model: gpt-3.5-turbo system_prompt: | - You just asked the user if there are any other requirements that should be - considered that we didnt cover. If the user doesnt give an answer sufficiently detailed for you to determine - what these additional requirements are then ask clarifying questions until this is clear. Once it is clear - enough for you to effectively summarize these additional requirements then reply with only the string - "SET_OTHER: " followed by a summary of the additional requirements the user has explained throughout the + If the user has not yet been asked about other requirements, ask them "Are there any other requirements or + specifications that should be considered for this paper?" If the user doesnt give an answer sufficiently + detailed for you to determine what these additional requirements are then ask clarifying questions until this + is clear. If the user indicates there are no other requirements, respond with "SET_OTHER: none". Once it is + clear enough for you to effectively summarize these additional requirements then reply with only the string + "SET_OTHER: " followed by a summary of the additional requirements the user has explained throughout the conversations. # ============================================ @@ -845,6 +844,267 @@ routes: - type: map params: agent: command_handler + # Command handler may return routing instructions, process them + - type: switch + params: + cases: + - condition: + type: content_contains + text: "GOTO_INTRO" + operators: + - type: transform + params: + type: replace + old: "GOTO_INTRO:" + new: "" + - type: map + params: + agent: intro_agent + - condition: + type: content_contains + text: "GOTO_DISCOVERY" + operators: + - type: map + params: + agent: discovery_controller + - type: switch + params: + cases: + - condition: + type: content_contains + text: "ROUTE_ASK_TOPIC" + operators: + - type: transform + params: + type: replace + old: "ROUTE_ASK_TOPIC:" + new: "" + - type: map + params: + agent: ask_topic + - type: map + params: + agent: discovery_controller + - condition: + type: content_contains + text: "ROUTE_ASK_LENGTH" + operators: + - type: transform + params: + type: replace + old: "ROUTE_ASK_LENGTH:" + new: "" + - type: map + params: + agent: ask_length + - type: map + params: + agent: discovery_controller + - condition: + type: content_contains + text: "ROUTE_ASK_AUDIENCE" + operators: + - type: transform + params: + type: replace + old: "ROUTE_ASK_AUDIENCE:" + new: "" + - type: map + params: + agent: ask_audience + - type: map + params: + agent: discovery_controller + - condition: + type: content_contains + text: "ROUTE_ASK_PUBLICATION" + operators: + - type: transform + params: + type: replace + old: "ROUTE_ASK_PUBLICATION:" + new: "" + - type: map + params: + agent: ask_publication + - type: map + params: + agent: discovery_controller + - condition: + type: content_contains + text: "ROUTE_ASK_FORMAT" + operators: + - type: transform + params: + type: replace + old: "ROUTE_ASK_FORMAT:" + new: "" + - type: map + params: + agent: ask_format + - type: map + params: + agent: discovery_controller + - condition: + type: content_contains + text: "ROUTE_ASK_OTHER" + operators: + - type: transform + params: + type: replace + old: "ROUTE_ASK_OTHER:" + new: "" + - type: map + params: + agent: ask_other + - type: map + params: + agent: discovery_controller + - condition: + type: content_contains + text: "DISCOVERY_RESPONSE:" + operators: + - type: transform + params: + type: replace + old: "DISCOVERY_RESPONSE:" + new: "" + - condition: + type: content_contains + text: "GOTO_BRAINSTORMING" + operators: + - type: transform + params: + type: replace + old: "GOTO_BRAINSTORMING:" + new: "" + - type: map + params: + agent: brainstorming_agent + - type: map + params: + agent: brainstorming_saver + - condition: + type: content_contains + text: "GOTO_VETTING" + operators: + - type: transform + params: + type: replace + old: "GOTO_VETTING:" + new: "" + - type: map + params: + agent: vetting_agent + - type: map + params: + agent: vetting_saver + - condition: + type: content_contains + text: "GOTO_STRUCTURE" + operators: + - type: transform + params: + type: replace + old: "GOTO_STRUCTURE:" + new: "" + - type: map + params: + agent: structure_agent + - type: map + params: + agent: structure_saver + - condition: + type: content_contains + text: "GOTO_DEEP_RESEARCH" + operators: + - type: transform + params: + type: replace + old: "GOTO_DEEP_RESEARCH:" + new: "" + - type: map + params: + agent: deep_research_agent + - type: map + params: + agent: deep_research_saver + - condition: + type: content_contains + text: "GOTO_CORE_CONTENT" + operators: + - type: transform + params: + type: replace + old: "GOTO_CORE_CONTENT:" + new: "" + - type: map + params: + agent: core_content_manager + - type: switch + params: + cases: + - condition: + type: content_contains + text: "WRITE_SECTION:" + operators: + - type: map + params: + agent: core_content_agent + - condition: + type: content_contains + text: "FINISH_CORE_CONTENT:" + operators: + - type: transform + params: + type: replace + old: "FINISH_CORE_CONTENT:" + new: "" + - condition: + type: content_contains + text: "GOTO_FRAMING_CONTENT" + operators: + - type: transform + params: + type: replace + old: "GOTO_FRAMING_CONTENT:" + new: "" + - type: map + params: + agent: framing_agent + - type: map + params: + agent: framing_saver + - condition: + type: content_contains + text: "GOTO_PROOFREADING" + operators: + - type: transform + params: + type: replace + old: "GOTO_PROOFREADING:" + new: "" + - type: map + params: + agent: proofreading_agent + - type: map + params: + agent: proofreading_saver + - condition: + type: content_contains + text: "GOTO_FORMATTING" + operators: + - type: transform + params: + type: replace + old: "GOTO_FORMATTING:" + new: "" + - type: map + params: + agent: latex_formatter + - type: map + params: + agent: formatting_saver - condition: type: content_contains text: "GOTO_INTRO"