aboutsummaryrefslogtreecommitdiff
path: root/autogpts/autogpt/autogpt/agents/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'autogpts/autogpt/autogpt/agents/base.py')
-rw-r--r--autogpts/autogpt/autogpt/agents/base.py58
1 files changed, 30 insertions, 28 deletions
diff --git a/autogpts/autogpt/autogpt/agents/base.py b/autogpts/autogpt/autogpt/agents/base.py
index 1dd9ac493..846427ae7 100644
--- a/autogpts/autogpt/autogpt/agents/base.py
+++ b/autogpts/autogpt/autogpt/agents/base.py
@@ -12,6 +12,7 @@ if TYPE_CHECKING:
from autogpt.config import Config
from autogpt.core.prompting.base import PromptStrategy
from autogpt.core.resource.model_providers.schema import (
+ AssistantChatMessage,
ChatModelInfo,
ChatModelProvider,
ChatModelResponse,
@@ -124,7 +125,7 @@ class BaseAgentConfiguration(SystemConfiguration):
class BaseAgentSettings(SystemSettings):
- agent_id: Optional[str] = None
+ agent_id: str = ""
agent_data_dir: Optional[Path] = None
ai_profile: AIProfile = Field(default_factory=lambda: AIProfile(ai_name="AutoGPT"))
@@ -230,10 +231,7 @@ class BaseAgent(Configurable[BaseAgentSettings], ABC):
return self.config.send_token_limit or self.llm.max_tokens * 3 // 4
async def propose_action(self) -> ThoughtProcessOutput:
- """Runs the agent for one cycle.
-
- Params:
- instruction: The instruction to put at the end of the prompt.
+ """Proposes the next action to execute, based on the task and current state.
Returns:
The command name and arguments, if any, and the agent's thoughts.
@@ -250,7 +248,7 @@ class BaseAgent(Configurable[BaseAgentSettings], ABC):
prompt = self.on_before_think(prompt, scratchpad=self._prompt_scratchpad)
logger.debug(f"Executing prompt:\n{dump_prompt(prompt)}")
- raw_response = await self.llm_provider.create_chat_completion(
+ response = await self.llm_provider.create_chat_completion(
prompt.messages,
functions=get_openai_command_specs(
self.command_registry.list_available_commands(self)
@@ -259,11 +257,16 @@ class BaseAgent(Configurable[BaseAgentSettings], ABC):
if self.config.use_functions_api
else [],
model_name=self.llm.name,
+ completion_parser=lambda r: self.parse_and_process_response(
+ r,
+ prompt,
+ scratchpad=self._prompt_scratchpad,
+ ),
)
self.config.cycle_count += 1
return self.on_response(
- llm_response=raw_response,
+ llm_response=response,
prompt=prompt,
scratchpad=self._prompt_scratchpad,
)
@@ -283,7 +286,7 @@ class BaseAgent(Configurable[BaseAgentSettings], ABC):
user_input: The user's input, if any.
Returns:
- The results of the command.
+ ActionResult: An object representing the result(s) of the command.
"""
...
@@ -294,13 +297,13 @@ class BaseAgent(Configurable[BaseAgentSettings], ABC):
extra_messages: Optional[list[ChatMessage]] = None,
**extras,
) -> ChatPrompt:
- """Constructs and returns a prompt with the following structure:
- 1. System prompt
- 2. Message history of the agent, truncated & prepended with running summary as needed
- 3. `cycle_instruction`
+ """Constructs a prompt using `self.prompt_strategy`.
Params:
- cycle_instruction: The final instruction for a thinking cycle
+ scratchpad: An object for plugins to write additional prompt elements to.
+ (E.g. commands, constraints, best practices)
+ extra_commands: Additional commands that the agent has access to.
+ extra_messages: Additional messages to include in the prompt.
"""
if not extra_commands:
extra_commands = []
@@ -349,7 +352,9 @@ class BaseAgent(Configurable[BaseAgentSettings], ABC):
output to the prompt.
Params:
- instruction: The instruction for the current cycle, also used in constructing the prompt
+ prompt: The prompt that is about to be executed.
+ scratchpad: An object for plugins to write additional prompt elements to.
+ (E.g. commands, constraints, best practices)
Returns:
The prompt to execute
@@ -386,30 +391,26 @@ class BaseAgent(Configurable[BaseAgentSettings], ABC):
) -> ThoughtProcessOutput:
"""Called upon receiving a response from the chat model.
- Adds the last/newest message in the prompt and the response to `history`,
- and calls `self.parse_and_process_response()` to do the rest.
+ Calls `self.parse_and_process_response()`.
Params:
- llm_response: The raw response from the chat model
- prompt: The prompt that was executed
- instruction: The instruction for the current cycle, also used in constructing the prompt
+ llm_response: The raw response from the chat model.
+ prompt: The prompt that was executed.
+ scratchpad: An object containing additional prompt elements from plugins.
+ (E.g. commands, constraints, best practices)
Returns:
The parsed command name and command args, if any, and the agent thoughts.
"""
- return self.parse_and_process_response(
- llm_response,
- prompt,
- scratchpad=scratchpad,
- )
+ return llm_response.parsed_result
# TODO: update memory/context
@abstractmethod
def parse_and_process_response(
self,
- llm_response: ChatModelResponse,
+ llm_response: AssistantChatMessage,
prompt: ChatPrompt,
scratchpad: PromptScratchpad,
) -> ThoughtProcessOutput:
@@ -419,9 +420,10 @@ class BaseAgent(Configurable[BaseAgentSettings], ABC):
since the implementation depends on the role of the derivative Agent.
Params:
- llm_response: The raw response from the chat model
- prompt: The prompt that was executed
- instruction: The instruction for the current cycle, also used in constructing the prompt
+ llm_response: The raw response from the chat model.
+ prompt: The prompt that was executed.
+ scratchpad: An object containing additional prompt elements from plugins.
+ (E.g. commands, constraints, best practices)
Returns:
The parsed command name and command args, if any, and the agent thoughts.