A task execution framework using language models to perform complex tasks.
Project description
LLM Agent X
Overview
LLM Agent X is a task execution framework that leverages language models to perform complex tasks by recursively decomposing them into subtasks and using tools like web search.
Installation
-
Clone the repository (optional, if you want to install from source):
git clone https://github.com/cvaz1306/llm_agent_x.git cd llm_agent_x
-
Install the package:
- From PyPI:
pip install llm-agent-x
- Or, for local development (from the project root directory):
pip install .
- To install with editable mode (useful for development):
pip install -e .
- From PyPI:
-
Set up environment variables: Create a
.envfile in the root directory (or ensure your environment is configured) and add the following variables:SEARX_HOST=http://localhost:8080 OUTPUT_DIR=./output/ OPENAI_BASE_URL=https://api.openai.com/v1 OPENAI_API_KEY=your_openai_api_key # Optional: Define a default LLM model # DEFAULT_LLM=gpt-4o-mini
Usage
To run the LLM agent, use the following command:
llm-agent-x "Your task description here" --max_layers 2 --output output.md --model gpt-4o-mini
cli.pyis not intended to be the primary interface for this project. It is merely a script demonstrating the project's capabilities. For your use, we recommend that you modify or copycli.pyor integratingllm_agent_x's API into your own project. In the future, we may implement a HTTP server,.
Arguments
task: The task to execute.--u_inst: User instructions for the task.--max_layers: The maximum number of layers for task splitting (default: 3).--output: The output file path (default: output.md, saved inOUTPUT_DIR).--model: The name of the LLM to use (default: value fromDEFAULT_LLMenvironment variable, or the hardcoded default incli.pyifDEFAULT_LLMis not set).--task_limit: Array defining task limits per layer (default: "[3,2,2,0]").--merger: Strategy for merging results, 'ai' or 'append' (default: 'ai').--align_summaries: Whether to align summaries with user instructions.--no-tree: If specified, disables tree rendering in console--default_subtask_type: The default task type to apply to all subtasks.--enable-python-execution: Enable theexec_pythontool for the agent. If enabled, the agent can choose to execute Python code, potentially in a Docker sandbox if configured (see Python Execution Sandbox section). Defaults to False.
Example
llm-agent-x "Research the impact of climate change on polar bears" --max_layers 3 --output climate_change_report.md --model gpt-4o-mini
See the samples folder for more examples, including their outputs.
Example flowchart output
flowchart TD
A[Research the evolution of the internet. use 5 subtasks, and make sure you follow all your previous instructions nd don't include a summarization task at the end. make your final report very detailed.]
A -->|Subtask| B[Identify key milestones in the development of the internet.]
B -->|Tool call| C[web_search]
C --> B
B -->|Completed| A
A -->|Subtask| D[Research the history of major internet protocols and technologies.]
D -->|Tool call| E[web_search]
E --> D
D -->|Completed| A
A -->|Subtask| F[Analyze the impact of government policies on the growth of the internet.]
F -->|Tool call| G[web_search]
G --> F
F -->|Completed| A
A -->|Subtask| H[Examine the role of private companies in shaping the internet's evolution.]
H -->|Tool call| I[web_search]
I --> H
H -->|Completed| A
A -->|Subtask| J[Evaluate the global spread and adoption of the internet over time.]
J -->|Tool call| K[web_search]
K --> J
J -->|Completed| A
Dependencies
Project dependencies are managed with Poetry and are listed in the pyproject.toml file.
⚠️
torchis optional in Poetry but required at runtime. You must install the correct version for your hardware manually using the appropriate--index-url.
License
This project is licensed under the MIT License.
Python Execution Sandbox (Optional)
LLM Agent X includes an optional Dockerized sandbox environment for executing Python code. This provides isolation and allows for pre-loading files and cloudpickle objects into the execution namespace.
Features
- Isolated Execution: Code runs inside a Docker container.
- File Uploads: Upload scripts or data files directly to the sandbox's workspace.
- Cloudpickle Support: Load
.pklfiles (created withcloudpickle) into the Python execution scope. - REST API: The sandbox is controlled via a simple REST API.
Building the Sandbox Image
From the root of the repository:
docker build -t python-sandbox ./sandbox
Running the Sandbox Container
To run the sandbox container and make it accessible on port 5000:
docker run -d -p 5000:5000 --rm python-sandbox
The --rm flag automatically removes the container when it exits.
The -d flag runs it in detached mode.
Configuration
The exec_python tool will interact with this sandbox if use_docker_sandbox=True is passed to it.
By default, it expects the sandbox API to be at http://localhost:5000.
You can configure this URL by setting the PYTHON_SANDBOX_API_URL environment variable for the environment running llm-agent-x (not for the Docker container itself). For example, in your .env file:
PYTHON_SANDBOX_API_URL=http://127.0.0.1:5000
Using with the Agent
To allow the agent to use the exec_python tool (and potentially the sandbox):
- Ensure the
exec_pythontool is enabled inllm_agent_x/cli.pyby the logic controlled by the--enable-python-executionflag. (This was done as part of the feature implementation). - Make sure the Docker sandbox container is running if you intend to use
use_docker_sandbox=True. - To make the
exec_pythontool available to the agent, use the--enable-python-executioncommand-line flag when runningllm-agent-x. - If enabled, the agent's underlying LLM must be prompted in a way that it understands when and how to use the
exec_pythontool (including its parameters likeuse_docker_sandbox,files_to_upload, andcloud_pickle_files_to_load). This typically involves providing clear instructions and examples in the prompt or task description given to the agent.
Example exec_python call (if used directly):
from llm_agent_x.tools.exec_python import exec_python
# Assuming sandbox is running and test_script.py exists locally
# and data.pkl was generated using cloudpickle.
# 1. Create dummy files for demonstration
with open("test_script.py", "w") as f:
f.write("my_obj = LOADED_PICKLES.get('data.pkl')\nprint(f'Loaded data: {my_obj}')\nprint('Hello from sandbox script!')")
import cloudpickle
with open("data.pkl", "wb") as f:
cloudpickle.dump({"key": "value"}, f)
# 2. Execute using the sandbox
result = exec_python(
code="with open('/workspace/test_script.py', 'r') as f: exec(f.read())", # Execute the uploaded script
use_docker_sandbox=True,
files_to_upload=["test_script.py", "data.pkl"],
cloud_pickle_files_to_load=["data.pkl"] # Path relative to sandbox workspace
)
print(result)
# Expected output (or similar):
# {'stdout': "Loaded data: {'key': 'value'}\nHello from sandbox script!\n", 'stderr': '', 'error': None}
# Don't forget to clean up dummy files
import os
os.remove("test_script.py")
os.remove("data.pkl")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_agent_x-1.0.0.tar.gz.
File metadata
- Download URL: llm_agent_x-1.0.0.tar.gz
- Upload date:
- Size: 66.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.5 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91850035fffe5899a1bc4392ac1911584434261afe0e21af716ffc3353437fc2
|
|
| MD5 |
f1025a5adbe46b43e2906db206045c16
|
|
| BLAKE2b-256 |
2f41d78627085ce4db47b91b569861e930bc9a4398e6aa4442d667fde333a9d0
|
File details
Details for the file llm_agent_x-1.0.0-py3-none-any.whl.
File metadata
- Download URL: llm_agent_x-1.0.0-py3-none-any.whl
- Upload date:
- Size: 78.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.5 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9bd646a3f80277e9c7d108c645dcfa7cd325d0b91a904d30d1fc9996fe7a8c2f
|
|
| MD5 |
5136b171fe9fca584ccdd2176b1c07ed
|
|
| BLAKE2b-256 |
136bc9b686fd766165315ee89b1faf42d56176ec678a139ba858ccde818fc0ca
|