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): Introduce Python code execution as prompt strategy #7142

Draft
wants to merge 53 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
ed5f12c
Add code validation
majdyz May 10, 2024
ca7ca22
one_shot_flow.ipynb + edits to make it work
Pwuts May 10, 2024
ef1fe7c
Update notebook
majdyz May 11, 2024
40426e4
Merge master
majdyz May 14, 2024
22e2373
Add code flow as a loop
majdyz May 15, 2024
0916df4
Fix async fiasco
majdyz May 15, 2024
0eccbe1
Prompt change
majdyz May 15, 2024
f763452
More prompt engineering
majdyz May 16, 2024
ea134c7
Benchmark test
majdyz May 16, 2024
7b5272f
Fix Await fiasco
majdyz May 16, 2024
922e643
Fix Await fiasco
majdyz May 16, 2024
fb80240
Add return type
majdyz May 17, 2024
834eb6c
Some quality polishing
majdyz May 20, 2024
81ad3cb
Merge conflicts
majdyz May 20, 2024
47eeaf0
Revert dumb changes
majdyz May 20, 2024
3c4ff60
Add unit tests
majdyz May 20, 2024
9f6e256
Debug Log changes
majdyz May 20, 2024
dfa7773
Remove unnecessary changes
majdyz May 20, 2024
3a60504
isort
majdyz May 20, 2024
c8e16f3
Fix linting
majdyz May 20, 2024
ae43136
Fix linting
majdyz May 20, 2024
a825aa8
Merge branch 'master' into zamilmajdy/code-validation
majdyz May 20, 2024
fdd9f9b
Log fix
majdyz May 20, 2024
ae63aa8
Merge remote-tracking branch 'origin/zamilmajdy/code-validation' into…
majdyz May 20, 2024
5c7c276
Merge branch 'master' into zamilmajdy/code-validation
Pwuts Jun 3, 2024
fcca4cc
clarify execute_code_flow
Pwuts Jun 3, 2024
6e715b6
simplify function header generation
Pwuts Jun 7, 2024
b4cd735
fix name collision with `type` in `Command.return_type`
Pwuts Jun 7, 2024
731d034
implement annotation expansion for non-builtin types
Pwuts Jun 8, 2024
0578fb0
fix async issues with code flow execution
Pwuts Jun 8, 2024
c3acb99
clean up `forge.command.command`
Pwuts Jun 8, 2024
6dd0975
clean up & improve `@command` decorator
Pwuts Jun 8, 2024
e264bf7
`forge.llm.providers.schema` + `code_flow_executor` lint-fix and cleanup
Pwuts Jun 8, 2024
8144d26
fix type issues
Pwuts Jun 8, 2024
111e858
feat(forge/llm): allow async completion parsers
Pwuts Jun 8, 2024
3e8849b
fix linting and type issues
Pwuts Jun 8, 2024
2c6e1eb
fix type issue in test_code_flow_strategy.py
Pwuts Jun 8, 2024
a9eb49d
Merge branch 'master' into zamilmajdy/code-validation
Pwuts Jun 8, 2024
81bac30
fix type issues
Pwuts Jun 8, 2024
b59862c
Address comment
majdyz Jun 10, 2024
3597f80
Merge branch 'master' of github.com:Significant-Gravitas/AutoGPT into…
majdyz Jun 10, 2024
e204491
Merge branch 'master' into zamilmajdy/code-validation
ntindle Jun 13, 2024
901dade
Merge branch 'master' into zamilmajdy/code-validation
kcze Jun 19, 2024
680fbf4
Merge branch 'master' into zamilmajdy/code-validation
Pwuts Jun 25, 2024
9f80408
address feedback: pass commands getter to CodeFlowExecutionComponent(..)
Pwuts Jun 25, 2024
37cc047
lint-fix + minor refactor
Pwuts Jun 25, 2024
3e67512
Merge branch 'master' into zamilmajdy/code-validation
Pwuts Jun 27, 2024
6d9f564
Merge branch 'master' into zamilmajdy/code-validation
Pwuts Jul 2, 2024
38eafdb
Update `CodeFlowPromptStrategy` with upstream changes (#7223)
Pwuts Jul 2, 2024
736ac77
Merge branch 'master' into zamilmajdy/code-validation
Pwuts Jul 2, 2024
7f6b7d6
remove unused import in forge/llm/providers/openai.py
Pwuts Jul 2, 2024
8b1d416
Merge branch 'master' into zamilmajdy/code-validation
Pwuts Jul 4, 2024
2c4afd4
Migrate `autogpt/agents/prompt_strategies/code_flow.py` to Pydantic v2
Pwuts Jul 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion autogpts/autogpt/autogpt/agents/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .agent import Agent, OneShotAgentActionProposal
from .agent import Agent
from .base import BaseAgent, BaseAgentActionProposal
from .prompt_strategies.one_shot import OneShotAgentActionProposal

Copy link
Contributor Author

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

__all__ = [
"BaseAgent",
Expand Down
37 changes: 23 additions & 14 deletions autogpts/autogpt/autogpt/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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."""

Expand All @@ -97,19 +103,20 @@
llm_provider: ChatModelProvider,
file_storage: FileStorage,
legacy_config: Config,
prompt_strategy_class: type[PromptStrategy] = CodeFlowAgentPromptStrategy,
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand All @@ -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."""
Expand All @@ -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:
Expand All @@ -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)

Check warning on line 178 in autogpts/autogpt/autogpt/agents/agent.py

View check run for this annotation

Codecov / codecov/patch

autogpts/autogpt/autogpt/agents/agent.py#L178

Added line #L178 was not covered by tests

# Get messages
messages = await self.run_pipeline(MessageProvider.get_messages)
Expand Down Expand Up @@ -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,
Expand All @@ -226,7 +235,7 @@

async def execute(
self,
proposal: OneShotAgentActionProposal,
proposal: BaseAgentActionProposal,
user_feedback: str = "",
) -> ActionResult:
tool = proposal.use_tool
Expand Down Expand Up @@ -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(
Expand Down
Loading
Loading