Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LangGraph Builder - Utility and abstraction to quickly build graphs #26973 #1898 #149

Open
rvndbalaji opened this issue Oct 2, 2024 · 1 comment

Comments

@rvndbalaji
Copy link

rvndbalaji commented Oct 2, 2024

In my org, I implemented a utility class to dynamically build LangGraph graphs
and abstracted away some of the common details

It is no means perfect, and is probably incomplete,
but is there a way for you guys to implement this in langchain-core or langgraph??

I have this raw implementation here - https://gist.github.com/rvndbalaji/2f50bf3d2fc635bf2f36f71c724e3347

I have provided a user interface with the following

Add Agent button & Build Graph button

  1. There is a d3 graph which is rendered. When user adds an agent on the top, a node is added to the graph using d3
  2. When user selects the node on the graph, a sidebar appears that allows the user to provide name of agent, prompt, selecting tools from drop down, selecting LLM etc. (In my case, the tools are ready-made and pre-exist in backend)
  3. The user can save this as config (as json in the DB)
  4. The exact same json is used to construct the request and send it to the python service and build the graph as shown in my examples
  5. Once the graph compiles properly, I will allow the user to call the graph.run method via the UI
  6. The user should be able to see the streamed outputs of each agent on the UI

List of Agents
[{"llm": "", "name": "start", "color": "#B2AFEB", "tools": [], "prompt": ""}, {"llm": "claude-sonnet-3.5", "name": "Researcher", "color": "#67D995", "tools": [], "prompt": "You are a research assistant. Your task is to search for information and summarize it concisely. Once research is done, give the text to the translator agent"}, {"llm": "claude-sonnet-3.5", "name": "Reviewer", "color": "#f094d3", "tools": [], "prompt": "You will review the outputs of other agents"}, {"llm": "claude-sonnet-3.5", "name": "Translator", "color": "#ffac4d", "tools": [], "prompt": "You are an expert translator"}, {"llm": "", "name": "end", "color": "#99DBEA", "tools": [], "prompt": ""}]

List of edges

[{"source": "Reviewer", "target": "end"}, {"source": "Researcher", "target": "Reviewer"}, {"source": "start", "target": "Researcher"}, {"source": "Translator", "target": "Reviewer"}]
This can be used as a reference to implement a proper utility class


body = GraphConfig(
    graph_id=3,
    name="Graph",
    description="Graph",
    session_id=None,
    agents=[
        AgentConfig(
                    name="Researcher", 
                    prompt="You are a research assistant", 
                    llm="claude-sonnet-3.5", 
                    tools=[], 
                    color="#FF871F"
                   ),
        AgentConfig(
                    name="Writer", 
                    prompt="You are a great writer",
                    llm="claude-sonnet-3.5", 
                    tools=[], 
                    color="#FF871F"
                   ),
    ],
    edges=[
        GraphEdge(source="start", target="Researcher"),
         GraphEdge(source="Researcher", target="Writer"),
        GraphEdge(source="Writer", target="end")
    ]
)


graph = GraphBuilder(graph_config=body)
graph.build()
response = GraphResponse(
    config = graph.get_compiled_config(),
    base64 = graph.get_image(xray=True, mermaid=True)
)
response

FYI @hwchase17 @dqbd

@pazevedo-hyland
Copy link

This type of abstraction would be very usefull tbh!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants