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 SimpleAgentComponent and related pytests #4318

Merged
merged 31 commits into from
Nov 2, 2024

Conversation

edwinjosechittilappilly
Copy link
Collaborator

Introduce the SimpleAgentComponent, a new agent component that extends ToolCallingAgentComponent. This component allows the agent to utilize various tools and supports both OpenAI and Azure OpenAI language models. It includes configurations for selecting the language model type and manages input types dynamically based on the selected model.

Screen.Recording.2024-10-29.at.1.52.46.PM.mov

Changes

  • Added SimpleAgentComponent class in src/backend/base/langflow/components/agents/simple_agent.py
  • Defined inputs and outputs for the component, including tool handling and language model selection
  • Implemented methods for building and managing language models (get_llm, _build_llm_model)
  • Included error handling for model configuration and missing keys in build_config
  • Updated input types dynamically based on the selected language model

Motivation and Context

This addition enhances the agent framework by providing a straightforward agent capable of leveraging different language models and tools. It offers greater flexibility and extensibility for building complex workflows within the Langflow application.

Future Updates:

  • Add Graph Run inside the component so we can integrate the input component and output component in the same agent.
  • Ability to add Agent Name as sender Name

Autogenerated: PR Message

This pull request introduces a new SimpleAgentComponent class, adds unit tests for this component, and modifies existing tests for the ToolCallingAgentComponent. The key changes include the creation of the SimpleAgentComponent class, the addition of unit tests for both the SimpleAgentComponent and ToolCallingAgentComponent, and the integration of various input and output components.

New Components:

  • src/backend/base/langflow/components/agents/simple_agent.py: Added SimpleAgentComponent class that extends ToolCallingAgentComponent to handle different language models and tools. ([src/backend/base/langflow/components/agents/simple_agent.pyR1-R132](https://github.com/langflow-ai/langflow/pull/4318/files#diff-6bcaea75d1cdcae8ab5798ab147a2956ebbf234384835993ce0a3a3a67abe42cR1-R132))

Unit Tests:

  • src/backend/tests/unit/components/agents/test_simple_agent.py: Added unit test for SimpleAgentComponent to verify its functionality using a calculator tool. ([src/backend/tests/unit/components/agents/test_simple_agent.pyR1-R31](https://github.com/langflow-ai/langflow/pull/4318/files#diff-f2758044606f96f1378563cfaab80149810adf5f7b8b5b780b63f93d4cb8063eR1-R31))
  • src/backend/tests/unit/components/agents/test_tool_calling_agent.py: Added unit test for ToolCallingAgentComponent to ensure it can correctly use a calculator tool and produce expected outputs. ([src/backend/tests/unit/components/agents/test_tool_calling_agent.pyR1-R32](https://github.com/langflow-ai/langflow/pull/4318/files#diff-cb1e0fb42766434760104f00ff364c54550e4c9d2df99d66cd58fa3e06c401a4R1-R32))

new component:
simple ai agent

py tests for tool calling agent as well as for simple ai agent
update _config Changes and code oprimised
Error or inputType as None Solved
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Oct 29, 2024
Copy link
Member

@italojohnny italojohnny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work!

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 30, 2024
@edwinjosechittilappilly
Copy link
Collaborator Author

Thank you @italojohnny

autofix-ci bot and others added 8 commits October 30, 2024 14:43
chat memory added
commit e965fd3
Author: Sebastián Estévez <[email protected]>
Date:   Thu Oct 31 17:16:08 2024 -0400

    fix: broken docker test (#4337)

    * Fix broken docker test

    Fixes #4336

    Update the Docker test workflow to use the `get_version` function from `langflow.utils.version`.

    * Modify the `Test image` step in `.github/workflows/docker_test.yml` to use the `get_version` function instead of directly importing `__version__`.
    * Modify the `Test backend image` step in `.github/workflows/docker_test.yml` to use the `get_version` function instead of directly importing `__version__`.

    ---

    For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/langflow-ai/langflow/issues/4336?shareId=XXXX-XXXX-XXXX-XXXX).

    * version.version not util.version

commit 3279b8a
Author: Lucas Oliveira <[email protected]>
Date:   Thu Oct 31 16:39:58 2024 -0300

    fix: add collapsible function to templates and fix design bugs (#4305)

    * Updated colors

    * Fixed design for small screens

    * Change border radius

    * Changed size of text on templates description

    * Fix shine effect on small screens

    * Fixed icons on starter templates

    * Updated mono font to JetBrains

    * Updated icon hit area for X

    * Added gradient wrapper and x-gradient

    * Changed colors and font weights for nav component

    * Added zoom on hover of gradient

    * Fixed input size

    * Fixed all templates to show everything

    * Hide scrollbar

    * Change text size of card

    * Removed title of the categories

    * Removed unused currentTab from templatecategory

    * Updated position of search icon

    * Updated style of inputs

    * Updated search clear button

    * Fixed bug on small screens

    * Added no results query

    * Fixed background on get started cards

    * Added focus ring on nav component

    * Added tab index to search and sidebar buttons

    * Added keyboard navigation to templates

    * Updated templatesModal to use ShadCN Sidebar

    * Implemented collapsible sidebar

    * Fix collapsible to work on mobile but be overlaying content

    * Added noise to styleUtils

    * Updated padding and sizes for mobile

    * Updated text size

    * Updated font family to inter

    * Made get started components fetch title and description from the flow

    * Updated description on get started component

    * Updated naming of sidebar

    * Updated description of start from scratch

    * Updated color of selected sidebar item

    * Changed text color for sidebar not active items

    * changed description sizes

    * changed to line clamp

    * Reduced gap between icon and category text

    * Fixed no results state

    * Fixed X icon only appearing on hover

    * Fix auto focus issue

    * fixed hover color of primary button

    * Fixed gradients to use stops if it exists and stop using random gradient

    * removed random gradient

    * Fixed design of cards in templates

    * Updated nav to go through tests

    * Fixed focus on input

    * [autofix.ci] apply automated fixes

    * New color

    * fix testes

    * Fixed starter projects test

    * ✨ (starter-projects.spec.ts): add Page import to test function parameters for better code readability and maintainability
    📝 (starter-projects.spec.ts): refactor test to include a function for waiting for template visibility, improving code readability and reducing duplication

    ---------

    Co-authored-by: Cristhian Zanforlin Lousa <[email protected]>
    Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

commit a03da10
Author: Sebastián Estévez <[email protected]>
Date:   Thu Oct 31 14:57:07 2024 -0400

    fix: langfuse upgrade and crew result usage (#4342)

    * lanfuse upgrade and crew result usage

    * ✅ (Dynamic Agent.spec.ts): Enable tests for checking the presence of required environment variables before running the test suite.

    ✨ (Hierarchical Agent.spec.ts): Add integration test for Hierarchical Tasks Agent to ensure proper functionality and behavior
    ✨ (Sequential Task Agent.spec.ts): Add integration test for Sequential Tasks Agent to ensure proper functionality and behavior

    ---------

    Co-authored-by: cristhianzl <[email protected]>
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Oct 31, 2024
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Oct 31, 2024
@edwinjosechittilappilly edwinjosechittilappilly enabled auto-merge (squash) November 1, 2024 21:22
@edwinjosechittilappilly
Copy link
Collaborator Author

edwinjosechittilappilly commented Nov 2, 2024

@Cristhianzl @italojohnny Any suggestion on why the FrontEnd Test Group 4 always fails in this PR?

changed simple agent to agent
@edwinjosechittilappilly
Copy link
Collaborator Author

@Cristhianzl Any suggestion on why the FrontEnd Test Group 4 always fails in this PR?

Found the Error: The simplified Agent is having the name just Agent and the starter template simple Agent Flow is based of the tool calling agent. We might need to update the started template so solve this issue

update Agent Flow.json
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Nov 2, 2024
@edwinjosechittilappilly
Copy link
Collaborator Author

@Cristhianzl Any suggestion on why the FrontEnd Test Group 4 always fails in this PR?

Found the Error: The simplified Agent is having the name just Agent and the starter template simple Agent Flow is based of the tool calling agent. We might need to update the started template so solve this issue

Updated the Agent Flow.json to use the Agent component instead of the tool calling agent, still the test fails.

The issue occurs because the button for inspecting component code is overlaying
the element the test is trying to click. This likely started happening after
the recent frontend layout updates. The solution mainly attempts to resolve the
problem by adjusting the zoom level.
@edwinjosechittilappilly edwinjosechittilappilly merged commit e2c26f1 into main Nov 2, 2024
28 checks passed
@edwinjosechittilappilly edwinjosechittilappilly deleted the feat-simple-agents branch November 2, 2024 09:37
ogabrielluiz pushed a commit that referenced this pull request Nov 4, 2024
* simple ai agent

new component:
simple ai agent

py tests for tool calling agent as well as for simple ai agent

* Update simple_agent.py

update _config Changes and code oprimised

* Update simple_agent.py

Error or inputType as None Solved

* [autofix.ci] apply automated fixes

* fix: INP001 ruff error

* Update test_tool_calling_agent.py

added pytest mark as api required

* Update simple_agent.py

added system prompt

* [autofix.ci] apply automated fixes

* updates in the input field orders

* [autofix.ci] apply automated fixes

* Update simple_agent.py

chat memory added

* [autofix.ci] apply automated fixes

* lint Errors Solved

* Squashed commit of the following:

commit e965fd3
Author: Sebastián Estévez <[email protected]>
Date:   Thu Oct 31 17:16:08 2024 -0400

    fix: broken docker test (#4337)

    * Fix broken docker test

    Fixes #4336

    Update the Docker test workflow to use the `get_version` function from `langflow.utils.version`.

    * Modify the `Test image` step in `.github/workflows/docker_test.yml` to use the `get_version` function instead of directly importing `__version__`.
    * Modify the `Test backend image` step in `.github/workflows/docker_test.yml` to use the `get_version` function instead of directly importing `__version__`.

    ---

    For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/langflow-ai/langflow/issues/4336?shareId=XXXX-XXXX-XXXX-XXXX).

    * version.version not util.version

commit 3279b8a
Author: Lucas Oliveira <[email protected]>
Date:   Thu Oct 31 16:39:58 2024 -0300

    fix: add collapsible function to templates and fix design bugs (#4305)

    * Updated colors

    * Fixed design for small screens

    * Change border radius

    * Changed size of text on templates description

    * Fix shine effect on small screens

    * Fixed icons on starter templates

    * Updated mono font to JetBrains

    * Updated icon hit area for X

    * Added gradient wrapper and x-gradient

    * Changed colors and font weights for nav component

    * Added zoom on hover of gradient

    * Fixed input size

    * Fixed all templates to show everything

    * Hide scrollbar

    * Change text size of card

    * Removed title of the categories

    * Removed unused currentTab from templatecategory

    * Updated position of search icon

    * Updated style of inputs

    * Updated search clear button

    * Fixed bug on small screens

    * Added no results query

    * Fixed background on get started cards

    * Added focus ring on nav component

    * Added tab index to search and sidebar buttons

    * Added keyboard navigation to templates

    * Updated templatesModal to use ShadCN Sidebar

    * Implemented collapsible sidebar

    * Fix collapsible to work on mobile but be overlaying content

    * Added noise to styleUtils

    * Updated padding and sizes for mobile

    * Updated text size

    * Updated font family to inter

    * Made get started components fetch title and description from the flow

    * Updated description on get started component

    * Updated naming of sidebar

    * Updated description of start from scratch

    * Updated color of selected sidebar item

    * Changed text color for sidebar not active items

    * changed description sizes

    * changed to line clamp

    * Reduced gap between icon and category text

    * Fixed no results state

    * Fixed X icon only appearing on hover

    * Fix auto focus issue

    * fixed hover color of primary button

    * Fixed gradients to use stops if it exists and stop using random gradient

    * removed random gradient

    * Fixed design of cards in templates

    * Updated nav to go through tests

    * Fixed focus on input

    * [autofix.ci] apply automated fixes

    * New color

    * fix testes

    * Fixed starter projects test

    * ✨ (starter-projects.spec.ts): add Page import to test function parameters for better code readability and maintainability
    📝 (starter-projects.spec.ts): refactor test to include a function for waiting for template visibility, improving code readability and reducing duplication

    ---------

    Co-authored-by: Cristhian Zanforlin Lousa <[email protected]>
    Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

commit a03da10
Author: Sebastián Estévez <[email protected]>
Date:   Thu Oct 31 14:57:07 2024 -0400

    fix: langfuse upgrade and crew result usage (#4342)

    * lanfuse upgrade and crew result usage

    * ✅ (Dynamic Agent.spec.ts): Enable tests for checking the presence of required environment variables before running the test suite.

    ✨ (Hierarchical Agent.spec.ts): Add integration test for Hierarchical Tasks Agent to ensure proper functionality and behavior
    ✨ (Sequential Task Agent.spec.ts): Add integration test for Sequential Tasks Agent to ensure proper functionality and behavior

    ---------

    Co-authored-by: cristhianzl <[email protected]>

* [autofix.ci] apply automated fixes

* Update worker.py

adding  # noqa: to solve CI Error

* [autofix.ci] apply automated fixes

* Update worker.py

removed unused params that were causing the issue

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: italojohnny <[email protected]>
diogocabral pushed a commit to headlinevc/langflow that referenced this pull request Nov 26, 2024
* simple ai agent

new component:
simple ai agent

py tests for tool calling agent as well as for simple ai agent

* Update simple_agent.py

update _config Changes and code oprimised

* Update simple_agent.py

Error or inputType as None Solved

* [autofix.ci] apply automated fixes

* fix: INP001 ruff error

* Update test_tool_calling_agent.py

added pytest mark as api required

* Update simple_agent.py

added system prompt

* [autofix.ci] apply automated fixes

* updates in the input field orders

* [autofix.ci] apply automated fixes

* Update simple_agent.py

chat memory added

* [autofix.ci] apply automated fixes

* lint Errors Solved

* Squashed commit of the following:

commit e965fd3
Author: Sebastián Estévez <[email protected]>
Date:   Thu Oct 31 17:16:08 2024 -0400

    fix: broken docker test (langflow-ai#4337)

    * Fix broken docker test

    Fixes langflow-ai#4336

    Update the Docker test workflow to use the `get_version` function from `langflow.utils.version`.

    * Modify the `Test image` step in `.github/workflows/docker_test.yml` to use the `get_version` function instead of directly importing `__version__`.
    * Modify the `Test backend image` step in `.github/workflows/docker_test.yml` to use the `get_version` function instead of directly importing `__version__`.

    ---

    For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/langflow-ai/langflow/issues/4336?shareId=XXXX-XXXX-XXXX-XXXX).

    * version.version not util.version

commit 3279b8a
Author: Lucas Oliveira <[email protected]>
Date:   Thu Oct 31 16:39:58 2024 -0300

    fix: add collapsible function to templates and fix design bugs (langflow-ai#4305)

    * Updated colors

    * Fixed design for small screens

    * Change border radius

    * Changed size of text on templates description

    * Fix shine effect on small screens

    * Fixed icons on starter templates

    * Updated mono font to JetBrains

    * Updated icon hit area for X

    * Added gradient wrapper and x-gradient

    * Changed colors and font weights for nav component

    * Added zoom on hover of gradient

    * Fixed input size

    * Fixed all templates to show everything

    * Hide scrollbar

    * Change text size of card

    * Removed title of the categories

    * Removed unused currentTab from templatecategory

    * Updated position of search icon

    * Updated style of inputs

    * Updated search clear button

    * Fixed bug on small screens

    * Added no results query

    * Fixed background on get started cards

    * Added focus ring on nav component

    * Added tab index to search and sidebar buttons

    * Added keyboard navigation to templates

    * Updated templatesModal to use ShadCN Sidebar

    * Implemented collapsible sidebar

    * Fix collapsible to work on mobile but be overlaying content

    * Added noise to styleUtils

    * Updated padding and sizes for mobile

    * Updated text size

    * Updated font family to inter

    * Made get started components fetch title and description from the flow

    * Updated description on get started component

    * Updated naming of sidebar

    * Updated description of start from scratch

    * Updated color of selected sidebar item

    * Changed text color for sidebar not active items

    * changed description sizes

    * changed to line clamp

    * Reduced gap between icon and category text

    * Fixed no results state

    * Fixed X icon only appearing on hover

    * Fix auto focus issue

    * fixed hover color of primary button

    * Fixed gradients to use stops if it exists and stop using random gradient

    * removed random gradient

    * Fixed design of cards in templates

    * Updated nav to go through tests

    * Fixed focus on input

    * [autofix.ci] apply automated fixes

    * New color

    * fix testes

    * Fixed starter projects test

    * ✨ (starter-projects.spec.ts): add Page import to test function parameters for better code readability and maintainability
    📝 (starter-projects.spec.ts): refactor test to include a function for waiting for template visibility, improving code readability and reducing duplication

    ---------

    Co-authored-by: Cristhian Zanforlin Lousa <[email protected]>
    Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

commit a03da10
Author: Sebastián Estévez <[email protected]>
Date:   Thu Oct 31 14:57:07 2024 -0400

    fix: langfuse upgrade and crew result usage (langflow-ai#4342)

    * lanfuse upgrade and crew result usage

    * ✅ (Dynamic Agent.spec.ts): Enable tests for checking the presence of required environment variables before running the test suite.

    ✨ (Hierarchical Agent.spec.ts): Add integration test for Hierarchical Tasks Agent to ensure proper functionality and behavior
    ✨ (Sequential Task Agent.spec.ts): Add integration test for Sequential Tasks Agent to ensure proper functionality and behavior

    ---------

    Co-authored-by: cristhianzl <[email protected]>

* [autofix.ci] apply automated fixes

* Update worker.py

adding  # noqa: to solve CI Error

* [autofix.ci] apply automated fixes

* Update worker.py

removed unused params that were causing the issue

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: italojohnny <[email protected]>
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:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants