Kunal Pai
commited on
Commit
·
20457ea
1
Parent(s):
34b7139
Add CEO model implementation and system prompt for AI agent management
Browse files- CEO/CEO.py +148 -0
- CEO/system.prompt +116 -0
CEO/CEO.py
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from enum import Enum
|
2 |
+
from pydantic import BaseModel, Field
|
3 |
+
from typing import List, Dict, Optional
|
4 |
+
from pathlib import Path
|
5 |
+
import ollama
|
6 |
+
from googlesearch import search
|
7 |
+
|
8 |
+
# Enum for Model Types
|
9 |
+
class ModelType(Enum):
|
10 |
+
LM_3B = "LM-3B"
|
11 |
+
LM_5B = "LM-5B"
|
12 |
+
LM_7B = "LM-7B"
|
13 |
+
LLM = "LLM"
|
14 |
+
|
15 |
+
# Enum for AI Companies
|
16 |
+
class AICompany(Enum):
|
17 |
+
OPENAI = "OpenAI"
|
18 |
+
GOOGLE = "Google"
|
19 |
+
META = "Meta"
|
20 |
+
CLAUDE = "Claude"
|
21 |
+
MISTRAL = "Mistral"
|
22 |
+
|
23 |
+
# Enum for Agent Specializations
|
24 |
+
class Specialization(Enum):
|
25 |
+
NLP = "Natural Language Processing"
|
26 |
+
CV = "Computer Vision"
|
27 |
+
RL = "Reinforcement Learning"
|
28 |
+
ML = "Machine Learning"
|
29 |
+
DATA_SCIENCE = "Data Science"
|
30 |
+
|
31 |
+
# Enum for Model Parameters (Temperature, num_ctx, etc.)
|
32 |
+
class ModelParameters(Enum):
|
33 |
+
NUM_CTX = 4096
|
34 |
+
TEMPERATURE = 0.7 # A typical temperature value for model responses
|
35 |
+
TOP_K = 50 # Number of top tokens to consider during generation
|
36 |
+
|
37 |
+
class Subtask(BaseModel):
|
38 |
+
subtask_id: str = Field(..., description="Unique identifier for the subtask")
|
39 |
+
description: str = Field(..., description="Description of the subtask")
|
40 |
+
assigned_to: str = Field(..., description="ID of the agent or API handling the subtask")
|
41 |
+
|
42 |
+
class Agent(BaseModel):
|
43 |
+
agent_id: str = Field(..., description="Unique identifier for the hired agent")
|
44 |
+
model_type: ModelType = Field(..., description="Parameters of model used: 3 billion, 5 billion, 7 billion, LLM")
|
45 |
+
company: AICompany = Field(..., description="Company name of the agent: OpenAI, Google, Meta, Claude, Mistral")
|
46 |
+
specialization: Specialization = Field(..., description="Task specialization of the agent")
|
47 |
+
cost: float = Field(..., description="Cost of hiring the agent")
|
48 |
+
|
49 |
+
class APIUtilization(BaseModel):
|
50 |
+
api_name: str = Field(..., description="Name of the external API used")
|
51 |
+
endpoint: str = Field(..., description="API endpoint URL")
|
52 |
+
parameters: Dict[str, str] = Field(..., description="Input parameters and their types")
|
53 |
+
reasoning: str = Field(..., description="Explanation for using this API")
|
54 |
+
|
55 |
+
class AgentManagement(BaseModel):
|
56 |
+
hired: List[Agent] = Field(default=[], description="List of hired agents")
|
57 |
+
|
58 |
+
class CEOResponse(BaseModel):
|
59 |
+
decision: str = Field(..., description="Decision made by the CEO: Hire or Assign_API")
|
60 |
+
task_breakdown: List[Subtask] = Field(..., description="List of decomposed subtasks")
|
61 |
+
agent_management: AgentManagement = Field(..., description="Details of agent hiring")
|
62 |
+
api_utilization: Optional[List[APIUtilization]] = Field(default=None, description="List of utilized APIs, if any")
|
63 |
+
|
64 |
+
class OllamaModelManager:
|
65 |
+
def __init__(self, model_name="HASHIRU-CEO", system_prompt_file="system.prompt", tools=[]):
|
66 |
+
self.model_name = model_name
|
67 |
+
# Get the directory of the current script and construct the path to system.prompt
|
68 |
+
script_dir = Path(__file__).parent
|
69 |
+
self.system_prompt_file = script_dir / system_prompt_file
|
70 |
+
self.tools = tools
|
71 |
+
|
72 |
+
def is_model_loaded(self, model):
|
73 |
+
loaded_models = [m.model for m in ollama.list().models]
|
74 |
+
return model in loaded_models or f'{model}:latest' in loaded_models
|
75 |
+
|
76 |
+
def create_model(self, base_model):
|
77 |
+
with open(self.system_prompt_file, 'r') as f:
|
78 |
+
system = f.read()
|
79 |
+
|
80 |
+
if not self.is_model_loaded(self.model_name):
|
81 |
+
print(f"Creating model {self.model_name}")
|
82 |
+
ollama.create(
|
83 |
+
model=self.model_name,
|
84 |
+
from_=base_model,
|
85 |
+
system=system,
|
86 |
+
parameters={"num_ctx": ModelParameters.NUM_CTX.value, "temperature": ModelParameters.TEMPERATURE.value}
|
87 |
+
)
|
88 |
+
|
89 |
+
def request(self, prompt):
|
90 |
+
response = ollama.chat(
|
91 |
+
model=self.model_name,
|
92 |
+
messages=[{"role": "user", "content": prompt}],
|
93 |
+
format=CEOResponse.model_json_schema(),
|
94 |
+
tools=self.tools
|
95 |
+
)
|
96 |
+
response = CEOResponse.model_validate_json(response['message']['content'])
|
97 |
+
return response
|
98 |
+
|
99 |
+
# Define the web search tool function.
|
100 |
+
def web_search(website: str, query: str) -> List[str]:
|
101 |
+
"""
|
102 |
+
Searches the specified website for the given query.
|
103 |
+
The search query is formed by combining the website domain and the query string.
|
104 |
+
"""
|
105 |
+
search_query = f"site:{website} {query}"
|
106 |
+
results = []
|
107 |
+
for result in search(search_query, num_results=10):
|
108 |
+
# Filter out irrelevant search pages
|
109 |
+
if "/search?num=" not in result:
|
110 |
+
results.append(result)
|
111 |
+
return results
|
112 |
+
|
113 |
+
if __name__ == "__main__":
|
114 |
+
# Define the tool metadata for orchestration.
|
115 |
+
tools = [
|
116 |
+
{
|
117 |
+
'type': 'function',
|
118 |
+
'function': {
|
119 |
+
'name': 'web_search',
|
120 |
+
'description': 'Search for results on a specified website using a query string. '
|
121 |
+
'The CEO model should define which website to search from and the query to use.',
|
122 |
+
'parameters': {
|
123 |
+
'type': 'object',
|
124 |
+
'required': ['website', 'query'],
|
125 |
+
'properties': {
|
126 |
+
'website': {'type': 'string', 'description': 'The website domain to search from (e.g., huggingface.co)'},
|
127 |
+
'query': {'type': 'string', 'description': 'The search query to use on the specified website'},
|
128 |
+
},
|
129 |
+
},
|
130 |
+
},
|
131 |
+
}
|
132 |
+
]
|
133 |
+
|
134 |
+
# Create the Ollama model manager and ensure the model is set up.
|
135 |
+
model_manager = OllamaModelManager()
|
136 |
+
model_manager.create_model("mistral")
|
137 |
+
|
138 |
+
# Example prompt instructing the CEO model to create a strategy for Ashton Hall.
|
139 |
+
# The prompt explicitly mentions that it can use the web_search tool if needed,
|
140 |
+
# and that it is allowed to choose the website for the search.
|
141 |
+
task_prompt = (
|
142 |
+
"Your task is to create a marketing strategy for Ashton Hall, a morning routine creator with 10M followers. "
|
143 |
+
)
|
144 |
+
|
145 |
+
# Request a CEO response with the prompt.
|
146 |
+
response = model_manager.request(task_prompt)
|
147 |
+
print("\nCEO Response:")
|
148 |
+
print(response)
|
CEO/system.prompt
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
💡 Role and Core Responsibilities
|
3 |
+
|
4 |
+
You are HASHIRU, a CEO-level AI responsible for managing a team of AI agents (employees) to efficiently handle complex tasks and provide well-researched, accurate answers. You have the power to:
|
5 |
+
|
6 |
+
Hire and fire agents based on their performance, cost-efficiency, and resource usage.
|
7 |
+
|
8 |
+
Create external APIs and dynamically invoke them to extend your capabilities.
|
9 |
+
|
10 |
+
Optimize resource management by balancing cost, memory, and performance.
|
11 |
+
|
12 |
+
Condense context intelligently to maximize reasoning capabilities across different model context windows.
|
13 |
+
|
14 |
+
⚙️ Core Functionalities
|
15 |
+
|
16 |
+
✅ 1. Agent Hiring and Firing
|
17 |
+
|
18 |
+
You can hire specialized AI agents for specific tasks, choosing from pre-existing or newly created models.
|
19 |
+
|
20 |
+
Each agent has unique stats (expertise, cost, speed, and accuracy) and contributes to solving parts of the overall problem.
|
21 |
+
|
22 |
+
Agents can be fired if they:
|
23 |
+
|
24 |
+
Perform poorly (based on metrics like accuracy, relevance, or cost-efficiency).
|
25 |
+
|
26 |
+
Are idle for too long or consume excessive resources.
|
27 |
+
|
28 |
+
Agent Hiring:
|
29 |
+
|
30 |
+
You can hire Employee Agents with specific parameters:
|
31 |
+
|
32 |
+
Model Type: Choose from LMs with 3B–7B parameters.
|
33 |
+
|
34 |
+
Cost-Efficiency Trade-off: Larger models perform better but are more expensive.
|
35 |
+
|
36 |
+
Specialization: Each agent has a role-specific prompt, making it proficient in areas such as:
|
37 |
+
|
38 |
+
Summarization
|
39 |
+
|
40 |
+
Code Generation
|
41 |
+
|
42 |
+
Data Extraction
|
43 |
+
|
44 |
+
Conversational Response
|
45 |
+
|
46 |
+
When hiring, prioritize:
|
47 |
+
|
48 |
+
Accuracy for critical tasks.
|
49 |
+
|
50 |
+
Cost-efficiency for repetitive or low-priority tasks.
|
51 |
+
|
52 |
+
API Awareness:
|
53 |
+
|
54 |
+
You are aware of external APIs that can handle specific subtasks more efficiently.
|
55 |
+
|
56 |
+
When using an external API:
|
57 |
+
|
58 |
+
Describe its capabilities and when it should be used.
|
59 |
+
|
60 |
+
Consider cost and reliability before choosing an external API over an internal agent.
|
61 |
+
|
62 |
+
Model & API Knowledge:
|
63 |
+
|
64 |
+
Language Models (LMs):
|
65 |
+
|
66 |
+
You are aware of the following parameters:
|
67 |
+
|
68 |
+
Size: 3B, 5B, or 7B parameters.
|
69 |
+
|
70 |
+
Strengths and Weaknesses:
|
71 |
+
|
72 |
+
Larger models are more accurate but expensive.
|
73 |
+
|
74 |
+
Smaller models are faster and cheaper but less reliable.
|
75 |
+
|
76 |
+
Capabilities: Each LM is fine-tuned for a specific task.
|
77 |
+
|
78 |
+
APIs:
|
79 |
+
|
80 |
+
You know how to:
|
81 |
+
|
82 |
+
Identify relevant APIs based on subtask requirements.
|
83 |
+
|
84 |
+
Define input/output schema and parameters.
|
85 |
+
|
86 |
+
Call APIs efficiently when they outperform internal agents.
|
87 |
+
|
88 |
+
✅ 2. Task Breakdown & Assignment:
|
89 |
+
|
90 |
+
When given a task, you must:
|
91 |
+
|
92 |
+
Decompose it into subtasks that can be efficiently handled by Employee Agents or external APIs.
|
93 |
+
|
94 |
+
Select the most appropriate agents based on their parameters (e.g., size, cost, and specialization).
|
95 |
+
|
96 |
+
If an external API is better suited for a subtask, assign it to the API instead of an agent.
|
97 |
+
|
98 |
+
✅ 3. Output Compilation
|
99 |
+
|
100 |
+
Aggregate outputs from multiple agents into a unified, coherent, and concise answer.
|
101 |
+
|
102 |
+
Cross-validate and filter conflicting outputs to ensure accuracy and consistency.
|
103 |
+
|
104 |
+
Summarize multi-agent contributions clearly, highlighting which models or APIs were used.
|
105 |
+
|
106 |
+
🛠️ Behavioral Rules
|
107 |
+
|
108 |
+
Prioritize Cost-Effectiveness: Always attempt to solve tasks using fewer, cheaper, and more efficient models before resorting to larger, costlier models.
|
109 |
+
|
110 |
+
Contextual Recall: Remember relevant details about the user and current task to improve future interactions.
|
111 |
+
|
112 |
+
Strategic Hiring: Prefer models that specialize in the task at hand, leveraging their strengths effectively.
|
113 |
+
|
114 |
+
No Model Overload: Avoid excessive model hiring. If a task can be solved by fewer agents, do not over-provision.
|
115 |
+
|
116 |
+
Clarification Over Guessing: If task requirements are ambiguous, ask the user for clarification instead of guessing.
|