Skip to content

Commit

Permalink
UI supporting (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
JimSalesforce authored Apr 22, 2024
2 parents 4d0d24a + 2960fcb commit 2e22803
Show file tree
Hide file tree
Showing 23 changed files with 49 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data/
bin/
include/
.chainlit
.files

# Python virtualenv
.venv
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
AgentLite is a research-oriented library designed for building and advancing LLM-based task-oriented agent systems. It simplifies the implementation of new agent/multi-agent architectures, enabling easy orchestration of multiple agents through a manager agent. Whether you're building individual agents or complex multi-agent systems, AgentLite provides a straightforward and lightweight foundation for your research and development. Check more details in [our paper](https://arxiv.org/abs/2402.15538).

## 🎉 News
- **[04.2024]** [UI Supporting](./app/Homepage.py) is released for AgentLite!
- **[03.2024]** [xLAM model](https://huggingface.co/collections/Salesforce/xlam-models-65f00e2a0a63bbcd1c2dade4) and [xLAM code](https://github.com/SalesforceAIResearch/xLAM) is released! Try it with [AgentLite benchmark](./benchmark/), which is comparable to GPT-4!
- **[03.2024]** We developed all the agent architectures in [BOLAA](https://arxiv.org/pdf/2308.05960.pdf) with AgentLite. Check our [new benchmark](./benchmark/)
- **[02.2024]** Initial Release of AgentLite library and [paper](https://arxiv.org/abs/2402.15538)!
Expand Down Expand Up @@ -63,6 +64,16 @@ export OPENAI_API_KEY=<INSERT YOUR OpenAI API KEY HERE>
python ./example/SearchManager.py
```

## 🖥️ UI Supporting
We provide a simple UI feature with AgentLite for demo purpose. To enable this capbility, uncomment the UI parts in [requirements.txt](./requirements.txt) to install the steamlite package.
After installation, start with
```shell
steamlite run app/Homepage.py
```
Check our recorded UI demo.
![UI demo](./image/weather_agent.gif)


## 🔍 Examples

### Building Individual Agents
Expand Down
2 changes: 1 addition & 1 deletion agentlite/agents/BaseAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from agentlite.commons.AgentAct import ActObsChainType
from agentlite.llm.agent_llms import BaseLLM
from agentlite.logging import DefaultLogger
from agentlite.logging.multi_agent_log import AgentLogger
from agentlite.logging.terminal_logger import AgentLogger
from agentlite.memory.AgentSTMemory import AgentSTMemory, DictAgentSTMemory

from .ABCAgent import ABCAgent
Expand Down
2 changes: 1 addition & 1 deletion agentlite/agents/ManagerAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from agentlite.commons.AgentAct import ActObsChainType
from agentlite.llm.agent_llms import BaseLLM
from agentlite.logging import DefaultLogger
from agentlite.logging.multi_agent_log import AgentLogger
from agentlite.logging.terminal_logger import AgentLogger

from .ABCAgent import ABCAgent
from .BaseAgent import BaseAgent
Expand Down
2 changes: 1 addition & 1 deletion agentlite/logging/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from agentlite.logging.multi_agent_log import AgentLogger
from agentlite.logging.terminal_logger import AgentLogger

DefaultLogger = AgentLogger()
11 changes: 7 additions & 4 deletions agentlite/logging/BaseLogger.py → agentlite/logging/base.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import os
from abc import ABC, abstractmethod

from agentlite.commons import AgentAct, TaskPackage
from agentlite.logging.utils import *
from agentlite.utils import bcolors


class BaseAgentLogger:

class BaseAgentLogger(ABC):
def __init__(
self,
log_file_name: str = "agent.log",
) -> None:
self.log_file_name = log_file_name

def __save_log__(self, log_str: str):
"""how to save the log"""
pass

def receive_task(self, task: TaskPackage, agent_name: str):
"""the agent receives a task and log it"""
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

from agentlite.commons import AgentAct, TaskPackage
from agentlite.logging.utils import *
from agentlite.utils import bcolors

from .BaseLogger import BaseAgentLogger
from .base import BaseAgentLogger

class AgentLogger(BaseAgentLogger):
class UILogger(BaseAgentLogger):
def __init__(
self,
log_file_name: str = "agent.log",
Expand All @@ -21,13 +20,6 @@ def __init__(
self.FLAG_PRINT = FLAG_PRINT # whether print the log into terminal
self.OBS_OFFSET = OBS_OFFSET
self.PROMPT_DEBUG_FLAG = PROMPT_DEBUG_FLAG

def __check_log_file__(self):
if os.path.isdir(self.log_file_name):
return True
else:
print(f"{self.log_file_name} does not exist. Created one")
return False

def __save_log__(self, log_str: str):
with st.chat_message("assistant"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from agentlite.logging.utils import *
from agentlite.utils import bcolors

from .BaseLogger import BaseAgentLogger
from .base import BaseAgentLogger

class AgentLogger(BaseAgentLogger):
def __init__(
Expand Down Expand Up @@ -34,13 +34,6 @@ def __color_obs_str__(self, act_str: str):
def __color_prompt_str__(self, prompt: str):
return f"""{bcolors.WARNING}{prompt}{bcolors.ENDC}"""

def __check_log_file__(self):
if os.path.isdir(self.log_file_name):
return True
else:
print(f"{self.log_file_name} does not exist. Created one")
return False

def __save_log__(self, log_str: str):
if self.FLAG_PRINT:
print(log_str)
Expand Down
9 changes: 9 additions & 0 deletions agentlite/logging/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import re


Expand All @@ -14,3 +15,11 @@ def str_color_remove(color_str: str):
ansi_escape = re.compile(r"\x1B[@-_][0-?]*[ -/]*[@-~]")
clean_str = ansi_escape.sub("", color_str)
return clean_str


def check_log_file(log_file_name):
if os.path.isdir(log_file_name):
return True
else:
print(f"{log_file_name} does not exist. Created one")
return False
4 changes: 2 additions & 2 deletions app/pages/Philosophers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from agentlite.llm.LLMConfig import LLMConfig
from agentlite.actions.BaseAction import BaseAction

from agentlite.logging.streamlit_log import AgentLogger
from agentlite.logging.streamlit_logger import UILogger

import streamlit as st

Expand Down Expand Up @@ -40,7 +40,7 @@ def __init__(
llm_config = LLMConfig({"llm_name": llm_name, "temperature": 0.0})
llm = get_llm_backend(llm_config)

logger = AgentLogger()
logger = UILogger()


Confucius = Philosopher(philosopher="Confucius", llm=llm)
Expand Down
4 changes: 2 additions & 2 deletions app/pages/Weatherman.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from agentlite.commons import TaskPackage
from agentlite.llm.agent_llms import get_llm_backend, LLMConfig

from agentlite.logging.streamlit_log import AgentLogger
from agentlite.logging.streamlit_logger import UILogger

llm_name = "gpt-4"
llm_config = LLMConfig({"llm_name": llm_name, "temperature": 0.0})
Expand All @@ -30,7 +30,7 @@
get_weather_forcast(),
]

logger = AgentLogger()
logger = UILogger()

agent = BaseAgent(
name=agent_info["name"],
Expand Down
2 changes: 1 addition & 1 deletion benchmark/hotpotqa/evaluate_hotpot_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from agentlite.commons import AgentAct, TaskPackage
from agentlite.llm.agent_llms import BaseLLM, get_llm_backend
from agentlite.llm.LLMConfig import LLMConfig
from agentlite.logging.multi_agent_log import AgentLogger
from agentlite.logging.terminal_logger import AgentLogger



Expand Down
2 changes: 1 addition & 1 deletion benchmark/hotpotqa/hotpotagents.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from agentlite.commons import AgentAct, TaskPackage
from agentlite.llm.agent_llms import BaseLLM, get_llm_backend
from agentlite.llm.LLMConfig import LLMConfig
from agentlite.logging.multi_agent_log import AgentLogger
from agentlite.logging.terminal_logger import AgentLogger

class WikiSearchAgent(BaseAgent):
"""
Expand Down
2 changes: 1 addition & 1 deletion benchmark/tool/evaluate_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from agentlite.commons import AgentAct, TaskPackage
from agentlite.llm.agent_llms import BaseLLM, get_llm_backend
from agentlite.llm.LLMConfig import LLMConfig
from agentlite.logging.multi_agent_log import AgentLogger
from agentlite.logging.terminal_logger import AgentLogger

LAM_URL = os.environ["LAM_URL"]

Expand Down
2 changes: 1 addition & 1 deletion benchmark/tool/tool_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from agentlite.agents import ABCAgent, BaseAgent
from agentlite.commons import AgentAct, TaskPackage
from agentlite.llm.agent_llms import BaseLLM
from agentlite.logging.multi_agent_log import AgentLogger
from agentlite.logging.terminal_logger import AgentLogger

class WeatherAgent(BaseAgent):
def __init__(self, env, llm: BaseLLM, agent_arch: str = "react", PROMPT_DEBUG_FLAG=False):
Expand Down
2 changes: 1 addition & 1 deletion benchmark/webshop/evaluate_webshop.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from agentlite.commons import AgentAct, TaskPackage
from agentlite.llm.agent_llms import BaseLLM, get_llm_backend
from agentlite.llm.LLMConfig import LLMConfig
from agentlite.logging.multi_agent_log import AgentLogger
from agentlite.logging.terminal_logger import AgentLogger

LAM_URL = os.environ["LAM_URL"]
webshop_env = Webshop()
Expand Down
2 changes: 1 addition & 1 deletion benchmark/webshop/webshop_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from agentlite.commons import AgentAct, TaskPackage
from agentlite.llm.agent_llms import BaseLLM, get_llm_backend
from agentlite.llm.LLMConfig import LLMConfig
from agentlite.logging.multi_agent_log import AgentLogger
from agentlite.logging.terminal_logger import AgentLogger

class WebshopAgent(BaseAgent):
"""
Expand Down
2 changes: 1 addition & 1 deletion benchmark/webshop/webshop_multiagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from agentlite.commons import AgentAct, TaskPackage
from agentlite.llm.agent_llms import BaseLLM, get_llm_backend
from agentlite.llm.LLMConfig import LLMConfig
from agentlite.logging.multi_agent_log import AgentLogger
from agentlite.logging.terminal_logger import AgentLogger

class SearchAgent(BaseAgent):
"""
Expand Down
2 changes: 1 addition & 1 deletion example/SearchAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from agentlite.commons import AgentAct, TaskPackage
from agentlite.llm.agent_llms import BaseLLM, get_llm_backend
from agentlite.llm.LLMConfig import LLMConfig
from agentlite.logging.multi_agent_log import AgentLogger
from agentlite.logging.terminal_logger import AgentLogger

# set PROMPT_DEBUG_FLAG to True to see the debug info
agent_logger = AgentLogger(PROMPT_DEBUG_FLAG=False)
Expand Down
2 changes: 1 addition & 1 deletion example/SearchManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from agentlite.commons import ActObsChainType, AgentAct, TaskPackage
from agentlite.llm.agent_llms import BaseLLM, get_llm_backend
from agentlite.llm.LLMConfig import LLMConfig
from agentlite.logging.multi_agent_log import AgentLogger
from agentlite.logging.terminal_logger import AgentLogger

# set PROMPT_DEBUG_FLAG to True to see the debug info
agent_logger = AgentLogger(PROMPT_DEBUG_FLAG=False)
Expand Down
2 changes: 1 addition & 1 deletion example/philosopher_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from agentlite.agents import ABCAgent, BaseAgent
from agentlite.llm.agent_llms import BaseLLM, get_llm_backend
from agentlite.llm.LLMConfig import LLMConfig
from agentlite.logging.multi_agent_log import AgentLogger
from agentlite.logging.terminal_logger import AgentLogger
from agentlite.actions.BaseAction import BaseAction

# Define the Philosopher class
Expand Down
2 changes: 1 addition & 1 deletion example/run_hotpot_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from agentlite.commons import AgentAct, TaskPackage
from agentlite.llm.agent_llms import BaseLLM, get_llm_backend
from agentlite.llm.LLMConfig import LLMConfig
from agentlite.logging.multi_agent_log import AgentLogger
from agentlite.logging.terminal_logger import AgentLogger


def download_file(url, filename):
Expand Down
Binary file added image/weather_agent.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2e22803

Please sign in to comment.