Skip to content

Commit

Permalink
Merge branch 'main' of github.com:l3vels/L3AGI
Browse files Browse the repository at this point in the history
  • Loading branch information
Chkhikvadze committed Nov 29, 2023
2 parents ca516c6 + 1901227 commit 74a7b8f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import List, Optional

from langchain.agents import AgentType, initialize_agent
from langchain.chat_models import ChatOpenAI
Expand All @@ -9,6 +9,7 @@
from agents.conversational.output_parser import ConvoOutputParser
from config import Config
from memory.zep.zep_memory import ZepMemory
from services.run_log import RunLogsManager
from typings.agent import AgentWithConfigsOutput


Expand All @@ -23,13 +24,15 @@ def __init__(
session_id: str,
sender_name: str,
is_memory: bool = False,
run_logs_manager: Optional[RunLogsManager] = None,
**tool_kwargs,
) -> None:
super().__init__(name, agent_with_configs, system_message, model)
self.tools = tools
self.session_id = session_id
self.sender_name = sender_name
self.is_memory = is_memory
self.run_logs_manager = run_logs_manager

def send(self) -> str:
"""
Expand All @@ -56,13 +59,20 @@ def send(self) -> str:
memory_key="chat_history", return_messages=True
)

callbacks = []

if self.run_logs_manager:
self.model.callbacks = [self.run_logs_manager.get_agent_callback_handler()]
callbacks.append(self.run_logs_manager.get_agent_callback_handler())

agent = initialize_agent(
self.tools,
self.model,
agent=AgentType.CHAT_CONVERSATIONAL_REACT_DESCRIPTION,
verbose=True,
handle_parsing_errors=True,
memory=memory,
callbacks=callbacks,
agent_kwargs={
"system_message": self.system_message.content,
"output_parser": ConvoOutputParser(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from agents.agent_simulations.agent.dialogue_agent_with_tools import \
DialogueAgentWithTools
from services.run_log import RunLogsManager
from typings.agent import AgentWithConfigsOutput


Expand All @@ -24,6 +25,7 @@ def __init__(
tools: List[any],
session_id: str,
sender_name: str,
run_logs_manager: RunLogsManager,
is_memory: bool = False,
) -> None:
super().__init__(
Expand All @@ -35,6 +37,7 @@ def __init__(
session_id,
sender_name,
is_memory,
run_logs_manager,
)
self.bidding_template = bidding_template

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from models.team import TeamModel
from postgres import PostgresChatMessageHistory
from services.pubsub import ChatPubSubService
from services.run_log import RunLogsManager
from tools.datasources.get_datasource_tools import get_datasource_tools
from tools.get_tools import get_agent_tools
from typings.agent import AgentWithConfigsOutput
Expand All @@ -48,6 +49,7 @@ def __init__(
provider_account,
stopping_probability: int,
word_limit: Optional[int] = 50,
run_logs_manager: Optional[RunLogsManager] = None,
) -> None:
super().__init__(
sender_name=sender_name,
Expand All @@ -58,6 +60,7 @@ def __init__(
self.stopping_probability = stopping_probability
self.settings = settings
self.chat_pubsub_service = chat_pubsub_service
self.run_logs_manager = run_logs_manager

@tenacity.retry(
stop=tenacity.stop_after_attempt(2),
Expand Down Expand Up @@ -102,21 +105,27 @@ def select_next_speaker(
def get_tools(
self, agent_with_configs: AgentWithConfigsOutput, settings: AccountSettings
):
tool_callback_handler = self.run_logs_manager.get_tool_callback_handler()

datasources = (
db.session.query(DatasourceModel)
.filter(DatasourceModel.id.in_(agent_with_configs.configs.datasources))
.all()
)
datasource_tools = get_datasource_tools(
datasources, settings, self.provider_account, agent_with_configs, None
datasources,
settings,
self.provider_account,
agent_with_configs,
tool_callback_handler,
)
agent_tools = get_agent_tools(
agent_with_configs.configs.tools,
db,
self.provider_account,
settings,
agent_with_configs,
None,
tool_callback_handler,
)
return datasource_tools + agent_tools

Expand Down Expand Up @@ -253,6 +262,7 @@ def run(
tools=self.get_tools(agent_with_configs, self.settings),
sender_name=self.sender_name,
is_memory=team.is_memory,
run_logs_manager=self.run_logs_manager,
)
)

Expand Down
5 changes: 5 additions & 0 deletions apps/server/services/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def process_chat_message(
team_configs=team_configs,
provider_account=provider_account,
provider_user=provider_user,
run_logs_manager=run_logs_manager,
)


Expand Down Expand Up @@ -311,6 +312,7 @@ def handle_team_types(
team_configs,
provider_account,
provider_user,
run_logs_manager: RunLogsManager,
):
team_status_config: Optional[ConfigModel] = None
if team.team_type == TeamOfAgentsType.PLAN_AND_EXECUTE.value:
Expand Down Expand Up @@ -386,6 +388,7 @@ def handle_team_types(
history=history,
team_configs=team_configs,
provider_account=provider_account,
run_logs_manager=run_logs_manager,
)

team_status_config.value = ChatStatus.IDLE.value
Expand Down Expand Up @@ -464,6 +467,7 @@ def handle_decentralized_speaker(
history: ZepMemory,
team_configs: Dict[str, Union[str, int, float]],
provider_account: AccountModel,
run_logs_manager: RunLogsManager,
):
topic = prompt
agents = [
Expand All @@ -482,6 +486,7 @@ def handle_decentralized_speaker(
stopping_probability=float(stopping_probability),
word_limit=int(word_limit),
provider_account=provider_account,
run_logs_manager=run_logs_manager,
)

decentralized_speaker.run(
Expand Down
2 changes: 1 addition & 1 deletion apps/server/tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class BaseTool(LangchainBaseTool):
tool_id: str
configs: Dict[str, str] = {}
settings: Optional[AccountSettings] = None
slug: str
slug: Optional[str] = None
toolkit_slug: Optional[str] = None
account: Optional[AccountOutput] = None
agent_with_configs: Optional[AgentWithConfigsOutput] = None
Expand Down

0 comments on commit 74a7b8f

Please sign in to comment.