-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (48 loc) · 1.52 KB
/
main.py
File metadata and controls
58 lines (48 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from langgraph.graph import StateGraph, START, END
from typing_extensions import TypedDict
from agents.chat_agent import chat_agent
from agents.interpreter import interpret_spec
from agents.codegen import codegen_agent
from agents.executor import executor_agent
from agents.summariser import summariser_agent
class SimulationState(TypedDict, total=False):
user_input: str
ack: str
forwarded: str
history: list
spec: dict
script: str
stdout: str
stderr: str
frames: list
gif: str
response: str
def main():
# Initialize the graph with the state schema
graph = StateGraph(SimulationState)
# Register agent nodes
graph.add_node("chat", chat_agent)
graph.add_node("interpret", interpret_spec)
graph.add_node("codegen", codegen_agent)
graph.add_node("execute", executor_agent)
graph.add_node("summarise", summariser_agent)
# Define execution order
graph.add_edge(START, "chat")
graph.add_edge("chat", "interpret")
graph.add_edge("interpret", "codegen")
graph.add_edge("codegen", "execute")
graph.add_edge("execute", "summarise")
graph.add_edge("summarise", END)
# Command-line interface
import sys
if len(sys.argv) > 1:
user_input = " ".join(sys.argv[1:])
else:
user_input = input("Enter your simulation request: ")
# Run the graph
result = graph.run({"user_input": user_input})
# Output the final summary
summary = result.get("response", "")
print(summary)
if __name__ == "__main__":
main()