-
Notifications
You must be signed in to change notification settings - Fork 44.1k
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): Introduce Python code execution as prompt strategy #7142
Draft
majdyz
wants to merge
58
commits into
master
Choose a base branch
from
zamilmajdy/code-validation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
ed5f12c
Add code validation
majdyz ca7ca22
one_shot_flow.ipynb + edits to make it work
Pwuts ef1fe7c
Update notebook
majdyz 40426e4
Merge master
majdyz 22e2373
Add code flow as a loop
majdyz 0916df4
Fix async fiasco
majdyz 0eccbe1
Prompt change
majdyz f763452
More prompt engineering
majdyz ea134c7
Benchmark test
majdyz 7b5272f
Fix Await fiasco
majdyz 922e643
Fix Await fiasco
majdyz fb80240
Add return type
majdyz 834eb6c
Some quality polishing
majdyz 81ad3cb
Merge conflicts
majdyz 47eeaf0
Revert dumb changes
majdyz 3c4ff60
Add unit tests
majdyz 9f6e256
Debug Log changes
majdyz dfa7773
Remove unnecessary changes
majdyz 3a60504
isort
majdyz c8e16f3
Fix linting
majdyz ae43136
Fix linting
majdyz a825aa8
Merge branch 'master' into zamilmajdy/code-validation
majdyz fdd9f9b
Log fix
majdyz ae63aa8
Merge remote-tracking branch 'origin/zamilmajdy/code-validation' intoβ¦
majdyz 5c7c276
Merge branch 'master' into zamilmajdy/code-validation
Pwuts fcca4cc
clarify execute_code_flow
Pwuts 6e715b6
simplify function header generation
Pwuts b4cd735
fix name collision with `type` in `Command.return_type`
Pwuts 731d034
implement annotation expansion for non-builtin types
Pwuts 0578fb0
fix async issues with code flow execution
Pwuts c3acb99
clean up `forge.command.command`
Pwuts 6dd0975
clean up & improve `@command` decorator
Pwuts e264bf7
`forge.llm.providers.schema` + `code_flow_executor` lint-fix and cleanup
Pwuts 8144d26
fix type issues
Pwuts 111e858
feat(forge/llm): allow async completion parsers
Pwuts 3e8849b
fix linting and type issues
Pwuts 2c6e1eb
fix type issue in test_code_flow_strategy.py
Pwuts a9eb49d
Merge branch 'master' into zamilmajdy/code-validation
Pwuts 81bac30
fix type issues
Pwuts b59862c
Address comment
majdyz 3597f80
Merge branch 'master' of github.com:Significant-Gravitas/AutoGPT intoβ¦
majdyz e204491
Merge branch 'master' into zamilmajdy/code-validation
ntindle 901dade
Merge branch 'master' into zamilmajdy/code-validation
kcze 680fbf4
Merge branch 'master' into zamilmajdy/code-validation
Pwuts 9f80408
address feedback: pass commands getter to CodeFlowExecutionComponent(..)
Pwuts 37cc047
lint-fix + minor refactor
Pwuts 3e67512
Merge branch 'master' into zamilmajdy/code-validation
Pwuts 6d9f564
Merge branch 'master' into zamilmajdy/code-validation
Pwuts 38eafdb
Update `CodeFlowPromptStrategy` with upstream changes (#7223)
Pwuts 736ac77
Merge branch 'master' into zamilmajdy/code-validation
Pwuts 7f6b7d6
remove unused import in forge/llm/providers/openai.py
Pwuts 8b1d416
Merge branch 'master' into zamilmajdy/code-validation
Pwuts 2c4afd4
Migrate `autogpt/agents/prompt_strategies/code_flow.py` to Pydantic v2
Pwuts f03c654
Merge branch 'master' into zamilmajdy/code-validation
Pwuts e19636a
feat(agent/cli): Pretty-print code flow proposal
Pwuts 9dea6a2
Merge branch 'master' into zamilmajdy/code-validation
Pwuts da9360f
feat(agent/api): Pretty-print `execute_code_flow` proposal in Agent Pβ¦
Pwuts 7e0b115
feat(agent): Improve history format for code flow execution results
Pwuts 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 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 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 |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
from pydantic import Field | ||
|
||
from autogpt.commands.execute_code import CodeExecutorComponent | ||
from autogpt.commands.execute_code_flow import CodeFlowExecutionComponent | ||
from autogpt.commands.git_operations import GitOperationsComponent | ||
from autogpt.commands.image_gen import ImageGeneratorComponent | ||
from autogpt.commands.system import SystemComponent | ||
|
@@ -17,7 +18,7 @@ | |
from autogpt.commands.web_selenium import WebSeleniumComponent | ||
from autogpt.components.event_history import EventHistoryComponent | ||
from autogpt.core.configuration import Configurable | ||
from autogpt.core.prompting import ChatPrompt | ||
from autogpt.core.prompting import ChatPrompt, PromptStrategy | ||
from autogpt.core.resource.model_providers import ( | ||
AssistantFunctionCall, | ||
ChatMessage, | ||
|
@@ -48,13 +49,18 @@ | |
UnknownCommandError, | ||
) | ||
|
||
from .base import BaseAgent, BaseAgentConfiguration, BaseAgentSettings | ||
from .base import ( | ||
BaseAgent, | ||
BaseAgentActionProposal, | ||
BaseAgentConfiguration, | ||
BaseAgentSettings, | ||
) | ||
from .features.agent_file_manager import FileManagerComponent | ||
from .features.context import AgentContext, ContextComponent | ||
from .features.watchdog import WatchdogComponent | ||
from .prompt_strategies.one_shot import ( | ||
OneShotAgentActionProposal, | ||
OneShotAgentPromptStrategy, | ||
from .prompt_strategies.code_flow import ( | ||
CodeFlowAgentPromptStrategy, | ||
CodeFlowAgentActionProposal, | ||
) | ||
from .protocols import ( | ||
AfterExecute, | ||
|
@@ -77,8 +83,8 @@ | |
class AgentSettings(BaseAgentSettings): | ||
config: AgentConfiguration = Field(default_factory=AgentConfiguration) | ||
|
||
history: EpisodicActionHistory[OneShotAgentActionProposal] = Field( | ||
default_factory=EpisodicActionHistory[OneShotAgentActionProposal] | ||
history: EpisodicActionHistory[BaseAgentActionProposal] = Field( | ||
default_factory=EpisodicActionHistory[BaseAgentActionProposal] | ||
) | ||
"""(STATE) The action history of the agent.""" | ||
|
||
|
@@ -97,19 +103,20 @@ | |
llm_provider: ChatModelProvider, | ||
file_storage: FileStorage, | ||
legacy_config: Config, | ||
prompt_strategy_class: type[PromptStrategy] = CodeFlowAgentPromptStrategy, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. decouple agent.py & OneShot. pass this class for custom prompt strategy |
||
): | ||
super().__init__(settings) | ||
|
||
self.llm_provider = llm_provider | ||
self.ai_profile = settings.ai_profile | ||
self.directives = settings.directives | ||
prompt_config = OneShotAgentPromptStrategy.default_configuration.copy(deep=True) | ||
prompt_config = prompt_strategy_class.default_configuration.copy(deep=True) | ||
prompt_config.use_functions_api = ( | ||
settings.config.use_functions_api | ||
# Anthropic currently doesn't support tools + prefilling :( | ||
and self.llm.provider_name != "anthropic" | ||
) | ||
self.prompt_strategy = OneShotAgentPromptStrategy(prompt_config, logger) | ||
self.prompt_strategy = prompt_strategy_class(prompt_config, logger) | ||
self.commands: list[Command] = [] | ||
|
||
# Components | ||
|
@@ -136,6 +143,7 @@ | |
self.web_selenium = WebSeleniumComponent(legacy_config, llm_provider, self.llm) | ||
self.context = ContextComponent(self.file_manager.workspace, settings.context) | ||
self.watchdog = WatchdogComponent(settings.config, settings.history) | ||
self.code_flow_executor = CodeFlowExecutionComponent() | ||
|
||
self.created_at = datetime.now().strftime("%Y%m%d_%H%M%S") | ||
"""Timestamp the agent was created; only used for structured debug logging.""" | ||
|
@@ -146,7 +154,7 @@ | |
self.event_history = settings.history | ||
self.legacy_config = legacy_config | ||
|
||
async def propose_action(self) -> OneShotAgentActionProposal: | ||
async def propose_action(self) -> BaseAgentActionProposal: | ||
"""Proposes the next action to execute, based on the task and current state. | ||
|
||
Returns: | ||
|
@@ -167,6 +175,7 @@ | |
# Get commands | ||
self.commands = await self.run_pipeline(CommandProvider.get_commands) | ||
self._remove_disabled_commands() | ||
self.code_flow_executor.set_available_functions(self.commands) | ||
|
||
# Get messages | ||
messages = await self.run_pipeline(MessageProvider.get_messages) | ||
|
@@ -197,12 +206,12 @@ | |
|
||
async def complete_and_parse( | ||
self, prompt: ChatPrompt, exception: Optional[Exception] = None | ||
) -> OneShotAgentActionProposal: | ||
) -> BaseAgentActionProposal: | ||
if exception: | ||
prompt.messages.append(ChatMessage.system(f"Error: {exception}")) | ||
|
||
response: ChatModelResponse[ | ||
OneShotAgentActionProposal | ||
BaseAgentActionProposal | ||
] = await self.llm_provider.create_chat_completion( | ||
prompt.messages, | ||
model_name=self.llm.name, | ||
|
@@ -226,7 +235,7 @@ | |
|
||
async def execute( | ||
self, | ||
proposal: OneShotAgentActionProposal, | ||
proposal: BaseAgentActionProposal, | ||
user_feedback: str = "", | ||
) -> ActionResult: | ||
tool = proposal.use_tool | ||
|
@@ -260,7 +269,7 @@ | |
return result | ||
|
||
async def do_not_execute( | ||
self, denied_proposal: OneShotAgentActionProposal, user_feedback: str | ||
self, denied_proposal: BaseAgentActionProposal, user_feedback: str | ||
) -> ActionResult: | ||
result = ActionInterruptedByHuman(feedback=user_feedback) | ||
self.log_cycle_handler.log_cycle( | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OneShotAgentActionProposal is not part of .agent