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

chore: implement langgraph #434

Merged
merged 2 commits into from
Jul 22, 2024
Merged

chore: implement langgraph #434

merged 2 commits into from
Jul 22, 2024

Conversation

Yuan325
Copy link
Collaborator

@Yuan325 Yuan325 commented Jul 8, 2024

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.

@Yuan325 Yuan325 requested a review from a team as a code owner July 8, 2024 20:54
@Yuan325 Yuan325 changed the base branch from main to langgraph July 8, 2024 20:54
Comment on lines 81 to 100
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]}
Copy link
Collaborator

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?

Copy link
Collaborator Author

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).

Comment on lines 102 to 112
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"
Copy link
Collaborator

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?

llm_demo/orchestrator/langgraph/langgraph_orchestrator.py Outdated Show resolved Hide resolved
llm_demo/orchestrator/langgraph/langgraph_orchestrator.py Outdated Show resolved Hide resolved
llm_demo/orchestrator/langgraph/langgraph_orchestrator.py Outdated Show resolved Hide resolved
@Yuan325 Yuan325 marked this pull request as draft July 18, 2024 19:30
@Yuan325 Yuan325 marked this pull request as ready for review July 20, 2024 00:49
@Yuan325 Yuan325 requested a review from kurtisvg July 20, 2024 06:44
@Yuan325 Yuan325 merged commit 4c9feb4 into langgraph Jul 22, 2024
4 checks passed
@Yuan325 Yuan325 deleted the langgraph-implementation branch July 22, 2024 22:26
Yuan325 added a commit that referenced this pull request Jul 26, 2024
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.
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

Successfully merging this pull request may close these issues.

None yet

2 participants