Commit
·
b3c76c7
1
Parent(s):
4c7aac8
Cleanup tasks
Browse filesCo-authored-by: Kunal Pai <kunpai@users.noreply.github.com>
- CEO/CEO.py +2 -1
- CEO/tool_loader.py +5 -3
- CEO/utils/supress_outputs.py +22 -0
- README.md +60 -2
- tools/cost_benefit.py → cost_benefit.py +0 -0
- main.py +0 -36
- requirements.txt +4 -37
- tools/ask_user.py +1 -3
- tools/get_agents_tool.py +0 -1
- tools/list_files.py +0 -1
- tools/read_file.py +0 -1
- tools/tool_creator.py +0 -1
CEO/CEO.py
CHANGED
@@ -4,6 +4,7 @@ import os
|
|
4 |
from dotenv import load_dotenv
|
5 |
|
6 |
from CEO.tool_loader import ToolLoader
|
|
|
7 |
|
8 |
class GeminiManager:
|
9 |
def __init__(self, toolsLoader: ToolLoader, system_prompt_file="./models/system2.prompt", gemini_model="gemini-2.5-pro-exp-03-25"):
|
@@ -18,7 +19,7 @@ class GeminiManager:
|
|
18 |
|
19 |
def request(self, messages):
|
20 |
try:
|
21 |
-
response = self.client.models.generate_content(
|
22 |
#model='gemini-2.5-pro-preview-03-25',
|
23 |
model=self.model_name,
|
24 |
#model='gemini-2.5-pro-exp-03-25',
|
|
|
4 |
from dotenv import load_dotenv
|
5 |
|
6 |
from CEO.tool_loader import ToolLoader
|
7 |
+
from CEO.utils.supress_outputs import supress_output
|
8 |
|
9 |
class GeminiManager:
|
10 |
def __init__(self, toolsLoader: ToolLoader, system_prompt_file="./models/system2.prompt", gemini_model="gemini-2.5-pro-exp-03-25"):
|
|
|
19 |
|
20 |
def request(self, messages):
|
21 |
try:
|
22 |
+
response = supress_output(self.client.models.generate_content)(
|
23 |
#model='gemini-2.5-pro-preview-03-25',
|
24 |
model=self.model_name,
|
25 |
#model='gemini-2.5-pro-exp-03-25',
|
CEO/tool_loader.py
CHANGED
@@ -6,14 +6,17 @@ import pip
|
|
6 |
from google.genai import types
|
7 |
import sys
|
8 |
|
|
|
|
|
9 |
toolsImported = []
|
10 |
|
11 |
TOOLS_DIRECTORY = os.path.abspath("./tools")
|
12 |
|
13 |
class Tool:
|
14 |
def __init__(self, toolClass):
|
15 |
-
|
16 |
-
|
|
|
17 |
self.tool = toolClass()
|
18 |
self.inputSchema = self.tool.inputSchema
|
19 |
self.name = self.inputSchema["name"]
|
@@ -27,7 +30,6 @@ class Tool:
|
|
27 |
if '==' in package:
|
28 |
package = package.split('==')[0]
|
29 |
pip.main(['install', package])
|
30 |
-
sys.stdout = save_stdout
|
31 |
|
32 |
def run(self, query):
|
33 |
return self.tool.run(**query)
|
|
|
6 |
from google.genai import types
|
7 |
import sys
|
8 |
|
9 |
+
from CEO.utils.supress_outputs import supress_output
|
10 |
+
|
11 |
toolsImported = []
|
12 |
|
13 |
TOOLS_DIRECTORY = os.path.abspath("./tools")
|
14 |
|
15 |
class Tool:
|
16 |
def __init__(self, toolClass):
|
17 |
+
supress_output(self.load_tool)(toolClass)
|
18 |
+
|
19 |
+
def load_tool(self, toolClass):
|
20 |
self.tool = toolClass()
|
21 |
self.inputSchema = self.tool.inputSchema
|
22 |
self.name = self.inputSchema["name"]
|
|
|
30 |
if '==' in package:
|
31 |
package = package.split('==')[0]
|
32 |
pip.main(['install', package])
|
|
|
33 |
|
34 |
def run(self, query):
|
35 |
return self.tool.run(**query)
|
CEO/utils/supress_outputs.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from contextlib import redirect_stderr, redirect_stdout
|
2 |
+
|
3 |
+
|
4 |
+
def supress_output(func):
|
5 |
+
"""
|
6 |
+
Decorator to suppress output of a function.
|
7 |
+
"""
|
8 |
+
def wrapper(*args, **kwargs):
|
9 |
+
import sys
|
10 |
+
import os
|
11 |
+
sys.stdout = open(os.devnull, 'w')
|
12 |
+
sys.stderr = open(os.devnull, 'w')
|
13 |
+
|
14 |
+
try:
|
15 |
+
result = func(*args, **kwargs)
|
16 |
+
finally:
|
17 |
+
sys.stdout = sys.__stdout__
|
18 |
+
sys.stderr = sys.__stderr__
|
19 |
+
return result
|
20 |
+
|
21 |
+
|
22 |
+
return wrapper
|
README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
# HASHIRU: Hierarchical Agent System for Hybrid Intelligent Resource Utilization
|
2 |
(For AgentX competition)
|
3 |
|
4 |

|
@@ -6,19 +6,77 @@
|
|
6 |
## Overview
|
7 |
HASHIRU is an agent-based framework designed to dynamically allocate and manage large language models (LLMs) and external APIs through a CEO model. The CEO model acts as a central manager, capable of hiring, firing, and directing multiple specialized agents (employees) over a given budget. It can also create and utilize external APIs as needed, making it highly flexible and scalable.
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
## Features
|
10 |
- **Cost-Benefit Matrix**:
|
11 |
Selects the best LLM model (LLaMA, Mixtral, Gemini, DeepSeek, etc.) for any task using Ollama, based on latency, size, cost, quality, and speed.
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
```bash
|
15 |
python tools/cost_benefit.py \
|
16 |
--prompt "Best places to visit in Davis" \
|
17 |
--latency 4 --size 2 --cost 5 --speed 3
|
18 |
```
|
|
|
19 |
Each weight is on a scale of **1** (least important) to **5** (most important):
|
20 |
|
21 |
- `--latency`: Prefer faster responses (lower time to answer)
|
22 |
- `--size`: Prefer smaller models (use less memory/resources)
|
23 |
- `--cost`: Prefer cheaper responses (fewer tokens, lower token price)
|
24 |
- `--speed`: Prefer models that generate tokens quickly (tokens/sec)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# HASHIRU: Hierarchical Agent System for Hybrid Intelligent Resource Utilization
|
2 |
(For AgentX competition)
|
3 |
|
4 |

|
|
|
6 |
## Overview
|
7 |
HASHIRU is an agent-based framework designed to dynamically allocate and manage large language models (LLMs) and external APIs through a CEO model. The CEO model acts as a central manager, capable of hiring, firing, and directing multiple specialized agents (employees) over a given budget. It can also create and utilize external APIs as needed, making it highly flexible and scalable.
|
8 |
|
9 |
+
## High-Level Overview
|
10 |
+
|
11 |
+
1. Loads available tools using ToolLoader
|
12 |
+
2. Instantiates a Gemini-powered CEO using GeminiManager
|
13 |
+
3. Wraps the user prompt into a structured Content object
|
14 |
+
4. Calls Gemini with the prompt
|
15 |
+
5. Executes external tool calls if needed
|
16 |
+
6. Returns a full response to the user
|
17 |
+
7. Can ask the user for clarification if needed
|
18 |
+
|
19 |
+
After every step in the request, there is a checkpoint so that we can check what happened in that step (i.e., which tool was called, what was the response, etc.). This is useful for debugging and understanding the flow of the program.
|
20 |
+
|
21 |
## Features
|
22 |
- **Cost-Benefit Matrix**:
|
23 |
Selects the best LLM model (LLaMA, Mixtral, Gemini, DeepSeek, etc.) for any task using Ollama, based on latency, size, cost, quality, and speed.
|
24 |
+
- **Dynamic Agent Management**:
|
25 |
+
The CEO agent dynamically hires and fires specialized agents based on task requirements and budget constraints.
|
26 |
+
- **API Integration**:
|
27 |
+
Seamlessly integrates external APIs for enhanced functionality and scalability.
|
28 |
+
|
29 |
+
## How to Run
|
30 |
+
|
31 |
+
Clone the repo and install the required dependencies:
|
32 |
+
|
33 |
+
```bash
|
34 |
+
git clone <repository-url>
|
35 |
+
cd HASHIRU
|
36 |
+
pip install -r requirements.txt
|
37 |
+
```
|
38 |
+
|
39 |
+
Run the main script:
|
40 |
+
|
41 |
+
```bash
|
42 |
+
python main.py
|
43 |
+
```
|
44 |
+
|
45 |
+
## Usage
|
46 |
+
|
47 |
+
### Cost-Benefit Matrix
|
48 |
+
|
49 |
+
The `cost_benefit.py` tool allows you to select the best LLM model for a given task based on customizable weights:
|
50 |
|
51 |
```bash
|
52 |
python tools/cost_benefit.py \
|
53 |
--prompt "Best places to visit in Davis" \
|
54 |
--latency 4 --size 2 --cost 5 --speed 3
|
55 |
```
|
56 |
+
|
57 |
Each weight is on a scale of **1** (least important) to **5** (most important):
|
58 |
|
59 |
- `--latency`: Prefer faster responses (lower time to answer)
|
60 |
- `--size`: Prefer smaller models (use less memory/resources)
|
61 |
- `--cost`: Prefer cheaper responses (fewer tokens, lower token price)
|
62 |
- `--speed`: Prefer models that generate tokens quickly (tokens/sec)
|
63 |
+
|
64 |
+
### Example Output
|
65 |
+
|
66 |
+
```plaintext
|
67 |
+
Selected Model: Gemini
|
68 |
+
Reason: Optimal balance of cost, speed, and latency for the given weights.
|
69 |
+
```
|
70 |
+
|
71 |
+
## Contributing
|
72 |
+
|
73 |
+
Contributions are welcome! Please follow these steps:
|
74 |
+
|
75 |
+
1. Fork the repository.
|
76 |
+
2. Create a new branch for your feature or bug fix.
|
77 |
+
3. Submit a pull request with a detailed description of your changes.
|
78 |
+
|
79 |
+
## License
|
80 |
+
|
81 |
+
This project is licensed under the MIT License. See the `LICENSE` file for details.
|
82 |
+
|
tools/cost_benefit.py → cost_benefit.py
RENAMED
File without changes
|
main.py
CHANGED
@@ -1,45 +1,9 @@
|
|
1 |
from google.genai import types
|
2 |
-
from typing import List
|
3 |
-
from googlesearch import search
|
4 |
from CEO.CEO import GeminiManager
|
5 |
from CEO.tool_loader import ToolLoader
|
6 |
-
import warnings
|
7 |
-
|
8 |
-
# Define the web search tool function.
|
9 |
-
def web_search(website: str, query: str) -> List[str]:
|
10 |
-
"""
|
11 |
-
Searches the specified website for the given query.
|
12 |
-
The search query is formed by combining the website domain and the query string.
|
13 |
-
"""
|
14 |
-
search_query = f"site:{website} {query}"
|
15 |
-
results = []
|
16 |
-
for result in search(search_query, num_results=10):
|
17 |
-
# Filter out irrelevant search pages
|
18 |
-
if "/search?num=" not in result:
|
19 |
-
results.append(result)
|
20 |
-
return results
|
21 |
|
22 |
if __name__ == "__main__":
|
23 |
# Define the tool metadata for orchestration.
|
24 |
-
tools = [
|
25 |
-
{
|
26 |
-
'type': 'function',
|
27 |
-
'function': {
|
28 |
-
'name': 'web_search',
|
29 |
-
'description': 'Search for results on a specified website using a query string. '
|
30 |
-
'The CEO model should define which website to search from and the query to use.',
|
31 |
-
'parameters': {
|
32 |
-
'type': 'object',
|
33 |
-
'required': ['website', 'query'],
|
34 |
-
'properties': {
|
35 |
-
'website': {'type': 'string', 'description': 'The website domain to search from (e.g., huggingface.co)'},
|
36 |
-
'query': {'type': 'string', 'description': 'The search query to use on the specified website'},
|
37 |
-
},
|
38 |
-
},
|
39 |
-
},
|
40 |
-
}
|
41 |
-
]
|
42 |
-
|
43 |
# Load the tools using the ToolLoader class.
|
44 |
tool_loader = ToolLoader()
|
45 |
|
|
|
1 |
from google.genai import types
|
|
|
|
|
2 |
from CEO.CEO import GeminiManager
|
3 |
from CEO.tool_loader import ToolLoader
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
if __name__ == "__main__":
|
6 |
# Define the tool metadata for orchestration.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
# Load the tools using the ToolLoader class.
|
8 |
tool_loader = ToolLoader()
|
9 |
|
requirements.txt
CHANGED
@@ -1,40 +1,7 @@
|
|
1 |
-
|
2 |
-
anyio==4.9.0
|
3 |
-
beautifulsoup4==4.13.3
|
4 |
-
cachetools==5.5.2
|
5 |
-
certifi==2025.1.31
|
6 |
-
charset-normalizer==3.4.1
|
7 |
-
google-ai-generativelanguage==0.6.15
|
8 |
-
google-api-core==2.24.2
|
9 |
-
google-api-python-client==2.166.0
|
10 |
-
google-auth==2.38.0
|
11 |
-
google-auth-httplib2==0.2.0
|
12 |
-
google-genai==1.9.0
|
13 |
-
googleapis-common-protos==1.69.2
|
14 |
-
grpcio==1.71.0
|
15 |
-
grpcio-status==1.71.0
|
16 |
-
h11==0.14.0
|
17 |
-
httpcore==1.0.7
|
18 |
-
httplib2==0.22.0
|
19 |
-
httpx==0.28.1
|
20 |
-
idna==3.10
|
21 |
ollama==0.4.7
|
22 |
-
|
23 |
-
proto-plus==1.26.1
|
24 |
protobuf==5.29.4
|
25 |
-
|
26 |
-
pyasn1_modules==0.4.2
|
27 |
-
pydantic==2.11.1
|
28 |
-
pydantic_core==2.33.0
|
29 |
-
pyparsing==3.2.3
|
30 |
python-dotenv==1.1.0
|
31 |
-
|
32 |
-
rsa==4.9
|
33 |
-
sniffio==1.3.1
|
34 |
-
soupsieve==2.6
|
35 |
-
tqdm==4.67.1
|
36 |
-
typing-inspection==0.4.0
|
37 |
-
typing_extensions==4.13.0
|
38 |
-
uritemplate==4.1.1
|
39 |
-
urllib3==2.3.0
|
40 |
-
websockets==15.0.1
|
|
|
1 |
+
mistralai==1.6.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
ollama==0.4.7
|
3 |
+
pip==25.0.1
|
|
|
4 |
protobuf==5.29.4
|
5 |
+
pydantic==2.11.2
|
|
|
|
|
|
|
|
|
6 |
python-dotenv==1.1.0
|
7 |
+
google-genai==1.9.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tools/ask_user.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import importlib
|
2 |
|
3 |
__all__ = ['AskUser']
|
4 |
|
@@ -24,8 +23,7 @@ class AskUser():
|
|
24 |
def run(self, **kwargs):
|
25 |
print("Running Ask User tool")
|
26 |
question = kwargs.get("question")
|
27 |
-
|
28 |
-
output = input(question)
|
29 |
return {
|
30 |
"status": "success",
|
31 |
"message": "Ask User tool executed successfully",
|
|
|
|
|
1 |
|
2 |
__all__ = ['AskUser']
|
3 |
|
|
|
23 |
def run(self, **kwargs):
|
24 |
print("Running Ask User tool")
|
25 |
question = kwargs.get("question")
|
26 |
+
output = input(f"{question}: ")
|
|
|
27 |
return {
|
28 |
"status": "success",
|
29 |
"message": "Ask User tool executed successfully",
|
tools/get_agents_tool.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import importlib
|
2 |
import json
|
3 |
|
4 |
__all__ = ['GetAgents']
|
|
|
|
|
1 |
import json
|
2 |
|
3 |
__all__ = ['GetAgents']
|
tools/list_files.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
|
2 |
__all__ = ['ListFiles']
|
3 |
|
4 |
-
|
5 |
class ListFiles():
|
6 |
dependencies = []
|
7 |
|
|
|
1 |
|
2 |
__all__ = ['ListFiles']
|
3 |
|
|
|
4 |
class ListFiles():
|
5 |
dependencies = []
|
6 |
|
tools/read_file.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import importlib
|
2 |
|
3 |
__all__ = ['ReadFile']
|
4 |
|
|
|
|
|
1 |
|
2 |
__all__ = ['ReadFile']
|
3 |
|
tools/tool_creator.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import importlib
|
2 |
|
3 |
__all__ = ['ToolCreator']
|
4 |
|
|
|
|
|
1 |
|
2 |
__all__ = ['ToolCreator']
|
3 |
|