DEV Community

Cover image for LangGraph idea generation
Olivier
Olivier

Posted on

LangGraph idea generation

TL;DR: Using a well written blog about langGraph and a Claude-3 prompt, I have a guide and starting point to build my own system using LangChain.

LangGraph takes a minute to wrap your head around but is brilliant. Rotem Weiss wrote a brilliant blog that explains it with a simple example from his GPT-Newspaper.

I used that blog's content (yes the full content) in combination with Claude-3-opus and my own idea (A research tool) that I needed to build a LangGraph for, and got a great response!

Copy-Paste the text from the blog in Claude then copy-paste this:

Given the logic of how LangGraph works given that example.
Help me come up with a LangGraph setup (help me with the 
logic of the nodes, the edges and the conditional edges 
knowing that we can define as many as we want and we also
define the functions and every fully customizable)... 
for a system that will Research a topic in XYZ. I have a
knowledge base that can be searched using a hybrid search 
(vector and keyword), I have the internet to search, I have a 
query deconstructor (to help break the user's research 
question down into multiple queries), I have a research 
planner that will help determine the tasks, I have a 
summarizer, and then a final_responder .. add any other 
functions or roles you can think of and give me the outline 
of the graph.
Enter fullscreen mode Exit fullscreen mode

Here is the response I got!


Here's a proposed LangGraph setup for a system that researches a topic in XYZ based on the components you mentioned:

Nodes (Functions):

  1. query_deconstructor: Breaks down the user's research question into multiple sub-queries.
  2. research_planner: Determines the tasks and steps needed to answer the sub-queries.
  3. knowledge_base_searcher: Searches the internal knowledge base using hybridSearch (vector and keyword).
  4. internet_searcher: Searches the internet for relevant information.
  5. information_filter: Filters and selects the most relevant information from the search results.
  6. information_synthesizer: Combines and synthesizes the filtered information into coherent sections.
  7. section_critic: Critiques and provides feedback on the synthesized sections.
  8. section_reviser: Revises the sections based on the feedback from the critic.
  9. summarizer: Summarizes the revised sections into a concise overview.
  10. final_responder: Generates the final response to the user's research question.

Edges:

  1. query_deconstructor -> research_planner
  2. research_planner -> knowledge_base_searcher
  3. research_planner -> internet_searcher
  4. knowledge_base_searcher -> information_filter
  5. internet_searcher -> information_filter
  6. information_filter -> information_synthesizer
  7. information_synthesizer -> section_critic
  8. section_critic -> section_reviser (conditional edge)
  9. section_critic -> summarizer (conditional edge)
  10. section_reviser -> section_critic
  11. summarizer -> final_responder

Conditional Edges:

  1. section_critic -> section_reviser: If the critic finds issues or suggests improvements, the section is sent to the reviser for refinement.
  2. section_critic -> summarizer: If the critic approves the section, it is sent to the summarizer.

Additional Functions/Roles:

  1. data_visualizer: Creates visualizations and infographics based on the researched information to enhance the final output.
  2. citation_manager: Manages and formats citations for the information used in the research.
  3. glossary_generator: Generates a glossary of key terms and concepts related to the researched topic.
  4. executive_summary_generator: Produces an executive summary of the research findings.

Outline of the Graph:

  1. Start with the query_deconstructor to break down the user's research question.
  2. Pass the deconstructed queries to the research_planner to determine the tasks and steps.
  3. The research_planner initiates searches in the knowledge_base_searcher and internet_searcher.
  4. The search results are passed to the information_filter for selection of the most relevant information.
  5. The filtered information is sent to the information_synthesizer to create coherent sections.
  6. The synthesized sections are critiqued by the section_critic.
  7. If the section_critic suggests improvements, the section is sent to the section_reviser for refinement and then back to the section_critic for re-evaluation.
  8. If the section_critic approves the section, it is passed to the summarizer.
  9. The summarizer condenses the revised sections into a concise overview.
  10. The summarized content is sent to the final_responder to generate the final response to the user's research question.
  11. Additional functions like data_visualizer, citation_manager, glossary_generator, and executive_summary_generator can be integrated at appropriate points in the graph to enhance the final output.

Honestly, that's not bad for the fact that LangGraph is new and Claude 3 has absolutely no knowledge of LangChain's LangGraph.

Top comments (0)