-
Notifications
You must be signed in to change notification settings - Fork 61
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
chore: implement langgraph #434
Conversation
def call_model(state: UserState, config: RunnableConfig): | ||
""" | ||
Node for function that calls the model | ||
""" | ||
messages = state["messages"] | ||
response = model_runnable.invoke(messages, config) | ||
if ( | ||
state["is_last_step"] | ||
and isinstance(response, AIMessage) | ||
and response.tool_calls | ||
): | ||
return { | ||
"messages": [ | ||
AIMessage( | ||
id=response.id, | ||
content="Sorry, need more steps to process this request.", | ||
) | ||
] | ||
} | ||
return {"messages": [response]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this function inline? Can we get a comment or explanation as to what it is doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is written similarly to the prebuilt react_agent. Let me know if it's better to move it out (so that this isn't inline).
def agent_should_continue(self, state: UserState) -> Literal["tools", "end"]: | ||
""" | ||
Function to determine which node is called next | ||
""" | ||
messages = state["messages"] | ||
last_message = messages[-1] | ||
# If the LLM makes a tool call, then we route to the "tools" node | ||
if isinstance(last_message, AIMessage) and last_message.tool_calls: | ||
return "tools" | ||
# Otherwise, we stop (reply to the user) | ||
return "end" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with this function -- does it need to be inline?
59cf2c6
to
825125c
Compare
825125c
to
fc1b51c
Compare
Update implementation to langgraph. Main changes: - We create a `UserAgent` for each session in langchain orchestration. For langgraph, we create a single graph and use `config` with `thread_id` to keep track of session. This PR does not include the following: - human-in-the-loop workflow (e.g. book ticket confirmation from user). - initialize tools with user-specific client. Currently the tools is initialized with a single client (each session/user is supposed to have their own client). Will create a custom ToolNode in another PR so that the Tool is able to get user's `client` object from the state.
Update implementation to langgraph.
Main changes:
UserAgent
for each session in langchain orchestration. For langgraph, we create a single graph and useconfig
withthread_id
to keep track of session.This PR does not include the following:
client
object from the state.