Skip to content

Commit

Permalink
New models, hints, bugfixes, prompt adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
frdel committed Aug 4, 2024
1 parent b6e3216 commit 35267ec
Show file tree
Hide file tree
Showing 15 changed files with 363 additions and 209 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
- No coding is required, only prompting and communication skills.
- With a solid system prompt, the framework is reliable even with small models, including precise tool usage.

![Time example](docs/time_example.jpg)

## Keep in mind
1. **Agent Zero can be dangerous!**
With proper instruction, Agent Zero is capable of many things, even potentially dangerous to your computer, data, or accounts. Always run Agent Zero in an isolated environment (like the built in docker container) and be careful what you wish for.
Expand All @@ -64,6 +62,8 @@ If your agent fails to communicate properly, use tools, reason, use memory, find
Agent Zero is made to be used in an isolated virtual environment (for safety) with some tools preinstalled and configured.
If you cannot provide all the necessary conditions or API keys, just change the system prompt and tell your agent what operating system and tools are at its disposal. Nothing is hard-coded; if you do not tell your agent about a certain tool, it will not know about it and will not try to use it.

[![David Ondrej video](/docs/david_vid.jpg)](https://www.youtube.com/watch?v=_Pionjv4hGc)

## Known problems
1. The system prompt sucks. You can do better. If you do, help me please :)
2. The communication between agent and terminal in docker container via SSH can sometimes break and stop producing outputs. Sometimes it is because the agent runs something like "server.serve_forever()" which causes the terminal to hang, sometimes a random error can occur. Restarting the agent and/or the docker container helps.
Expand All @@ -74,7 +74,12 @@ If you cannot provide all the necessary conditions or API keys, just change the
- **Python**: Python has to be installed on the system to run the framework.
- **Internet access**: The agent will need internet access to use its online knowledge tool and execute commands and scripts requiring a connection. If you do not need your agent to be online, you can alter its prompts in the **prompts/** folder and make it fully local.

![Time example](docs/time_example.jpg)

## Setup

Update: [Guide by CheezChat for Windows](./docs/win_installation_guide.txt)

1. **Required API keys:**
- At the moment, the only recommended API key is for https://www.perplexity.ai/ API. Perplexity is used as a convenient web search tool and has not yet been replaced by an open-source alternative. If you do not have an API key for Perplexity, leave it empty in the .env file and Perplexity will not be used.
- Chat models and embedding models can be executed locally via Ollama and HuggingFace or via API as well.
Expand Down
9 changes: 5 additions & 4 deletions agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_core.messages import HumanMessage, SystemMessage
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.language_models.llms import BaseLLM
from langchain_core.embeddings import Embeddings

@dataclass
class AgentConfig:
chat_model:BaseChatModel
utility_model: BaseChatModel
chat_model: BaseChatModel | BaseLLM
utility_model: BaseChatModel | BaseLLM
embeddings_model:Embeddings
memory_subdir: str = ""
auto_memory_count: int = 3
Expand Down Expand Up @@ -53,8 +54,8 @@ def __init__(self, number:int, config: AgentConfig):
self.number = number
self.agent_name = f"Agent {self.number}"

self.system_prompt = files.read_file("./prompts/agent.system.md").replace("{", "{{").replace("}", "}}")
self.tools_prompt = files.read_file("./prompts/agent.tools.md").replace("{", "{{").replace("}", "}}")
self.system_prompt = files.read_file("./prompts/agent.system.md", agent_name=self.agent_name)
self.tools_prompt = files.read_file("./prompts/agent.tools.md")

self.history = []
self.last_message = ""
Expand Down
Binary file added docs/david_vid.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
194 changes: 194 additions & 0 deletions docs/win_installation_guide.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@

## Setup

### General Installation Information

Start here if you are experienced using Python, Docker, Environments, installing requirements, and working with a Github project.

1. **Required API keys:**

At the moment, the only recommended API key is for https://www.perplexity.ai/ API. Perplexity is used as a convenient web search tool and has not yet been replaced by an open-source alternative. If you do not have an API key for Perplexity, leave it empty in the .env file and Perplexity will not be used.

Note: Chat models and embedding models can be executed locally via Ollama, LMStudio and HuggingFace or via API as well.

2. **Enter your API keys:**

Enter your API keys into a **.env** file, which is a file used to keep your API keys private. Create the file in the agent-zero root folder or duplicate and rename the included **example.env**. The example file included contains examples for entering each API key type, shown below.

~~~.env
API_KEY_OPENAI=YOUR-API-KEY-HERE
API_KEY_ANTHROPIC=
API_KEY_GROQ=
API_KEY_PERPLEXITY=
API_KEY_GOOGLE=

TOKENIZERS_PARALLELISM=true
PYDEVD_DISABLE_FILE_VALIDATION=1
~~~

Or you can export your API keys in the terminal session:

~~~bash
export API_KEY_PERPLEXITY="your-api-key-here"
export API_KEY_OPENAI="your-api-key-here"
~~~

3. **Install Dependencies:**

~~~bash
pip install -r requirements.txt
~~~

1. **Choose your chat, utility and embeddings model:**
- In the **main.py** file, right at the start of the **chat()** function, you can see how the chat model and embedding model are set.
- You can choose between online models (OpenAI, Anthropic, Groq) or offline (Ollama, HuggingFace) for both.

1. **Run Docker:**
- Easiest way is to install Docker Desktop application and just run it. The rest will be handled by the framework itself.

## Run the program
- Just run the **main.py** file in Python:
~~~bash
python main.py
~~~
- Or run it in debug mode in VS Code using the **debug** button in the top right corner of the editor. I have provided config files for VS Code for this purpose.


### Windows Installation Tips & Quick-Start

Start here for a step-by-step with explanations.

1. **Download and Install Anaconda**

* We're going to install something called an environment manager. The environment manager has a GUI and although it looks complicated, it's pretty easy to set up.
* An Environment is a way of using Python that lets you use different software versions and requirements for different programs. An Environment Manager lets you create and switch between the different environments.
* Follow the excellent guide here: **How To Install Anaconda**. https://www.askpython.com/python/examples/install-python-with-conda
* or Download and install Anaconda Distribution directly if you prefer https://www.anaconda.com/download/
* Your computer will need to reboot at least once or twice and you will need Administrator access.
2. **Create an Anaconda Environment**

* Open Anaconda Navigator.
* On the left hand side, click **Environments**
* You will see an existing environment called base(root)
* At the bottom of the middle column, click **Create**
* Name the environment **Agent-Zero**
* Select **Python** package
* Select version **3.11.9** from the dropdown
* Click **Create**
* **Wait**

At the bottom right you will see a flashing blue progress bar while Anaconda creates your environment. This process installs Python and a basic set of common packages. It should only take a few minutes.

* Wait for installation of the environment to finish
* In the middle column you should see your new environment
* Click the green circle with the white triangle inside of it and select **Open Terminal**
* A system terminal window should open and you should see something like this:
```(Agent-Zero) C:\Users\yourUserName>```
* The (Agent-Zero) at the beginning of the prompt tells you that you are running inside of the Agent-Zero environment that you created

* confirm that python is functioning properly by typing:
```
(Agent-Zero) C:\Users\yourUserName>python --version
Python 3.11.9
```
If your terminal window replies with the Python version number as shown above, you have succeeded installing Anaconda and Python. Great work! Get a snack.

1. **Download Agent-Zero**

If you have already downloaded the zip file archive of the Agent-Zero project, skip ahead.

* Click the green button labeled **<> Code** at the top of the agent-zero github page
* Click **Download Zip**
* **Unzip** the entire contents of the file to a **folder on your computer**

4. **Download Docker Desktop**

Docker is a program that allows you to create unique environments for your applications. The advantage to this is that the programs running in Docker cannot have any access to your computer unless you specifically allow it. https://www.docker.com/products/docker-desktop/

Agent-Zero uses Docker to run programs because it can do so safely. If there are errors, your computer won't be affected.

* Install Docker Desktop using the link above
* Use default settings
* Reboot as required by the installer
* That's it for Docker! Agent-Zero will do the rest with Docker. It's pretty cool.

5. **Configure Agent-Zero**

* Right Click on the file **example.env** in the Agent-Zero root folder
* Select **Open With**
* Select **Notepad** or your preferred text editor
* You should see a small text file that resembles this:
~~~example.env
API_KEY_OPENAI=YOUR-API-KEY-HERE
API_KEY_ANTHROPIC=
API_KEY_GROQ=
API_KEY_PERPLEXITY=
API_KEY_GOOGLE=

TOKENIZERS_PARALLELISM=true
PYDEVD_DISABLE_FILE_VALIDATION=1
~~~
* Select File | **Save as... **
* From the **Save as Type** drop-down at the bottom of the Save As dialog window, select **Save as Type All Files**
* Name the file **.env** and select **save**
* Enter your API key(s) for your preferred models (https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key)
* Save and Close your new .env file
* Note that the file should be simply ".env" and you might not even be able to see it

!!! If you see a file named .env.txt that is **wrong** Make sure to select the type All Files when saving.

6. Configure API Preferences

If you entered an openAI API key earlier, you may skip this step. If you entered an alternative key,
* Right Click on the file **main.py** in the Agent-Zero root folder
* Select **Open With**
* Select **Notepad** or your preferred text editor
* Scroll about 20 lines down from the top until you see lines that look like this: *chat_llm = models.get_*
* Comment out the openAI model and enable the model that corresponds to your API key
* Save

1. **Install Requirements (Dependencies)**

* Open **Anaconda Navigator** and navigate to your Environment
* Click the green circle with the white triangle inside of it and select **Open Terminal**

* Reopen your new environment's **terminal window**
* Click the green circle with the white triangle inside of it and select **Open Terminal**
* A system terminal window should open and you should see something like this

~~~
(Agent-Zero) C:\Users\yourUserName>
~~~

* Navigate to the agent-zero folder

~~~
(Agent-Zero) C:\Users\yourUserName>cd c:\projects\agent-zero
~~~

* Install the necessary packages required by Agent-Zero from the file requirements.txt. The requirements file has a list of specific software needed for agent-zero to operate. We will be using "pip", a tool for downloading software for Python.

~~~
(Agent-Zero) C:\projects\agent-zero>pip install -r requirements.txt
~~~

* You will see a ton of text scrolling down the screen while pip downloads and installs your software.
* It will take a while. Be patient.
* pip is finished when you see your command prompt again at the bottom of the screen

If all of the requirements installed succesfully, you can proceed to run the program.

* Open Anaconda Navigator
* Activate the Agent-Zero environment by double clicking on its name
* click Open Terminal
* Navigate to the agent-zero folder
* Type **python main.py** and press enter

```
(Agent-Zero) C:\Users\yourUserName>cd c:\projects\agent-zero
(Agent-Zero) C:\projects\agent-zero\python main.py
Initializing framework...

User message ('e' to leave):

```
4 changes: 4 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ API_KEY_PERPLEXITY=
API_KEY_GOOGLE=
API_KEY_OPENROUTER=

API_KEY_OPENAI_AZURE=
OPENAI_AZURE_ENDPOINT=
OPENAI_API_VERSION=

TOKENIZERS_PARALLELISM=true
PYDEVD_DISABLE_FILE_VALIDATION=1
36 changes: 13 additions & 23 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,22 @@
def initialize():

# main chat model used by agents (smarter, more accurate)

# chat_llm = models.get_groq_llama70b(temperature=0.2)
# chat_llm = models.get_groq_llama70b_json(temperature=0.2)
# chat_llm = models.get_groq_llama8b(temperature=0.2)
# chat_llm = models.get_openai_gpt35(temperature=0)
# chat_llm = models.get_openai_gpt4o(temperature=0)
chat_llm = models.get_openai_chat(temperature=0)
# chat_llm = models.get_anthropic_opus(temperature=0)
# chat_llm = models.get_anthropic_sonnet(temperature=0)
# chat_llm = models.get_anthropic_sonnet_35(temperature=0)
# chat_llm = models.get_anthropic_haiku(temperature=0)
# chat_llm = models.get_ollama_dolphin()
# chat_llm = models.get_ollama(model_name="gemma2:27b")
# chat_llm = models.get_ollama(model_name="llama3:8b-text-fp16")
# chat_llm = models.get_ollama(model_name="gemma2:latest")
# chat_llm = models.get_ollama(model_name="qwen:14b")
chat_llm = models.get_openai_chat(model_name="gpt-4o-mini", temperature=0)
# chat_llm = models.get_ollama_chat(model_name="gemma2:latest", temperature=0)
# chat_llm = models.get_lmstudio_chat(model_name="TheBloke/Mistral-7B-Instruct-v0.2-GGUF", temperature=0)
# chat_llm = models.get_openrouter(model_name="meta-llama/llama-3-8b-instruct:free")
# chat_llm = models.get_google_chat()


# utility model used for helper functions (cheaper, faster)
utility_llm = models.get_openai_chat(temperature=0)
# chat_llm = models.get_azure_openai_chat(deployment_name="gpt-4o-mini", temperature=0)
# chat_llm = models.get_anthropic_chat(model_name="claude-3-5-sonnet-20240620", temperature=0)
# chat_llm = models.get_google_chat(model_name="gemini-1.5-flash", temperature=0)
# chat_llm = models.get_groq_chat(model_name="llama-3.1-70b-versatile", temperature=0)

# utility model used for helper functions (cheaper, faster)
utility_llm = chat_llm # change if you want to use a different utility model

# embedding model used for memory
embedding_llm = models.get_embedding_openai()
# embedding_llm = models.get_embedding_hf()
embedding_llm = models.get_openai_embedding(model_name="text-embedding-3-small")
# embedding_llm = models.get_ollama_embedding(model_name="nomic-embed-text")
# embedding_llm = models.get_huggingface_embedding(model_name="sentence-transformers/all-MiniLM-L6-v2")

# agent configuration
config = AgentConfig(
Expand Down
Loading

0 comments on commit 35267ec

Please sign in to comment.