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

feat: add message_output and refactor LCAgentComponent #2755

Merged
merged 12 commits into from
Jul 17, 2024

Conversation

ogabrielluiz
Copy link
Contributor

This PR improves LCAgentComponent and adds output to all Agents.

Copy link
Contributor

Pull Request Validation Report

This comment is automatically generated by Conventional PR

Whitelist Report

Whitelist Active Result
Pull request is a draft and should be ignored
Pull request is made by a whitelisted user and should be ignored
Pull request is submitted by a bot and should be ignored
Pull request is submitted by administrators and should be ignored

Result

Pull request matches with one (or more) enabled whitelist criteria. Pull request validation is skipped.

Last Modified at 17 Jul 24 13:18 UTC

Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-2755.dmtpw4p5recq1.amplifyapp.com

@github-actions github-actions bot added the enhancement New feature or request label Jul 17, 2024
@ogabrielluiz ogabrielluiz force-pushed the add_text_output_agents branch from 2a8d9cd to 82b1000 Compare July 17, 2024 16:09
…Component to improve agent functionality and interaction with messages
This commit adds a new type alias `ToolEnabledLanguageModel` to the `constants.py` file in the `field_typing` module. This type alias is used to define the type of language models that have tooling enabled. It includes the `BaseLanguageModel`, `BaseLLM`, and `BaseChatModel` types. This change enhances the typing capabilities of the codebase and improves the clarity of the code.
This commit modifies the `agent.py` file to include support for the `ToolEnabledLanguageModel` in the `LCToolsAgentComponent` class. The `ToolEnabledLanguageModel` is now added as an input type in the `HandleInput` section. This change enhances the functionality of the agent by allowing it to work with language models that have tooling enabled. The addition of this input type improves the flexibility and versatility of the codebase.
This commit modifies the `agent.py` file to include support for the `ToolEnabledLanguageModel` in the `LCAgentComponent` class. The `ToolEnabledLanguageModel` is now added as an input type in the `HandleInput` section. This change enhances the functionality of the agent by allowing it to work with language models that have tooling enabled. The addition of this input type improves the flexibility and versatility of the codebase.
This commit adds the `AgentAsyncHandler` class to handle callbacks from langchain in the `callback.py` file. The `AgentAsyncHandler` is an async callback handler that can be used to handle various events such as tool start, tool end, agent action, and agent finish. This change enhances the functionality of the codebase by providing a convenient way to handle callbacks from langchain and log the events if a log function is provided.
…ization

This commit adds the `field_serializer` decorator to the `Log` class in the `schema.py` file. The decorator is used to serialize the `message` attribute of the `Log` class, ensuring that all nested objects are properly serialized. This change improves the serialization process and enhances the functionality of the codebase.
@ogabrielluiz ogabrielluiz force-pushed the add_text_output_agents branch from 82b1000 to e69f823 Compare July 17, 2024 18:07
This commit fixes an issue in the `LangSmithTracer` class where logs were not being properly serialized. The `add_metadata` method now converts logs to dictionaries using the `model_dump` method if they are not already dictionaries. This ensures that all logs are correctly serialized and improves the functionality of the codebase.
This commit modifies the `LCAgentComponent` class in the `agent.py` file to handle list results in the `result` variable. If the `result` is a list, it is joined into a single string using the `text` attribute of each result dictionary. This change improves the functionality of the codebase by ensuring that the `result` variable is always a string, which is expected by the `Message` class.
This commit adds a "name" parameter to the `on_tool_start`, `on_tool_end`, `on_agent_action`, and `on_agent_finish` methods of the `AgentAsyncHandler` class in the `callback.py` file. The "name" parameter allows for specifying a name for the event, which can be useful for logging and tracking purposes. This change enhances the functionality of the codebase by providing more flexibility in handling callbacks and improves the clarity of the code.
@ogabrielluiz ogabrielluiz marked this pull request as ready for review July 17, 2024 20:26
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 17, 2024
@ogabrielluiz ogabrielluiz requested a review from namastex888 July 17, 2024 20:26
@ogabrielluiz ogabrielluiz enabled auto-merge (squash) July 17, 2024 20:27
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 17, 2024
@ogabrielluiz ogabrielluiz disabled auto-merge July 17, 2024 20:30
@ogabrielluiz ogabrielluiz enabled auto-merge (squash) July 17, 2024 20:30
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 17, 2024
…e loggable types

This commit updates the `AgentAsyncHandler` constructor in the `callback.py` file to support logging multiple loggable types. The `log_function` parameter now accepts a callable that can handle either a single `LoggableType` or a list of `LoggableType` objects along with a string representing the event name. This change enhances the flexibility of the codebase by allowing for more versatile logging options and improves the clarity of the code.
…ctor and methods for better readability and accuracy

refactor(callback.py): simplify on_tool_end method by using **kwargs for flexibility and consistency with other methods
@ogabrielluiz ogabrielluiz disabled auto-merge July 17, 2024 21:14
@ogabrielluiz ogabrielluiz enabled auto-merge (squash) July 17, 2024 21:14
@ogabrielluiz ogabrielluiz merged commit 2c3e93b into main Jul 17, 2024
45 checks passed
@ogabrielluiz ogabrielluiz deleted the add_text_output_agents branch July 17, 2024 21:38
nicoloboschi pushed a commit to datastax/ragstack-ai-langflow that referenced this pull request Jul 30, 2024
)

* feat(agent.py): add support for handling message responses in LCAgentComponent to improve agent functionality and interaction with messages

* feat: add ToolEnabledLanguageModel type alias to constants.py

This commit adds a new type alias `ToolEnabledLanguageModel` to the `constants.py` file in the `field_typing` module. This type alias is used to define the type of language models that have tooling enabled. It includes the `BaseLanguageModel`, `BaseLLM`, and `BaseChatModel` types. This change enhances the typing capabilities of the codebase and improves the clarity of the code.

* feat: update agent.py to include support for ToolEnabledLanguageModel

This commit modifies the `agent.py` file to include support for the `ToolEnabledLanguageModel` in the `LCToolsAgentComponent` class. The `ToolEnabledLanguageModel` is now added as an input type in the `HandleInput` section. This change enhances the functionality of the agent by allowing it to work with language models that have tooling enabled. The addition of this input type improves the flexibility and versatility of the codebase.

* feat: add support for ToolEnabledLanguageModel in LCAgentComponent

This commit modifies the `agent.py` file to include support for the `ToolEnabledLanguageModel` in the `LCAgentComponent` class. The `ToolEnabledLanguageModel` is now added as an input type in the `HandleInput` section. This change enhances the functionality of the agent by allowing it to work with language models that have tooling enabled. The addition of this input type improves the flexibility and versatility of the codebase.

* feat: add AgentAsyncHandler for handling callbacks from Agents

This commit adds the `AgentAsyncHandler` class to handle callbacks from langchain in the `callback.py` file. The `AgentAsyncHandler` is an async callback handler that can be used to handle various events such as tool start, tool end, agent action, and agent finish. This change enhances the functionality of the codebase by providing a convenient way to handle callbacks from langchain and log the events if a log function is provided.

* chore: add field_serializer decorator to Log class for message serialization

This commit adds the `field_serializer` decorator to the `Log` class in the `schema.py` file. The decorator is used to serialize the `message` attribute of the `Log` class, ensuring that all nested objects are properly serialized. This change improves the serialization process and enhances the functionality of the codebase.

* feat: Fix issue with logs in LangSmithTracer

This commit fixes an issue in the `LangSmithTracer` class where logs were not being properly serialized. The `add_metadata` method now converts logs to dictionaries using the `model_dump` method if they are not already dictionaries. This ensures that all logs are correctly serialized and improves the functionality of the codebase.

* feat: Add support for Pydantic V1 models in Log serialization

* fix: Update LCAgentComponent to handle list results in result variable

This commit modifies the `LCAgentComponent` class in the `agent.py` file to handle list results in the `result` variable. If the `result` is a list, it is joined into a single string using the `text` attribute of each result dictionary. This change improves the functionality of the codebase by ensuring that the `result` variable is always a string, which is expected by the `Message` class.

* feat: Add "name" parameter to AgentAsyncHandler methods

This commit adds a "name" parameter to the `on_tool_start`, `on_tool_end`, `on_agent_action`, and `on_agent_finish` methods of the `AgentAsyncHandler` class in the `callback.py` file. The "name" parameter allows for specifying a name for the event, which can be useful for logging and tracking purposes. This change enhances the functionality of the codebase by providing more flexibility in handling callbacks and improves the clarity of the code.

* feat: Update AgentAsyncHandler constructor to support logging multiple loggable types

This commit updates the `AgentAsyncHandler` constructor in the `callback.py` file to support logging multiple loggable types. The `log_function` parameter now accepts a callable that can handle either a single `LoggableType` or a list of `LoggableType` objects along with a string representing the event name. This change enhances the flexibility of the codebase by allowing for more versatile logging options and improves the clarity of the code.

* refactor(callback.py): update type hints in AgentAsyncHandler constructor and methods for better readability and accuracy
refactor(callback.py): simplify on_tool_end method by using **kwargs for flexibility and consistency with other methods

(cherry picked from commit 2c3e93b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants