Files
Auto-GPT/autogpt/models/context_item.py
Reinier van der Leer 3fe2246468 Agent loop v2: Prompting improvements & WIP planning (#5077)
* Add categories to command registry

* Fix tests

* Clean up prompt generation

* Rename Performance Evaluations to Best Practices
* Move specification of response format from system prompt to Agent.construct_base_prompt
* Clean up PromptGenerator class

* Add debug logging to AIConfig autogeneration

* Clarify prompting and add support for multiple thought processes to Agent

* WIP: PlanningAgent

* Disable message history by default on BaseAgent

* Add CommandOutput and ThoughtProcessOutput type aliases

* Fix interrupts in main.py

* Use custom exceptions and clean up exception/error handling

* Remove duplicate agent_history.py

* Update PlanningAgent from upstream

* WIP: Support for dynamic in-prompt context

* WIP: response formats for PlanningAgent three-stage cycle

* Remove browsing overlay & separate browsing from extraction code

* Fix human feedback

* Fix tests

* Include history in Agent prompt generation

* Code improvements in agent.py

* Add ask_user command and revise system prompt
2023-08-19 17:44:50 +02:00

77 lines
1.7 KiB
Python

from abc import ABC, abstractmethod
from dataclasses import dataclass
from pathlib import Path
from typing import Optional
class ContextItem(ABC):
@property
@abstractmethod
def description(self) -> str:
"""Description of the context item"""
...
@property
@abstractmethod
def source(self) -> Optional[str]:
"""A string indicating the source location of the context item"""
...
@property
@abstractmethod
def content(self) -> str:
"""The content represented by the context item"""
...
def __str__(self) -> str:
return (
f"{self.description} (source: {self.source})\n"
"```\n"
f"{self.content}\n"
"```"
)
@dataclass
class FileContextItem(ContextItem):
file_path: Path
description: str
@property
def source(self) -> str:
return f"local file '{self.file_path}'"
@property
def content(self) -> str:
return self.file_path.read_text()
@dataclass
class FolderContextItem(ContextItem):
path: Path
def __post_init__(self) -> None:
assert self.path.exists(), "Selected path does not exist"
assert self.path.is_dir(), "Selected path is not a directory"
@property
def description(self) -> str:
return f"The contents of the folder '{self.path}' in the workspace"
@property
def source(self) -> str:
return f"local folder '{self.path}'"
@property
def content(self) -> str:
items = [f"{p.name}{'/' if p.is_dir() else ''}" for p in self.path.iterdir()]
items.sort()
return "\n".join(items)
@dataclass
class StaticContextItem(ContextItem):
description: str
source: Optional[str]
content: str