# How to Develop Agents

To develop new agents to run on AIOS, it provides the [native Agent-SDK](https://docs.aios.foundation/aios-docs/aios-agent/how-to-develop-agents/develop-with-native-sdk) and various adapters to adapt different agent frameworks into AIOS.&#x20;

Below shows the agent frameworks that have been integrated and the current integration modules.&#x20;

The table below shows the agent frameworks we have integrated and different modules that have been integrated, and the details can be found in later sections.&#x20;

<table><thead><tr><th width="288">Agent Framework</th><th>Integrated Module</th></tr></thead><tbody><tr><td>AutoGen</td><td><code>LLM</code></td></tr><tr><td>Open-Interpreter</td><td><code>LLM</code></td></tr><tr><td>MetaGPT</td><td><code>LLM</code></td></tr></tbody></table>

Before developing agents, it is required to follow the guidelines of how to organize the agent files in the following structure.&#x20;

#### Agent Structure

First, let's look at how to organize your agent's files. Every agent needs three mandatory components:

```
author/
└── agent_name/
      │── entry.py        # Your agent's main logic
      │── config.json     # Configuration and metadata
      └── meta_requirements.txt  # Additional dependencies
```

For example, if your name is demo\_author and you're building a demo\_agent that searches and summarizes articles, your folder structure would look like this:

```
demo_author/
   └── demo_agent/
         │── entry.py
         │── config.json
         └── meta_requirements.txt
```

Note: If your agent needs any libraries beyond AIOS's built-in ones, make sure to list them in meta\_requirements.txt. Apart from the above three files, you can have any other files in your folder.

A minimal example of an agent is shown as below

```python
from cerebrum.llm.apis import LLMQuery, LLMResponse
from cerebrum.utils.communication import send_request, aios_kernel_url

class TestAgent:
    def __init__(self, agent_name):
        self.agent_name = agent_name
        self.messages = []

    def run(self, task_input):
        self.messages.append({"role": "user", "content": task_input})
        
        tool_response = llm_chat(
            agent_name=self.agent_name,
            messages=self.messages,
            base_url=aios_kernel_url
        )
        
        final_result = tool_response["response"]["response_message"]
        return final_result
    def __init__(self, agent_name, task_input, config_):
        super().__init__(agent_name, task_input, config_)

    def run(self):
        response = self.send_request(
            agent_name = self.agent_name,
            query=LLMQuery(
                messages=[{"role": "user", "content": "What is the capital of US? "}]
            )
        )
        print(response)
        return response
```

**\[Important]: Rules to be strictly followed in the entry.py**

* The agent class must inherit the BaseAgent from <https://github.com/agiresearch/Cerebrum/blob/main/cerebrum/agents/base.py>
* The agent class must have a `run` method as the main function to be executed
* All the interactions with AIOS kernel must be through the `send_request` API, otherwise the services provided by the AIOS will not support for the agents.&#x20;

#### Configure the agent

Your agent needs a config.json file that describes its functionality. Here's what it should include:

```json
{
   "name": "demo_agent",
   "description": [
      "Demo agent that can help search AIOS-related papers"
   ],
   "tools": [
      "demo_author/arxiv"
   ],
   "meta": {
      "author": "demo_author",
      "version": "0.0.1",
      "license": "CC0"
   },
   "build": {
      "entry": "agent.py",
      "module": "DemoAgent"
   }
}
```

When setting up your agent, you'll need to specify which tools it will use.&#x20;

View tools available in the AIOS Tool Hub:

```bash
list-toolhub-tools
```

View tools available locally:

```bash
list-local-tools
```

To use these tools in your agent, use the [`AutoTool`](https://github.com/agiresearch/Cerebrum/blob/main/cerebrum/interface/__init__.py) provided by the AIOS SDK to load these tools within your agent logic.&#x20;

To load a tool from ToolHub in your code:

```python
from cerebrum.interface import AutoTool
tool = AutoTool.from_preloaded("example/arxiv", local=False)
```

To load a local tool in your code:

```python
from cerebrum.tool import AutoTool
tool = AutoTool.from_preloaded("google/google_search", local=True)
```

If you would like to create your new tools, you can either integrate the tool within your agent code or you can follow the tool examples in the tool folder to develop your standalone tools. The detailed instructions are in [How to develop new tools](https://docs.aios.foundation/aios-docs/aios-agent-sdk/tool-api/how-to-develop-tools).&#x20;
