The goal of AIOS is to build a Large Language Model (LLM) agent operating system, which intends to embed large language model into the operating system as the brain of the OS. AIOS is designed to address problems (e.g., scheduling, context switch, memory management, etc.) during the development and deployment of LLM-based agents, for a better ecosystem among agent developers and users.
The AIOS-Agent SDK is designed for agent users and developers, enabling them to build and run agent applications by interacting with the AIOS kernel.
- [2024-11-26] π₯ Cerebrum is available for public release on PyPI!
-
Install the package
pip install aios-agent-sdk
-
Verify installation
python -c "import cerebrum; from cerebrum.client import Cerebrum; print(Cerebrum)"
-
Clone Repo
git clone https://github.com/agiresearch/Cerebrum.git cd Cerebrum
-
Create Virtual Environment
conda create -n cerebrum-env python=3.10
or
conda create -n cerebrum-env python=3.11
or
# Windows (cmd) python -m venv cerebrum-env # Linux/MacOS python3 -m venv cerebrum-env
-
Activate the environment
conda activate myenv
or
# Windows (cmd) cd cerebrum-env cd Scripts activate.bat cd .. cd .. # Linux/MacOS source cerebrum-env/bin/activate
-
Install the package
pip install -e .
-
Verify installation
python -c "import cerebrum; from cerebrum.client import Cerebrum; print(Cerebrum)"
Tip
Please see our documentation for more information.
-
Start the AIOS Kernel π See here.
-
Run the AIOS Client
Run the client with a single agent
aios-basic-demo --llm_name gpt-4o-mini --llm_backend openai --agent <replace with the actual agent> --task <replace with the actual task>
Code file is located at
cerebrum/example/aios_demo.py
Run the client with agents concurrently
aios-concurrent-demo --llm_name gpt-4o-mini --llm_backend openai
Code file is located at
cerebrum/example/aios_demo_concurrent.py
Before you develop your own agents and would like to run that on AIOS, you need to make sure that structure of agent is strictly organized as below.
You need to put the agent folder as the following structure
author/
βββ agent_name/
βββ entry.py # the entry file to run your new agents
βββ config.json # agent information, e.g., name, usage, license, etc.
βββ meta_requirements.txt # specific dependencies used for running your agent
For example, your author name is βexampleβ, and you have developed an agent called demo_agent used for searching and summarizing articles. Your local folder will be like the following:
example/
βββ dem_agent/
βββ entry.py
βββ config.json
βββ meta_requirements.txt
If your agent requires extra libraries (in addition to the AIOS-dependent libraries) to run, you must put them in the meta_requirements.txt.
These three files (config.json, entry.py, meta_requirements.txt) are the minimal requirements to be had in the agent implementations.
After you have setup the agent folder, you can then follow the instructions below to develop your agents.
You are required to include a JSON file with all the metadata used for the agent you would like to develop including the following attributes:
{
"name": "name of the agent",
"description": [
"description of the agent functionality"
],
"tools": [
"tools need to be used"
],
"meta": {
"author": "",
"version": "",
"license": ""
},
"build": {
"entry": "entry file to start the agent",
"module": "the module name of the agent"
}
}
The table below shows current available tools and provides how to set them in the configuration. Their source code can be found at the tool folder.
Author | Name | How to set them in the configuration |
---|---|---|
example | arxiv | example/arxiv |
example | bing_search | example/bing_search |
example | currency_converter | example/currency_converter |
example | wolfram_alpha | example/wolfram_alpha |
example | google_search | example/google_search |
openai | speech_to_text | openai/speech_to_text |
example | web_browser | example/web_browser |
timbrooks | image_to_image | timbrooks/image_to_image |
example | downloader | example/downloader |
example | doc_question_answering | example/doc_question_answering |
stability-ai | text_to_image | stability-ai/text_to_image |
example | text_to_speech | example/text_to_speech |
If you would like to develop your new tools, you can refer to the too
Here provides a minimal example of how to build your agents.
First, you need to construct an agent class which is exactly the same name you set up for the module in the JSON file. To connect to the AIOS, you need to inherit the BaseAgent class and override the init and run method.
from cerebrum.agents.base import BaseAgent
import json
class DemoAgent(BaseAgent):
def __init__(self, agent_name, task_input, config_):
super().__init__(agent_name, task_input, config_)
pass
For now, we provide four different query classes to interact with different modules in the AIOS and use the Response format to receive results by sending queries.
from cerebrum.llm.communication import LLMQuery # use LLMQuery as an example
Below shows how to use different queries (MemoryQuery and StorageQuery are under development).
class | Arguments | Output |
---|---|---|
LLMQuery | messages: List, tools: List, action_type: str, message_return_type: str | response: Response |
MemoryQuery | TBD | response: Response |
StorageQuery | TBD | response: Response |
ToolQuery | tool_calls: List | response: Response |
Then you need construct your own system prompts for your agent, below shows a simple example.
def build_system_instruction(self):
prefix = "".join(["".join(self.config["description"])])
plan_instruction = "".join(
[
f"You are given the available tools from the tool list: {json.dumps(self.tool_info)} to help you solve problems. ",
"Generate a plan with comprehensive yet minimal steps to fulfill the task. ",
"The plan must follow the json format as below: ",
"[",
'{"action_type": "action_type_value", "action": "action_value","tool_use": [tool_name1, tool_name2,...]}',
'{"action_type": "action_type_value", "action": "action_value", "tool_use": [tool_name1, tool_name2,...]}',
"...",
"]",
"In each step of the planned plan, identify tools to use and recognize no tool is necessary. ",
"Followings are some plan examples. ",
"[" "[",
'{"action_type": "tool_use", "action": "gather information from arxiv. ", "tool_use": ["arxiv"]},',
'{"action_type": "chat", "action": "write a summarization based on the gathered information. ", "tool_use": []}',
"];",
"[",
'{"action_type": "tool_use", "action": "gather information from arxiv. ", "tool_use": ["arxiv"]},',
'{"action_type": "chat", "action": "understand the current methods and propose ideas that can improve ", "tool_use": []}',
"]",
"]",
]
)
if self.workflow_mode == "manual":
self.messages.append({"role": "system", "content": prefix})
else:
assert self.workflow_mode == "automatic"
self.messages.append({"role": "system", "content": prefix})
self.messages.append({"role": "user", "content": plan_instruction})
You can either build workflow by manual definition
def manual_workflow(self):
workflow = [
{
"action_type": "chat",
"action": "Identify user's target language and learning goals and create grammar explanations and practice sentences.",
"tool_use": []
},
{
"action_type": "chat",
"action": "Provide audio examples of pronunciation.",
"tool_use": []
},
{
"action_type": "chat",
"action": "Engage in conversation practice with the user.",
"tool_use": []
}
]
return workflow
or generate workflow automatically.
def automatic_workflow(self):
for i in range(self.plan_max_fail_times):
response = self.send_request(
agent_name=self.agent_name,
query=LLMQuery(
messages=self.messages, tools=None, message_return_type="json"
),
)["response"]
workflow = self.check_workflow(response.response_message)
self.rounds += 1
if workflow:
return workflow
else:
self.messages.append(
{
"role": "assistant",
"content": f"Fail {i+1} times to generate a valid plan. I need to regenerate a plan",
}
)
return None
After defining your workflows, you can build the run method.
def run(self):
self.build_system_instruction()
task_input = self.task_input
self.messages.append({"role": "user", "content": task_input})
workflow = None
if self.workflow_mode == "automatic":
workflow = self.automatic_workflow()
self.messages = self.messages[:1] # clear long context
else:
assert self.workflow_mode == "manual"
workflow = self.manual_workflow()
self.messages.append(
{
"role": "user",
"content": f"[Thinking]: The workflow generated for the problem is {json.dumps(workflow)}. Follow the workflow to solve the problem step by step. ",
}
)
try:
if workflow:
final_result = ""
for i, step in enumerate(workflow):
action_type = step["action_type"]
action = step["action"]
tool_use = step["tool_use"]
prompt = f"At step {i + 1}, you need to: {action}. "
self.messages.append({"role": "user", "content": prompt})
if tool_use:
selected_tools = self.pre_select_tools(tool_use)
else:
selected_tools = None
response = self.send_request(
agent_name=self.agent_name,
query=LLMQuery(
messages=self.messages,
tools=selected_tools,
action_type=action_type,
),
)["response"]
self.messages.append({"role": "assistant", "content": response.response_message})
self.rounds += 1
final_result = self.messages[-1]["content"]
return {
"agent_name": self.agent_name,
"result": final_result,
"rounds": self.rounds,
}
else:
return {
"agent_name": self.agent_name,
"result": "Failed to generate a valid workflow in the given times.",
"rounds": self.rounds,
}
except Exception as e:
return {}
To run your new developed agents, you can pass the absolute path for the agent and assign the task using the aios_demo.py script by setting up the llm_name and the llm_backend.
python aios_demo.py --llm_name <llm_name> --llm_backend <llm_backend> --
Provider π’ | Model Name π€ | Open Source π | Model String β¨οΈ | Backend βοΈ |
---|---|---|---|---|
Anthropic | Claude 3.5 Sonnet | β | claude-3-5-sonnet-20241022 | anthropic |
Anthropic | Claude 3.5 Haiku | β | claude-3-5-haiku-20241022 | anthropic |
Anthropic | Claude 3 Opus | β | claude-3-opus-20240229 | anthropic |
Anthropic | Claude 3 Sonnet | β | claude-3-sonnet-20240229 | anthropic |
Anthropic | Claude 3 Haiku | β | claude-3-haiku-20240307 | anthropic |
OpenAI | GPT-4 | β | gpt-4 | openai |
OpenAI | GPT-4 Turbo | β | gpt-4-turbo | openai |
OpenAI | GPT-4o | β | gpt-4o | openai |
OpenAI | GPT-4o mini | β | gpt-4o-mini | openai |
OpenAI | GPT-3.5 Turbo | β | gpt-3.5-turbo | openai |
Gemini 1.5 Flash | β | gemini-1.5-flash | ||
Gemini 1.5 Flash-8B | β | gemini-1.5-flash-8b | ||
Gemini 1.5 Pro | β | gemini-1.5-pro | ||
Gemini 1.0 Pro | β | gemini-1.0-pro | ||
Groq | Llama 3.2 90B Vision | β | llama-3.2-90b-vision-preview | groq |
Groq | Llama 3.2 11B Vision | β | llama-3.2-11b-vision-preview | groq |
Groq | Llama 3.1 70B | β | llama-3.1-70b-versatile | groq |
Groq | Llama Guard 3 8B | β | llama-guard-3-8b | groq |
Groq | Llama 3 70B | β | llama3-70b-8192 | groq |
Groq | Llama 3 8B | β | llama3-8b-8192 | groq |
Groq | Mixtral 8x7B | β | mixtral-8x7b-32768 | groq |
Groq | Gemma 7B | β | gemma-7b-it | groq |
Groq | Gemma 2B | β | gemma2-9b-it | groq |
Groq | Llama3 Groq 70B | β | llama3-groq-70b-8192-tool-use-preview | groq |
Groq | Llama3 Groq 8B | β | llama3-groq-8b-8192-tool-use-preview | groq |
ollama | All Models | β | model-name | ollama |
vLLM | All Models | β | model-name | vllm |
HuggingFace | All Models | β | model-name | huggingface |
@article{mei2024aios,
title={AIOS: LLM Agent Operating System},
author={Mei, Kai and Li, Zelong and Xu, Shuyuan and Ye, Ruosong and Ge, Yingqiang and Zhang, Yongfeng}
journal={arXiv:2403.16971},
year={2024}
}
@article{ge2023llm,
title={LLM as OS, Agents as Apps: Envisioning AIOS, Agents and the AIOS-Agent Ecosystem},
author={Ge, Yingqiang and Ren, Yujie and Hua, Wenyue and Xu, Shuyuan and Tan, Juntao and Zhang, Yongfeng},
journal={arXiv:2312.03815},
year={2023}
}
For how to contribute, see CONTRIBUTE. If you would like to contribute to the codebase, issues or pull requests are always welcome!
If you would like to join the community, ask questions, chat with fellows, learn about or propose new features, and participate in future developments, join our Discord Community!
For issues related to Cerebrum development, we encourage submitting issues, pull requests, or initiating discussions in AIOS Discord Channel. For other issues please feel free to contact the AIOS Foundation ([email protected]).