I am trying to develop a dynamic graph system: The planner agent make a plan first, it will generate something like DSL (Domain Specific Language) and a graph generator agent construct and run the graph dynamically. Are there any examples about this kind of pattern ? I am considering dynamically generate a python script and run it, but it is probably unsafe. And the chat bot of LangChain document recommended that do not use dynamic graph, as they may cause performance issues.
It will be really helpful if there is an example about dynamically graph construction and tool call (I am trying to use ToolNode class to do this).
Grok tells me I can just use Send() and Command() API to run any workflow (even with loop and branches) in a staic graph. I’ll try this.
Hello @MSJavaScript ,
I won’t recommend to use generate and exec Python to build graphs, unsafe and hard to test/deploy. As far as I know and in my experience I have never encounter a use case for building dynamic graphs.
What I would recommend is similar to Groq which is to have a fixed graph with dynamic routing: One compiled graph with predefined nodes/tools. The planner outputs structured data (JSON/Pydantic), not code. An orchestrator node routes execution via state, Send, or Command.