Update agent.py
Browse files
agent.py
CHANGED
|
@@ -148,4 +148,48 @@ def files_condition(state: AgentState) -> str:
|
|
| 148 |
elif state["file_name"]=="":
|
| 149 |
return "reformulate_question"
|
| 150 |
else:
|
| 151 |
-
return "not_handled"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
elif state["file_name"]=="":
|
| 149 |
return "reformulate_question"
|
| 150 |
else:
|
| 151 |
+
return "not_handled"
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def build_agent()
|
| 155 |
+
## The graph
|
| 156 |
+
builder = StateGraph(AgentState)
|
| 157 |
+
|
| 158 |
+
# Define nodes: these do the work
|
| 159 |
+
builder.add_node("get_question", get_question)
|
| 160 |
+
builder.add_node("reformulate_question", reformulate_question)
|
| 161 |
+
builder.add_node("assistant", assistant)
|
| 162 |
+
builder.add_node("tools", ToolNode(tools))
|
| 163 |
+
builder.add_node("get_final_answer", get_final_answer)
|
| 164 |
+
builder.add_node("python_interpreter", python_interpreter)
|
| 165 |
+
builder.add_node("image_interpreter", image_interpreter)
|
| 166 |
+
builder.add_node("not_handled", not_handled)
|
| 167 |
+
|
| 168 |
+
# Define edges: these determine how the control flow moves
|
| 169 |
+
builder.add_edge(START, "get_question")
|
| 170 |
+
builder.add_conditional_edges(
|
| 171 |
+
"get_question",
|
| 172 |
+
files_condition,
|
| 173 |
+
{
|
| 174 |
+
"python_interpreter": "python_interpreter",
|
| 175 |
+
"image_interpreter": "image_interpreter",
|
| 176 |
+
"reformulate_question": "reformulate_question",
|
| 177 |
+
"not_handled": "not_handled"
|
| 178 |
+
}
|
| 179 |
+
)
|
| 180 |
+
builder.add_edge("python_interpreter", "get_final_answer")
|
| 181 |
+
builder.add_edge("image_interpreter", "get_final_answer")
|
| 182 |
+
builder.add_edge("reformulate_question", "assistant")
|
| 183 |
+
builder.add_conditional_edges(
|
| 184 |
+
"assistant",
|
| 185 |
+
tools_condition,
|
| 186 |
+
{
|
| 187 |
+
"tools": "tools",
|
| 188 |
+
"get_final_answer": "get_final_answer"
|
| 189 |
+
}
|
| 190 |
+
)
|
| 191 |
+
builder.add_edge("tools", "assistant")
|
| 192 |
+
builder.add_edge("get_final_answer", END)
|
| 193 |
+
builder.add_edge("not_handled", END)
|
| 194 |
+
mySuperAgent = builder.compile()
|
| 195 |
+
return mySuperAgent
|