Skip to content

Conversation

@Virtuoso633
Copy link

This pull request addresses several critical dependency and runtime bugs that prevent the XAgent project from building and running successfully on modern development environments, particularly on macOS with ARM64 architecture (Apple Silicon) and recent Linux distributions.

These changes should significantly improve the out-of-the-box experience for new contributors and users.

The Problem

On a clean clone of the repository, the setup process fails at multiple stages:

  1. Docker Build Failures: The ToolServerNode Docker image fails to build due to:
    • The openjdk-17-jdk-headless package being unavailable in the base image's package repositories.
    • The playwright install-deps command failing because it tries to install outdated or unavailable system dependencies.
  2. Docker Runtime Failures: The xagent-mysql container consistently fails to start on ARM64 platforms due to an incompatible image or configuration.
  3. Local Script Dependency Conflicts: The run.py script fails due to:
    • An outdated pinecone-client dependency, which now intentionally throws an exception.
    • Incompatibilities between the latest openai library (v1.x) and the agent's parsing logic, which expects the legacy openai<1.0 response format. This results in a KeyError: 0 during JSON parsing.
  4. Agent Runtime Bugs: Even after fixing the dependencies, the agent would crash during execution due to:
    • A ValueError: max_workers must be greater than 0 when the web search tool returns an empty list of results.
    • The same KeyError: 0 parsing error in the "reflection" step, caused by the code trying to parse an object that was already a dictionary.

The Solution

This PR implements the following fixes to address these issues:

  1. Dockerfile Updates (ToolServer/Dockerfile.node):

    • Updated the Java dependency to openjdk-21-jre-headless, which is available in the base image.
    • Made the playwright install-deps command non-fatal by appending || true. This allows the build to succeed even if some optional browser dependencies are missing, which doesn't affect the core functionality.
    • Commented out the hardcoded Tsinghua PyPI mirror to improve reliability for international users.
  2. Docker Compose Update (docker-compose.yml):

    • Replaced the generic mysql image with the official mysql/mysql-server:latest image.
    • Added platform: linux/amd64 and a more robust health check to ensure the MySQL container starts reliably across different architectures.
  3. Dependency Fixes (requirements.txt):

    • Pinned legacy versions of openai==0.28.1 and httpx==0.23.0. This is the "magic combination" that is compatible with the agent's internal parsing logic for OpenAI function calls.
    • Replaced the deprecated pinecone-client with pinecone==3.1.0.
  4. Runtime Code Patches:

    • In XAgent/XAgent/function_handler.py: Added a check to ensure len(result) > 0 before creating a ThreadPoolExecutor to prevent the ValueError.
    • In XAgent/XAgent/workflow/plan_exec.py: Fixed the primary parsing bug by removing the redundant json5.loads() call, directly using the dictionary object from the OpenAI response.
    • In XAgent/XAgent/workflow/reflection.py: Applied the same fix to the reflection step, resolving the final runtime crash.

How to Test This Fix

  1. On a clean clone of this branch, ensure you are on a modern system (e.g., macOS with Apple Silicon or a recent Linux distro).
  2. Run docker compose up --build -d. The build process and container startup should now complete successfully without any errors.
  3. Create and activate a Python virtual environment:
    python3 -m venv .venv
    source .venv/bin/activate
  4. Install the corrected dependencies:
    pip install -r requirements.txt
  5. Set a valid OpenAI API key in assets/config.yml.
  6. Run a test task:
    python run.py --task "What is the capital of France and what is the weather there now?"
  7. Expected Result: The task should now run to completion, with the agent successfully planning, using its tools, and finishing all subtasks without crashing.

…ents

This commit addresses several issues that prevent the project from running on up-to-date systems, particularly on macOS with Apple Silicon.

Fixes include:
- Updated Dockerfiles to use available package versions (OpenJDK, Playwright deps).
- Corrected MySQL service configuration in docker-compose for better compatibility.
- Pinned legacy versions of 'openai' and 'httpx' in requirements.txt to resolve API response parsing errors.
- Replaced deprecated 'pinecone-client' with 'pinecone'.
- Patched runtime code in plan_exec.py, reflection.py, and function_handler.py to prevent crashes from outdated parsing logic and empty API results.
@Virtuoso633 Virtuoso633 force-pushed the fix/dependency-and-parsing-bugs branch from 59054a2 to 7bafaa4 Compare August 19, 2025 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant