Agent Zero AI framework
project finalizing, openrouter embeddings
frdele6eae9c7dd50
diff --git a/.gitignore b/.gitignoreindex d9ede2a76..c33c0598c 100644--- a/.gitignore+++ b/.gitignore@@ -5,10 +5,9 @@*.py[cod]**/.conda/-#Ignore cursor rules+#Ignore IDE files.cursor/.windsurf/-.cursorindexingignore# ignore test files in root dir/*.test.py@@ -43,11 +42,7 @@ instruments/**# Global rule to include .gitkeep files anywhere!**/.gitkeep++# for browser-useagent_history.gif-# specify, specstory extension data-.serena-.specify-.specstory-specs/*/.reviews-specs/*/reviewsdiff --git a/conf/model_providers.yaml b/conf/model_providers.yamlindex 0683cf011..3454daa9f 100644--- a/conf/model_providers.yaml+++ b/conf/model_providers.yaml@@ -107,6 +107,15 @@ embedding:azure:name: OpenAI Azurelitellm_provider: azure+ # TODO: OpenRouter not yet supported by LiteLLM, replace with native litellm_provider openrouter and remove api_base when ready+ openrouter:+ name: OpenRouter+ litellm_provider: openai+ kwargs:+ api_base: https://openrouter.ai/api/v1+ extra_headers:+ "HTTP-Referer": "https://agent-zero.ai/"+ "X-Title": "Agent Zero"other:name: Other OpenAI compatiblelitellm_provider: openai\ No newline at end of filediff --git a/conf/projects.default.gitignore b/conf/projects.default.gitignorenew file mode 100644index 000000000..9a5f01f2a--- /dev/null+++ b/conf/projects.default.gitignore@@ -0,0 +1,13 @@+# A0 project meta folder+.a0proj/++# Python environments & cache+venv/+**/__pycache__/++# Node.js dependencies+**/node_modules/+**/.npm/++# Version control metadata+**/.git/diff --git a/prompts/agent.extras.project.file_structure.md b/prompts/agent.extras.project.file_structure.mdnew file mode 100644index 000000000..5167003f9--- /dev/null+++ b/prompts/agent.extras.project.file_structure.md@@ -0,0 +1,9 @@+# File structure of project {{project_name}}+- this is filtered overview not full scan+- list yourself if needed+- maximum depth: {{max_depth}}+- ignored:+{{gitignore}}++## file tree+{{file_structure}}\ No newline at end of filediff --git a/prompts/agent.system.projects.main.md b/prompts/agent.system.projects.main.mdindex b062e00e7..1b6890de6 100644--- a/prompts/agent.system.projects.main.md+++ b/prompts/agent.system.projects.main.md@@ -1,5 +1,5 @@# Projects- user can create and activate projects-- projects have work folder and instructions+- projects have work folder in /usr/projects/<name> and instructions and config in /usr/projects/<name>/.a0proj- when activated agent works in project follows project instructions- agent cannot manipulate or switch projects\ No newline at end of filediff --git a/python/api/projects.py b/python/api/projects.pyindex 6d96a0e76..3e06fadcd 100644--- a/python/api/projects.py+++ b/python/api/projects.py@@ -25,6 +25,8 @@ class Projects(ApiHandler):data = self.activate_project(ctxid, input.get("name", None))elif action == "deactivate":data = self.deactivate_project(ctxid)+ elif action == "file_structure":+ data = self.get_file_structure(input.get("name", None), input.get("settings"))else:raise Exception("Invalid action")@@ -75,4 +77,15 @@ class Projects(ApiHandler):def deactivate_project(self, context_id: str|None):if not context_id:raise Exception("Context ID is required")- return projects.deactivate_project(context_id)\ No newline at end of file+ return projects.deactivate_project(context_id)++ def get_file_structure(self, name: str|None, settings: dict|None):+ if not name:+ raise Exception("Project name is required")+ # project data+ basic_data = projects.load_basic_project_data(name)+ # override file structure settings+ if settings:+ basic_data["file_structure"] = settings # type: ignore+ # get structure+ return projects.get_file_structure(name, basic_data)\ No newline at end of filediff --git a/python/extensions/message_loop_prompts_after/_75_include_project_extras.py b/python/extensions/message_loop_prompts_after/_75_include_project_extras.pynew file mode 100644index 000000000..87bef95be--- /dev/null+++ b/python/extensions/message_loop_prompts_after/_75_include_project_extras.py@@ -0,0 +1,47 @@+from python.helpers.extension import Extension+from agent import LoopData+from python.helpers import projects+++class IncludeProjectExtras(Extension):+ async def execute(self, loop_data: LoopData = LoopData(), **kwargs):++ # active project+ project_name = projects.get_context_project_name(self.agent.context)+ if not project_name:+ return++ # project config+ project = projects.load_basic_project_data(project_name)++ # load file structure if enabled+ if project["file_structure"]["enabled"]:+ file_structure = projects.get_file_structure(project_name)+ gitignore = cleanup_gitignore(project["file_structure"]["gitignore"])++ # read prompt+ file_structure_prompt = self.agent.read_prompt(+ "agent.extras.project.file_structure.md",+ max_depth=project["file_structure"]["max_depth"],+ gitignore=gitignore,+ project_name=project_name,+ file_structure=file_structure,+ )+ # add file structure to the prompt+ loop_data.extras_temporary["project_file_structure"] = file_structure_prompt+++def cleanup_gitignore(gitignore_raw: str) -> str:+ """Process gitignore: split lines, strip, remove comments, remove empty lines."""+ gitignore_lines = []+ for line in gitignore_raw.split('\n'):+ # Strip whitespace+ line = line.strip()+ # Remove inline comments (everything after #)+ if '#' in line:+ line = line.split('#')[0].strip()+ # Keep only non-empty lines+ if line:+ gitignore_lines.append(line)++ return '\n'.join(gitignore_lines) if gitignore_lines else "nothing ignored"diff --git a/python/helpers/file_tree.py b/python/helpers/file_tree.pyindex 8d94dba98..c53dbcda5 100644--- a/python/helpers/file_tree.py+++ b/python/helpers/file_tree.py@@ -28,11 +28,11 @@ def file_tree(max_depth: int = 0,max_lines: int = 0,folders_first: bool = True,- max_folders: int | None = None,- max_files: int | None = None,- sort: tuple[str, str] = (SORT_BY_MODIFIED, SORT_DESC),+ max_folders: int = 0,+ max_files: int = 0,+ sort: tuple[Literal["name", "created", "modified"], Literal["asc", "desc"]] = ("modified", "desc"),ignore: str | None = None,- output_mode: str = OUTPUT_MODE_STRING,+ output_mode: Literal["string", "flat", "nested"] = OUTPUT_MODE_STRING,) -> str | list[dict]:"""Render a directory tree relative to the repository base path.diff --git a/python/helpers/projects.py b/python/helpers/projects.pyindex 75ae35138..e64970619 100644--- a/python/helpers/projects.py+++ b/python/helpers/projects.py@@ -1,7 +1,7 @@import osfrom typing import Literal, TypedDict, TYPE_CHECKING-from python.helpers import files, dirty_json, persist_chat+from python.helpers import files, dirty_json, persist_chat, file_treefrom python.helpers.print_style import PrintStyle@@ -17,6 +17,15 @@ PROJECT_HEADER_FILE = "project.json"CONTEXT_DATA_KEY_PROJECT = "project"+class FileStructureInjectionSettings(TypedDict):+ enabled: bool+ max_depth: int+ max_files: int+ max_folders: int+ max_lines: int+ gitignore: str++class BasicProjectData(TypedDict):title: strdescription: str@@ -25,6 +34,7 @@ class BasicProjectData(TypedDict):memory: Literal["own", "global"] # in the future we can add cutom and point to another existing folder+ file_structure: FileStructureInjectionSettingsclass EditProjectData(BasicProjectData):@@ -73,6 +83,21 @@ def load_project_header(name: str):return header+def _default_file_structure_settings():+ try:+ gitignore = files.read_file("conf/projects.default.gitignore")+ except Exception:+ gitignore = ""+ return FileStructureInjectionSettings(+ enabled=True,+ max_depth=5,+ max_files=20,+ max_folders=20,+ max_lines=250,+ gitignore=gitignore,+ )++def _normalizeBasicData(data: BasicProjectData):return BasicProjectData(title=data.get("title", ""),@@ -80,6 +105,10 @@ def _normalizeBasicData(data: BasicProjectData):instructions=data.get("instructions", ""),color=data.get("color", ""),memory=data.get("memory", "own"),+ file_structure=data.get(+ "file_structure",+ _default_file_structure_settings(),+ ),)@@ -95,6 +124,10 @@ def _normalizeEditData(data: EditProjectData):knowledge_files_count=data.get("knowledge_files_count", 0),secrets=data.get("secrets", ""),memory=data.get("memory", "own"),+ file_structure=data.get(+ "file_structure",+ _default_file_structure_settings(),+ ),)@@ -324,3 +357,26 @@ def get_knowledge_files_count(name: str):get_project_meta_folder(name, PROJECT_KNOWLEDGE_DIR))return len(files.list_files_in_dir_recursively(knowledge_folder))++def get_file_structure(name: str, basic_data: BasicProjectData|None=None) -> str:+ project_folder = get_project_folder(name)+ if basic_data is None:+ basic_data = load_basic_project_data(name)++ tree = str(file_tree.file_tree(+ project_folder,+ max_depth=basic_data["file_structure"]["max_depth"],+ max_files=basic_data["file_structure"]["max_files"],+ max_folders=basic_data["file_structure"]["max_folders"],+ max_lines=basic_data["file_structure"]["max_lines"],+ ignore=basic_data["file_structure"]["gitignore"],+ output_mode=file_tree.OUTPUT_MODE_STRING+ ))++ # empty?+ if "\n" not in tree:+ tree += "\n # Empty"++ return tree++\ No newline at end of filediff --git a/python/helpers/strings.py b/python/helpers/strings.pyindex 1144b1f3b..dac89c63e 100644--- a/python/helpers/strings.py+++ b/python/helpers/strings.py@@ -168,6 +168,7 @@ def replace_file_includes(text: str, placeholder_pattern: str = r"§§include\((path = match.group(1)try:# read file content+ path = files.fix_dev_path(path)return files.read_file(path)except Exception:# if file not readable keep original placeholderdiff --git a/requirements.dev.txt b/requirements.dev.txtnew file mode 100644index 000000000..93bada795--- /dev/null+++ b/requirements.dev.txt@@ -0,0 +1,3 @@+pytest>=8.4.2+pytest-asyncio>=1.2.0+pytest-mock>=3.15.1\ No newline at end of filediff --git a/requirements2.txt b/requirements2.txtindex bb132bdaa..7256765d8 100644--- a/requirements2.txt+++ b/requirements2.txt@@ -1,2 +1,2 @@-litellm==1.79.0+litellm==1.79.3openai==1.99.5\ No newline at end of filediff --git a/webui/components/chat/speech/speech-store.js b/webui/components/chat/speech/speech-store.jsindex 8d20a418a..9ca202e6c 100644--- a/webui/components/chat/speech/speech-store.js+++ b/webui/components/chat/speech/speech-store.js@@ -2,6 +2,7 @@ import { createStore } from "/js/AlpineStore.js";import { updateChatInput, sendMessage } from "/index.js";import { sleep } from "/js/sleep.js";import { store as microphoneSettingStore } from "/components/settings/speech/microphone-setting-store.js";+import * as shortcuts from "/js/shortcuts.js";const Status = {INACTIVE: "inactive",@@ -94,7 +95,9 @@ const model = {async init() {// Guard against multiple initializationsif (this._initialized) {- console.log('[Speech Store] Already initialized, skipping duplicate init()');+ console.log(+ "[Speech Store] Already initialized, skipping duplicate init()"+ );return;}@@ -368,11 +371,13 @@ const model = {// Show a prompt to user to enable audioshowAudioPermissionPrompt() {- if (window.toast) {- window.toast("Click anywhere to enable audio playback", "info", 5000);- } else {- console.log("Please click anywhere on the page to enable audio playback");- }+ shortcuts.frontendNotification({+ type: "info",+ message: "Click anywhere to enable audio playback",+ displayTime: 5000,+ frontendOnly: true,+ });+ console.log("Please click anywhere on the page to enable audio playback");},// Browser TTSdiff --git a/webui/components/notifications/notification-toast-stack.html b/webui/components/notifications/notification-toast-stack.htmlindex c4337a8c8..01fdcf619 100644--- a/webui/components/notifications/notification-toast-stack.html+++ b/webui/components/notifications/notification-toast-stack.html@@ -82,6 +82,8 @@box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);position: relative;min-height: 60px;+ max-height: 15em;+ overflow-y: auto;}.toast-item:hover {diff --git a/webui/components/projects/project-edit-file-structure.html b/webui/components/projects/project-edit-file-structure.htmlnew file mode 100644index 000000000..63652067a--- /dev/null+++ b/webui/components/projects/project-edit-file-structure.html@@ -0,0 +1,102 @@+<html>++<head>+ <title>Create a new project</title>+ <script type="module">+ import { store } from "/components/projects/projects-store.js";+ </script>+</head>++<body>+ <div x-data>+ <template x-if="$store.projects && $store.projects.selectedProject">+ <div>+ <!-- <div class="project-detail-header">+ <div class="projects-project-card-title">Project details</div>+ <div class="project-path" x-text="$store.projects.selectedProject.path"></div>+ </div> -->+++ <div class="projects-setting-row" style="padding: 1rem 0;">+ <div class="projects-setting-text">+ <label class="projects-form-label">Inject project structure into context window</label>+ <span class="projects-form-description">When turned on, the project file structure will be+ injected into the context window of the agent. This is useful for agents that need to+ have an overview of project folders and files at all times.</span>+ </div>+ <div class="projects-setting-control">+ <label class="toggle">+ <input type="checkbox" x-model="$store.projects.selectedProject.file_structure.enabled">+ <span class="toggler"></span>+ </label>+ </div>+ </div>++ <div x-show="$store.projects.selectedProject.file_structure.enabled">+++ <div class="projects-form-group">+ <label class="projects-form-label">Max Depth</label>+ <span class="projects-form-description">Set the maximum depth for the file structure (0 =+ unlimited).</span>+ <input type="number" class="projects-form-input"+ x-model.number="$store.projects.selectedProject.file_structure.max_depth" min="0" step="1"+ placeholder="0">+ </div>++ <div class="projects-form-group">+ <label class="projects-form-label">Max Lines</label>+ <span class="projects-form-description">Maximum total lines outputted for the agent. This limits+ the+ space occupied in the context window (0 = unlimited).</span>+ <input type="number" class="projects-form-input"+ x-model.number="$store.projects.selectedProject.file_structure.max_lines" min="0" step="1"+ placeholder="0">+ </div>++ <div class="projects-form-group">+ <label class="projects-form-label">Max Folders</label>+ <span class="projects-form-description">Maximum number of subfolders to display under one folder+ (0 =+ unlimited).</span>+ <input type="number" class="projects-form-input"+ x-model.number="$store.projects.selectedProject.file_structure.max_folders" min="0" step="1"+ placeholder="0">+ </div>++ <div class="projects-form-group">+ <label class="projects-form-label">Max Files</label>+ <span class="projects-form-description">Maximum number of files to display under one folder (0 =+ unlimited).</span>+ <input type="number" class="projects-form-input"+ x-model.number="$store.projects.selectedProject.file_structure.max_files" min="0" step="1"+ placeholder="0">+ </div>++ <div class="projects-form-group">+ <label class="projects-form-label">Ignored files / folders</label>+ <span class="projects-form-description">Specify patterns in gitignore format. These files and+ folders will be skipped during analysis, such as meta folders, cache directories, packages,+ and+ build artifacts.</span>+ <textarea class="projects-form-textarea"+ x-model="$store.projects.selectedProject.file_structure.gitignore" rows="5"+ placeholder="Enter gitignore patterns (e.g., node_modules/, .git/, *.log)"></textarea>+ </div>++ <button class="button icon-button" x-on:click="$store.projects.testFileStructure()">+ <span class="icon material-symbols-outlined">account_tree</span>+ <span>Test output</span>+ </button>+++ </div>++ </div>+ </template>+ </div>+</body>+<style>+</style>++</html>\ No newline at end of filediff --git a/webui/components/projects/project-edit.html b/webui/components/projects/project-edit.htmlindex 871c576b6..ad04b446b 100644--- a/webui/components/projects/project-edit.html+++ b/webui/components/projects/project-edit.html@@ -50,6 +50,14 @@</x-component></div>+ <div class="project-detail">+ <div class="project-detail-header">+ <span class="projects-project-card-title">File structure</span>+ </div>+ <x-component path="projects/project-edit-file-structure.html">+ </x-component>+ </div>+<div class="project-detail"><div class="project-detail-header"><span class="projects-project-card-title">Secrets</span>diff --git a/webui/components/projects/project-file-structure-test.html b/webui/components/projects/project-file-structure-test.htmlnew file mode 100644index 000000000..b39b0eb8b--- /dev/null+++ b/webui/components/projects/project-file-structure-test.html@@ -0,0 +1,25 @@+<html>++<head>+ <title>File structure test</title>+ <script type="module">+ import { store } from "/components/projects/projects-store.js";+ </script>+</head>++<body>+ <div x-data>+ <template x-if="$store.projects && $store.projects.selectedProject">+ <div>++ <h3>File structure test - <span x-text="$store.projects.selectedProject.name"></span></h3>+ <pre x-text="$store.projects.fileStructureTestOutput"></pre>++ </div>+ </template>+ </div>+</body>+<style>+</style>++</html>\ No newline at end of filediff --git a/webui/components/projects/project-selector.html b/webui/components/projects/project-selector.htmlindex bd2ea151d..08855fa61 100644--- a/webui/components/projects/project-selector.html+++ b/webui/components/projects/project-selector.html@@ -26,7 +26,8 @@</template><div x-show="open" x-init="$store.projects.loadProjectsList()" class="project-dropdown-menu" style="display: none;" x-transition>- <a href="#" @click.prevent="$store.projects.openProjectsModal(); open = false;" class="project-dropdown-item"><span class="icon material-symbols-outlined">snippet_folder</span> <span class="project-selector-item-text">Edit Projects</span></a>+ <a href="#" @click.prevent="$store.projects.openProjectsModal(); open = false;" class="project-dropdown-item"><span class="icon material-symbols-outlined">snippet_folder</span> <span class="project-selector-item-text">Projects</span></a>+ <a x-show="$store.chats.selectedContext.project?.name" href="#" @click.prevent="$store.projects.editActiveProject(); open = false;" class="project-dropdown-item"><span class="icon material-symbols-outlined">edit</span> <span class="project-selector-item-text">Edit <span x-text="$store.chats.selectedContext.project?.title"></span></span></a><a x-show="$store.chats.selectedContext.project?.name" href="#" @click.prevent="$store.projects.deactivateProject(); open = false;" class="project-dropdown-item"><span class="icon material-symbols-outlined">close</span> <span class="project-selector-item-text">Deactivate</span></a><!-- <a href="#" @click.prevent="$store.projects.openProjectsModal(); $store.projects.openCreateModal(); open = false;" class="project-dropdown-item">Create Project</a> -->diff --git a/webui/components/projects/projects-store.js b/webui/components/projects/projects-store.jsindex fcba1c1b5..a213ee383 100644--- a/webui/components/projects/projects-store.js+++ b/webui/components/projects/projects-store.js@@ -378,6 +378,33 @@ const model = {.join("/").replace(/\/+/g, "/");},++ async editActiveProject() {+ const ctx = shortcuts.getCurrentContext();+ if(!ctx) return;+ this.openEditModal(ctx.project.name);+ },++ async testFileStructure() {+ try {+ const response = await api.callJsonApi("projects", {+ action: "file_structure",+ name: this.selectedProject.name,+ settings: this.selectedProject.file_structure,+ });+ this.fileStructureTestOutput = response.data;+ shortcuts.openModal("projects/project-file-structure-test.html");+ } catch (error) {+ console.error("Error testing file structure:", error);+ shortcuts.frontendNotification({+ type: shortcuts.NotificationType.ERROR,+ message: "Error testing file structure",+ priority: shortcuts.NotificationPriority.NORMAL,+ displayTime: 3,+ frontendOnly: true,+ });+ }+ },};// convert it to alpine storediff --git a/webui/components/sidebar/chats/chats-store.js b/webui/components/sidebar/chats/chats-store.jsindex 6564f5b10..722c8e660 100644--- a/webui/components/sidebar/chats/chats-store.js+++ b/webui/components/sidebar/chats/chats-store.js@@ -23,6 +23,10 @@ const model = {return this.selected;},+ getSelectedContext(){+ return this.selectedContext;+ },+init() {// Initialize from localStorageconst lastSelectedChat = localStorage.getItem("lastSelectedChat");diff --git a/webui/js/shortcuts.js b/webui/js/shortcuts.jsindex 9a70f7799..3043d1d46 100644--- a/webui/js/shortcuts.js+++ b/webui/js/shortcuts.js@@ -1,9 +1,10 @@import { store as chatsStore } from "/components/sidebar/chats/chats-store.js";import { callJsonApi } from "/js/api.js";+import * as modals from "/js/modals.js";import {NotificationType,NotificationPriority,- store as notificationStore+ store as notificationStore,} from "/components/notifications/notification-store.js";// shortcuts utils for convenience@@ -12,13 +13,24 @@ import {export { callJsonApi };// notifications-export {- NotificationType,- NotificationPriority,-}-export const frontendNotification = notificationStore.frontendNotification.bind(notificationStore);+export { NotificationType, NotificationPriority };+export const frontendNotification =+ notificationStore.frontendNotification.bind(notificationStore);// chat contextexport function getCurrentContextId() {return chatsStore.getSelectedChatId();}++export function getCurrentContext(){+ return chatsStore.getSelectedContext();+}++// modals+export function openModal(modalPath) {+ return modals.openModal(modalPath);+}++export function closeModal(modalPath = null) {+ return modals.closeModal(modalPath);+}