-
Notifications
You must be signed in to change notification settings - Fork 29
feat: conversational agent support #395
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| """Routing functions for conditional edges in the agent graph.""" | ||
|
|
||
| import logging | ||
| from typing import Literal | ||
|
|
||
| from uipath_langchain.agent.react.router_utils import validate_last_message_is_AI | ||
|
|
||
| from .types import AgentGraphNode, AgentGraphState | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def create_route_agent_conversational(): | ||
| """Create a routing function for conversational agents. It routes between agent and tool calls until | ||
| the agent response has no tool calls, then it routes to the USER_MESSAGE_WAIT node which does an interrupt. | ||
|
|
||
| Returns: | ||
| Routing function for LangGraph conditional edges | ||
| """ | ||
|
|
||
| def route_agent_conversational( | ||
| state: AgentGraphState, | ||
| ) -> list[str] | Literal[AgentGraphNode.TERMINATE]: | ||
| """Route after agent | ||
|
|
||
| Routing logic: | ||
| 3. If tool calls, route to specific tool nodes (return list of tool names) | ||
| 4. If no tool calls, route to user message wait node | ||
|
|
||
| Returns: | ||
| - list[str]: Tool node names for parallel execution | ||
| - AgentGraphNode.USER_MESSAGE_WAIT: When there are no tool calls | ||
|
|
||
| Raises: | ||
| AgentNodeRoutingException: When encountering unexpected state (empty messages, non-AIMessage, or excessive completions) | ||
| """ | ||
| last_message = validate_last_message_is_AI(state.messages) | ||
| if last_message.tool_calls: | ||
| return [tc["name"] for tc in last_message.tool_calls] | ||
| else: | ||
| return AgentGraphNode.TERMINATE | ||
|
|
||
| return route_agent_conversational |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """Routing functions for conditional edges in the agent graph.""" | ||
|
|
||
| from langchain_core.messages import AIMessage, AnyMessage | ||
|
|
||
| from ..exceptions import AgentNodeRoutingException | ||
|
|
||
|
|
||
| def validate_last_message_is_AI(messages: list[AnyMessage]) -> AIMessage: | ||
| """Validate and return last message from state. | ||
|
|
||
| Raises: | ||
| AgentNodeRoutingException: If messages are empty or last message is not AIMessage | ||
| """ | ||
| if not messages: | ||
| raise AgentNodeRoutingException( | ||
| "No messages in state - cannot route after agent" | ||
| ) | ||
|
|
||
| last_message = messages[-1] | ||
| if not isinstance(last_message, AIMessage): | ||
| raise AgentNodeRoutingException( | ||
| f"Last message is not AIMessage (type: {type(last_message).__name__}) - cannot route after agent" | ||
| ) | ||
|
|
||
| return last_message |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.