Skip to content

Commit 79826b9

Browse files
committed
Merge branch 'testing'
2 parents cf244e2 + eb9411e commit 79826b9

File tree

93 files changed

+3880
-846
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+3880
-846
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
**/__pycache__/
55
**/.conda/
66

7+
# ignore test files in root dir
8+
/*.test.py
9+
710
# Ignore git internal files (for bundler)
811
.git/
912

.vscode/launch.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"request": "launch",
88
"program": "./run_ui.py",
99
"console": "integratedTerminal",
10+
"justMyCode": false,
1011
"args": ["--development=true", "-Xfrozen_modules=off"]
1112
},
1213
{
@@ -15,6 +16,7 @@
1516
"request": "launch",
1617
"program": "./run_cli.py",
1718
"console": "integratedTerminal",
19+
"justMyCode": false,
1820
"args": ["--development=true", "-Xfrozen_modules=off"]
1921
},
2022
{
@@ -23,6 +25,7 @@
2325
"request": "launch",
2426
"program": "${file}",
2527
"console": "integratedTerminal",
28+
"justMyCode": false,
2629
"args": ["--development=true", "-Xfrozen_modules=off"]
2730
}
2831
]

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
# `Agent Zero`
66

7-
[![Join our Skool Community](https://img.shields.io/badge/Skool-Join%20our%20Community-4A90E2?style=for-the-badge&logo=skool&logoColor=white)](https://www.skool.com/agent-zero) [![Join our Discord](https://img.shields.io/badge/Discord-Join%20our%20server-5865F2?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/B8KZKNsPpj) [![Subscribe on YouTube](https://img.shields.io/badge/YouTube-Subscribe-red?style=for-the-badge&logo=youtube&logoColor=white)](https://www.youtube.com/@AgentZeroFW) [![Connect on LinkedIn](https://img.shields.io/badge/LinkedIn-Connect-blue?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/jan-tomasek/) [![Follow on X.com](https://img.shields.io/badge/X.com-Follow-1DA1F2?style=for-the-badge&logo=x&logoColor=white)](https://x.com/JanTomasekDev)
7+
[![Thanks to Sponsors](https://img.shields.io/badge/GitHub%20Sponsors-Thanks%20to%20Sponsors-FF69B4?style=for-the-badge&logo=githubsponsors&logoColor=white)](https://github.com/sponsors/frdel) [![Join our Skool Community](https://img.shields.io/badge/Skool-Join%20our%20Community-4A90E2?style=for-the-badge&logo=skool&logoColor=white)](https://www.skool.com/agent-zero) [![Join our Discord](https://img.shields.io/badge/Discord-Join%20our%20server-5865F2?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/B8KZKNsPpj) [![Subscribe on YouTube](https://img.shields.io/badge/YouTube-Subscribe-red?style=for-the-badge&logo=youtube&logoColor=white)](https://www.youtube.com/@AgentZeroFW) [![Connect on LinkedIn](https://img.shields.io/badge/LinkedIn-Connect-blue?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/jan-tomasek/) [![Follow on X.com](https://img.shields.io/badge/X.com-Follow-1DA1F2?style=for-the-badge&logo=x&logoColor=white)](https://x.com/JanTomasekDev)
8+
89

910
[Installation](./docs/installation.md)
1011
[How to update](./docs/installation.md#how-to-update-agent-zero)
@@ -13,6 +14,10 @@
1314

1415
</div>
1516

17+
> [!NOTE]
18+
> **🎉 v0.8.1 Release**: Now featuring a browser agent capable of using Chromium for web interactions! This enables Agent Zero to browse the web, gather information, and interact with web content autonomously.
19+
20+
1621
https://github.com/user-attachments/assets/c168759d-57d8-4b43-b62a-1026afcf52e6
1722

1823
## A personal, organic agentic framework that grows and learns with you
@@ -119,19 +124,10 @@ docker run -p 50001:80 frdel/agent-zero-run
119124

120125
- With proper instruction, Agent Zero is capable of many things, even potentially dangerous actions concerning your computer, data, or accounts. Always run Agent Zero in an isolated environment (like Docker) and be careful what you wish for.
121126

122-
2. **Agent Zero Is Not Pre-programmed; It Is Prompt-based.**
123-
124-
- The whole framework contains only a minimal amount of code and does not guide the agent in any way. Everything lies in the system prompt located in the **prompts/** folder.
127+
2. **Agent Zero Is Prompt-based.**
125128

126-
3. **If You Cannot Provide the Ideal Environment, Let Your Agent Know.**
129+
- The whole framework is guided by the **prompts/** folder. Agent guidelines, tool instructions, messages, utility AI functions, it's all there.
127130

128-
- Agent Zero is made to be used in an isolated virtual environment (for safety) with some tools preinstalled and configured.
129-
130-
### 📌 Known Problems
131-
132-
1. The system prompt may need improvements; contributions are welcome!
133-
2. The agent may inadvertently alter its operating environment; cleaning up the `work_dir` often fixes this.
134-
3. Agents might loop in multi-agentic interactions, leading to unexpected behaviors.
135131

136132
## 📚 Read the Documentation
137133

@@ -147,15 +143,19 @@ docker run -p 50001:80 frdel/agent-zero-run
147143

148144
### Coming soon
149145

150-
- **User Interaction Refinements**
151-
- **Browser Use and RAG Tools**
146+
- **Knowledge and RAG Tools**
147+
- **Planning and Scheduling**
152148

153149
> [!IMPORTANT]
154150
>
155151
>**Changes to frdel/agent-zero Docker image since v0.7:**
156152
>
157153
> The new Docker image `frdel/agent-zero-run` provides the new unified environment.
158154
155+
### v0.8.1
156+
- **Browser Agent**
157+
- **UX Improvements**
158+
159159
### v0.8
160160

161161
- **Docker Runtime**

agent.py

Lines changed: 57 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from dataclasses import dataclass, field
44
import time, importlib, inspect, os, json
55
import token
6-
from typing import Any, Awaitable, Optional, Dict, TypedDict
6+
from typing import Any, Awaitable, Coroutine, Optional, Dict, TypedDict
77
import uuid
88
import models
99

@@ -44,7 +44,7 @@ def __init__(
4444
self.agent0 = agent0 or Agent(0, self.config, self)
4545
self.paused = paused
4646
self.streaming_agent = streaming_agent
47-
self.process: DeferredTask | None = None
47+
self.task: DeferredTask | None = None
4848
AgentContext._counter += 1
4949
self.no = AgentContext._counter
5050

@@ -66,13 +66,13 @@ def first():
6666
@staticmethod
6767
def remove(id: str):
6868
context = AgentContext._contexts.pop(id, None)
69-
if context and context.process:
70-
context.process.kill()
69+
if context and context.task:
70+
context.task.kill()
7171
return context
7272

7373
def kill_process(self):
74-
if self.process:
75-
self.process.kill()
74+
if self.task:
75+
self.task.kill()
7676

7777
def reset(self):
7878
self.kill_process()
@@ -89,8 +89,8 @@ def nudge(self):
8989
else:
9090
current_agent = self.agent0
9191

92-
self.process = DeferredTask(current_agent.monologue)
93-
return self.process
92+
self.task =self.run_task(current_agent.monologue)
93+
return self.task
9494

9595
def communicate(self, msg: "UserMessage", broadcast_level: int = 1):
9696
self.paused = False # unpause if paused
@@ -100,7 +100,7 @@ def communicate(self, msg: "UserMessage", broadcast_level: int = 1):
100100
else:
101101
current_agent = self.agent0
102102

103-
if self.process and self.process.is_alive():
103+
if self.task and self.task.is_alive():
104104
# set intervention messages to agent(s):
105105
intervention_agent = current_agent
106106
while intervention_agent and broadcast_level != 0:
@@ -110,11 +110,19 @@ def communicate(self, msg: "UserMessage", broadcast_level: int = 1):
110110
Agent.DATA_NAME_SUPERIOR, None
111111
)
112112
else:
113+
self.task = self.run_task(self._process_chain, current_agent, msg)
113114

114-
# self.process = DeferredTask(current_agent.monologue, msg)
115-
self.process = DeferredTask(self._process_chain, current_agent, msg)
115+
return self.task
116116

117-
return self.process
117+
def run_task(
118+
self, func: Callable[..., Coroutine[Any, Any, Any]], *args: Any, **kwargs: Any
119+
):
120+
if not self.task:
121+
self.task = DeferredTask(
122+
thread_name=self.__class__.__name__,
123+
)
124+
self.task.start_task(func, *args, **kwargs)
125+
return self.task
118126

119127
# this wrapper ensures that superior agents are called back if the chat was loaded from file and original callstack is gone
120128
async def _process_chain(self, agent: "Agent", msg: "UserMessage|str", user=True):
@@ -139,18 +147,20 @@ async def _process_chain(self, agent: "Agent", msg: "UserMessage|str", user=True
139147
class ModelConfig:
140148
provider: models.ModelProvider
141149
name: str
142-
ctx_length: int
143-
limit_requests: int
144-
limit_input: int
145-
limit_output: int
146-
kwargs: dict
150+
ctx_length: int = 0
151+
limit_requests: int = 0
152+
limit_input: int = 0
153+
limit_output: int = 0
154+
vision: bool = False
155+
kwargs: dict = field(default_factory=dict)
147156

148157

149158
@dataclass
150159
class AgentConfig:
151160
chat_model: ModelConfig
152161
utility_model: ModelConfig
153162
embeddings_model: ModelConfig
163+
browser_model: ModelConfig
154164
prompts_subdir: str = ""
155165
memory_subdir: str = ""
156166
knowledge_subdirs: list[str] = field(default_factory=lambda: ["default", "custom"])
@@ -480,6 +490,30 @@ def concat_messages(
480490
): # TODO add param for message range, topic, history
481491
return self.history.output_text(human_label="user", ai_label="assistant")
482492

493+
def get_chat_model(self):
494+
return models.get_model(
495+
models.ModelType.CHAT,
496+
self.config.chat_model.provider,
497+
self.config.chat_model.name,
498+
**self.config.chat_model.kwargs,
499+
)
500+
501+
def get_utility_model(self):
502+
return models.get_model(
503+
models.ModelType.CHAT,
504+
self.config.utility_model.provider,
505+
self.config.utility_model.name,
506+
**self.config.utility_model.kwargs,
507+
)
508+
509+
def get_embedding_model(self):
510+
return models.get_model(
511+
models.ModelType.EMBEDDING,
512+
self.config.embeddings_model.provider,
513+
self.config.embeddings_model.name,
514+
**self.config.embeddings_model.kwargs,
515+
)
516+
483517
async def call_utility_model(
484518
self,
485519
system: str,
@@ -494,12 +528,7 @@ async def call_utility_model(
494528
response = ""
495529

496530
# model class
497-
model = models.get_model(
498-
models.ModelType.CHAT,
499-
self.config.utility_model.provider,
500-
self.config.utility_model.name,
501-
**self.config.utility_model.kwargs,
502-
)
531+
model = self.get_utility_model()
503532

504533
# rate limiter
505534
limiter = await self.rate_limiter(
@@ -526,12 +555,7 @@ async def call_chat_model(
526555
response = ""
527556

528557
# model class
529-
model = models.get_model(
530-
models.ModelType.CHAT,
531-
self.config.chat_model.provider,
532-
self.config.chat_model.name,
533-
**self.config.chat_model.kwargs,
534-
)
558+
model = self.get_chat_model()
535559

536560
# rate limiter
537561
limiter = await self.rate_limiter(self.config.chat_model, prompt.format())
@@ -594,6 +618,10 @@ async def handle_intervention(self, progress: str = ""):
594618
await self.hist_add_user_message(msg, intervention=True)
595619
raise InterventionException(msg)
596620

621+
async def wait_if_paused(self):
622+
while self.context.paused:
623+
await asyncio.sleep(0.1)
624+
597625
async def process_tools(self, msg: str):
598626
# search for tool usage requests in agent message
599627
tool_request = extract_tools.json_parse_dirty(msg)

docker/run/build.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ docker buildx build --build-arg BRANCH=development -t frdel/agent-zero-run:devel
1515
docker buildx build --build-arg BRANCH=testing -t frdel/agent-zero-run:testing --platform linux/amd64,linux/arm64 --push --build-arg CACHE_DATE=$(date +%Y-%m-%d:%H:%M:%S) .
1616

1717
# main
18-
docker buildx build --build-arg BRANCH=testing -t frdel/agent-zero-run:testing --platform linux/amd64,linux/arm64 --push --no-cache .
18+
docker buildx build --build-arg BRANCH=main -t frdel/agent-zero-run:latest --platform linux/amd64,linux/arm64 --push --build-arg CACHE_DATE=$(date +%Y-%m-%d:%H:%M:%S) .

docker/run/fs/exe/initialize.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ apt-get update > /dev/null 2>&1 &
2121
/usr/sbin/sshd -D &
2222

2323
# Start searxng server in background
24-
su - searxng -c "bash /exe/run_searxng.sh" &
24+
su - searxng -c "bash /exe/run_searxng.sh \"$@\"" &
2525

2626
# Start A0 and restart on exit
2727
bash /exe/run_A0.sh "$@"

docker/run/fs/exe/run_A0.sh

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,13 @@
11
#!/bin/bash
22

3-
# Paths
4-
SOURCE_DIR="/git/agent-zero"
5-
TARGET_DIR="/a0"
6-
7-
8-
function setup_venv() {
9-
. "/ins/setup_venv.sh" "$@"
10-
}
11-
12-
function clone_repo() {
13-
# Copy repository files if run_ui.py is missing in /a0 (if the volume is mounted)
14-
if [ ! -f "$TARGET_DIR/run_ui.py" ]; then
15-
echo "Copying files from $SOURCE_DIR to $TARGET_DIR..."
16-
cp -rn --no-preserve=ownership,mode "$SOURCE_DIR/." "$TARGET_DIR"
17-
fi
18-
}
19-
20-
# setup and preload A0
21-
setup_venv
22-
clone_repo
23-
python /a0/prepare.py --dockerized=true
24-
python /a0/preload.py --dockerized=true
25-
263
# Loop to restart the Python script when it finishes
274
while true; do
285

29-
setup_venv
30-
clone_repo
6+
. "/ins/setup_venv.sh" "$@"
7+
. "/ins/copy_A0.sh" "$@"
8+
9+
python /a0/prepare.py --dockerized=true
10+
python /a0/preload.py --dockerized=true
3111

3212
echo "Starting A0..."
3313
python /a0/run_ui.py \

docker/run/fs/ins/copy_A0.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
# Paths
4+
SOURCE_DIR="/git/agent-zero"
5+
TARGET_DIR="/a0"
6+
7+
# Copy repository files if run_ui.py is missing in /a0 (if the volume is mounted)
8+
if [ ! -f "$TARGET_DIR/run_ui.py" ]; then
9+
echo "Copying files from $SOURCE_DIR to $TARGET_DIR..."
10+
cp -rn --no-preserve=ownership,mode "$SOURCE_DIR/." "$TARGET_DIR"
11+
fi

docker/run/fs/ins/install_A0.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,14 @@ git clone -b "$BRANCH" "https://github.com/frdel/agent-zero" "/git/agent-zero"
1313
# setup python environment
1414
. "/ins/setup_venv.sh" "$@"
1515

16+
# Ensure the virtual environment and pip setup
17+
pip install --upgrade pip ipython requests
18+
19+
# Install some packages in specific variants
20+
pip install torch --index-url https://download.pytorch.org/whl/cpu
21+
22+
# Install remaining A0 python packages
23+
pip install -r /git/agent-zero/requirements.txt
24+
1625
# Preload A0
1726
python /git/agent-zero/preload.py --dockerized=true
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/bash
22

33
# searxng
4-
bash /ins/install_searxng.sh "$@"
4+
bash /ins/install_searxng.sh "$@"
5+
6+
# playwright
7+
bash /ins/install_playwright.sh "$@"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
# activate venv
4+
. "/ins/setup_venv.sh" "$@"
5+
6+
# install playwright
7+
pip install playwright
8+
9+
# install chromium with dependencies
10+
playwright install --with-deps chromium

docker/run/fs/ins/setup_venv.sh

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ if [ ! -d /opt/venv ]; then
44
# Create and activate Python virtual environment
55
python3 -m venv /opt/venv
66
source /opt/venv/bin/activate
7-
8-
# Ensure the virtual environment and pip setup
9-
pip install --upgrade pip ipython requests
10-
11-
# Install some packages in specific variants
12-
pip install torch --index-url https://download.pytorch.org/whl/cpu
13-
14-
# Install remaining A0 python packages
15-
pip install -r /git/agent-zero/requirements.txt
167
else
178
source /opt/venv/bin/activate
189
fi

docs/res/favicon.png

38.7 KB
Loading

docs/res/favicon_round.png

50.7 KB
Loading

0 commit comments

Comments
 (0)