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(agent): Update component ordering #7148

Conversation

kcze
Copy link
Contributor

@kcze kcze commented May 11, 2024

User description

Merged with #7106

Background

Refactor #7106 is causing many problems with circular imports.
Static run_after inside component classes needlessely couples components to each other and hides ordering from the developer. And it's only useful for internal components as the exact type needs to be known.

Changes 🏗️

Removed usage of static run_after field and introduced run_after method that allows defining ordering at the agent level (local & clear). This also allows user to order specific components (without defining order for all components).

  • Introduced run_after method in ComponentAgent
  • Updated relevant code and docs
  • Added code comments

PR Quality Scorecard ✨

  • Have you used the PR description template?   +2 pts
  • Is your pull request atomic, focusing on a single change?   +5 pts
  • Have you linked the GitHub issue(s) that this PR addresses?   +5 pts
  • Have you documented your changes clearly and comprehensively?   +5 pts
  • Have you changed or added a feature?   -4 pts
    • Have you added/updated corresponding documentation?   +4 pts
    • Have you added/updated corresponding integration tests?   +5 pts
  • Have you changed the behavior of AutoGPT?   -5 pts
    • Have you also run agbenchmark to verify that these changes do not regress performance?   +10 pts

PR Type

Enhancement, Documentation


Description

  • Introduced a dynamic run_after method to replace static ordering in components, enhancing flexibility and clarity in component execution order.
  • Updated agent initialization in agent.py to use the new dynamic run_after method for WatchdogComponent and ContextComponent.
  • Removed outdated static run_after lists from WatchdogComponent and EventHistoryComponent.
  • Documentation in README.md updated to guide on using the new dynamic ordering method and to warn about potential circular dependencies.

Changes walkthrough 📝

Relevant files
Enhancement
agent.py
Implement dynamic component ordering in Agent initialization

autogpts/autogpt/autogpt/agents/agent.py

  • Replaced static run_after with dynamic run_after method calls for
    WatchdogComponent and ContextComponent.
  • +4/-2     
    base.py
    Refine component collection and fix comment typo                 

    autogpts/autogpt/autogpt/agents/base.py

  • Fixed typo in a comment.
  • Updated component collection logic to prevent revisiting components.
  • +3/-4     
    components.py
    Add dynamic ordering method to AgentComponent                       

    autogpts/autogpt/autogpt/agents/components.py

  • Added run_after method to dynamically set component execution order.
  • Removed static run_after list.
  • +17/-2   
    watchdog.py
    Remove static ordering from WatchdogComponent                       

    autogpts/autogpt/autogpt/agents/features/watchdog.py

    • Removed static run_after list from WatchdogComponent.
    +0/-3     
    event_history.py
    Remove static ordering from EventHistoryComponent               

    autogpts/autogpt/autogpt/components/event_history.py

    • Removed static run_after list from EventHistoryComponent.
    +0/-3     
    Documentation
    README.md
    Update README to document dynamic component ordering         

    autogpts/autogpt/autogpt/commands/README.md

  • Updated documentation to reflect dynamic component ordering.
  • Added warnings about circular dependencies.
  • +18/-9   

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @kcze kcze requested a review from a team as a code owner May 11, 2024 20:48
    @kcze kcze requested review from ntindle and Pwuts May 11, 2024 20:48
    Copy link

    netlify bot commented May 11, 2024

    Deploy Preview for auto-gpt-docs canceled.

    Name Link
    🔨 Latest commit ffd6377
    🔍 Latest deploy log https://app.netlify.com/sites/auto-gpt-docs/deploys/663fd99edaac5800083eb939

    @codiumai-pr-agent-pro codiumai-pr-agent-pro bot added documentation Improvements or additions to documentation enhancement New feature or request labels May 11, 2024
    Copy link

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Description updated to latest commit (ffd6377)

    Copy link

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Review 🔍

    ⏱️ Estimated effort to review [1-5]

    3, because the PR involves changes across multiple files with modifications to the core functionality of component ordering. Understanding the impact of these changes on the system's behavior and ensuring no side effects or circular dependencies require careful review.

    🧪 Relevant tests

    No

    ⚡ Possible issues

    Possible Bug: The new run_after method implementation allows setting up dependencies, but there's no check for circular dependencies which could lead to infinite loops or stack overflow errors during component initialization.

    Compatibility Issue: The removal of the static run_after list and introduction of the instance method might break existing code if external scripts or modules depend on the old static list.

    🔒 Security concerns

    No

    Copy link

    codecov bot commented May 11, 2024

    Codecov Report

    All modified and coverable lines are covered by tests ✅

    Project coverage is 44.07%. Comparing base (b0cbf71) to head (ffd6377).
    Report is 7 commits behind head on master.

    Additional details and impacted files
    @@            Coverage Diff             @@
    ##           master    #7148      +/-   ##
    ==========================================
    - Coverage   44.68%   44.07%   -0.62%     
    ==========================================
      Files         133      133              
      Lines        6315     6319       +4     
      Branches      823      825       +2     
    ==========================================
    - Hits         2822     2785      -37     
    - Misses       3382     3424      +42     
    + Partials      111      110       -1     
    Flag Coverage Δ
    Linux ?
    Windows 42.82% <100.00%> (+0.05%) ⬆️
    autogpt-agent 44.07% <100.00%> (-0.59%) ⬇️
    macOS 44.04% <100.00%> (+0.05%) ⬆️

    Flags with carried forward coverage won't be shown. Click here to find out more.

    ☔ View full report in Codecov by Sentry.
    📢 Have feedback on the report? Share it here.

    Pwuts added a commit that referenced this pull request May 15, 2024
    …7106)
    
    Moved from `autogpt` to `forge`:
    - `autogpt.config`          -> `forge.config`
    - `autogpt.processing`      -> `forge.content_processing`
    - `autogpt.file_storage`    -> `forge.file_storage`
    - `autogpt.logs`            -> `forge.logging`
    - `autogpt.speech`          -> `forge.speech`
    - `autogpt.agents.(base|components|protocols)`  -> `forge.agent.*`
    - `autogpt.command_decorator`                   -> `forge.command.decorator`
    - `autogpt.models.(command|command_parameter)`  -> `forge.command.(command|parameter)`
    - `autogpt.(commands|components|features)`      -> `forge.components`
    - `autogpt.core.utils.json_utils`           -> `forge.json.parsing`
    - `autogpt.prompts.utils`                   -> `forge.llm.prompting.utils`
    - `autogpt.core.prompting.(base|schema|utils)`    -> `forge.llm.prompting.*`
    - `autogpt.core.resource.model_providers`   -> `forge.llm.providers`
    - `autogpt.llm.providers.openai` + `autogpt.core.resource.model_providers.utils`
                                                -> `forge.llm.providers.utils`
    - `autogpt.models.action_history:Action*`   -> `forge.models.action`
    - `autogpt.core.configuration.schema`       -> `forge.models.config`
    - `autogpt.core.utils.json_schema`          -> `forge.models.json_schema`
    - `autogpt.core.resource.schema`            -> `forge.models.providers`
    - `autogpt.models.utils`                    -> `forge.models.utils`
    - `forge.sdk.(errors|utils)` + `autogpt.utils.(exceptions|file_operations_utils|validators)`
                            -> `forge.utils.(exceptions|file_operations|url_validator)`
    - `autogpt.utils.utils` -> `forge.utils.const` + `forge.utils.yaml_validator`
    
    Moved within `forge`:
    - forge/prompts/* -> forge/llm/prompting/*
    
    The rest are mostly import updates, and some sporadic removals and necessary updates (for example to fix circular deps):
    - Changed `CommandOutput = Any` to remove coupling with `ContextItem` (no longer needed)
    - Removed unused `Singleton` class
    - Reluctantly moved `speech` to forge due to coupling (tts needs to be changed into component)
    - Moved `function_specs_from_commands` and `core/resource/model_providers` to `llm/providers` (resources were a `core` thing and are no longer relevant)
    - Keep tests in `autogpt` to reduce changes in this PR
    - Removed unused memory-related code from tests
    - Removed duplicated classes: `FancyConsoleFormatter`, `BelowLevelFilter`
    - `prompt_settings.yaml` is in both `autogpt` and `forge` because for some reason doesn't work when placed in just one dir (need to be taken care of)
    - Removed `config` param from `clean_input`, it wasn't used and caused circular dependency
    - Renamed `BaseAgentActionProposal` to `ActionProposal`
    - Updated `pyproject.toml` in `forge` and `autogpt`
    - Moved `Action*` models from `forge/components/action_history/model.py` to `forge/models/action.py` as those are relevant to the entire agent and not just `EventHistoryComponent` + to reduce coupling
    - Renamed `DEFAULT_ASK_COMMAND` to `ASK_COMMAND` and `DEFAULT_FINISH_COMMAND` to `FINISH_COMMAND`
    - Renamed `AutoGptFormatter` to `ForgeFormatter` and moved to `forge`
    
    Includes changes from PR #7148
    ---------
    
    Co-authored-by: Reinier van der Leer <pwuts@agpt.co>
    @github-actions github-actions bot added the conflicts Automatically applied to PRs with merge conflicts label May 15, 2024
    Copy link

    This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

    @kcze kcze closed this May 15, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    AutoGPT Agent conflicts Automatically applied to PRs with merge conflicts documentation Improvements or additions to documentation enhancement New feature or request Review effort [1-5]: 3 size/m
    Projects
    Status: Done
    Development

    Successfully merging this pull request may close these issues.

    None yet

    1 participant