Skip to content

Commit

Permalink
feat(agent):Agent App
Browse files Browse the repository at this point in the history
1.Fix the display problem under dashboboard
2.Support Awel Agent to arrange fixed targets
  • Loading branch information
yhjun1026 committed Feb 19, 2024
1 parent 5e81302 commit a50fd1d
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 20 deletions.
8 changes: 5 additions & 3 deletions dbgpt/agent/actions/dashboard_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ async def a_run(
sql_df = await resource_db_client.a_query_to_df(
resource.value, chart_item.sql
)
chart_item["data"] = sql_df
chart_dict = chart_item.dict()

chart_dict["data"] = sql_df
except Exception as e:
logger.warn(f"Sql excute Failed!{str(e)}")
chart_item["err_msg"] = str(e)
chart_params.append(chart_item)
chart_dict["err_msg"] = str(e)
chart_params.append(chart_dict)
view = await self.render_protocal.disply(charts=chart_params)
return ActionOutput(
is_exe_success=True,
Expand Down
2 changes: 2 additions & 0 deletions dbgpt/agent/agents/agents_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .expand.code_assistant_agent import CodeAssistantAgent
from .expand.dashboard_assistant_agent import DashboardAssistantAgent
from .expand.data_scientist_agent import DataScientistAgent
from .expand.Indicator_assistant_agent import IndicatorAssistantAgent
from .expand.plugin_assistant_agent import PluginAssistantAgent
from .expand.summary_assistant_agent import SummaryAssistantAgent

Expand Down Expand Up @@ -98,3 +99,4 @@ def list_agents(self):
agent_manage.register_agent(DataScientistAgent)
agent_manage.register_agent(SummaryAssistantAgent)
agent_manage.register_agent(PluginAssistantAgent)
agent_manage.register_agent(IndicatorAssistantAgent)
6 changes: 4 additions & 2 deletions dbgpt/agent/agents/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ class Role(ABC, BaseModel):

expand_prompt: str = ""

fixed_subgoal: Optional[str] = None

constraints: List[str] = []
examples: str = ""
desc: str = ""
language: str = "en"
is_human: bool = False
is_team: bool = False

def __init__(self, **kwargs):
super().__init__(**kwargs)
class Config:
arbitrary_types_allowed = True

def prompt_template(
self,
Expand Down
32 changes: 22 additions & 10 deletions dbgpt/serve/agent/team/layout/agent_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,30 @@ async def map(
self,
input_value: AgentGenerateContext,
) -> AgentGenerateContext:
now_rely_messages: List[Dict] = []

now_message = input_value.message
agent = await self.get_agent(input_value)
if agent.fixed_subgoal and len(agent.fixed_subgoal) > 0:
# Isolate the message delivery mechanism and pass it to the operator
input_value.message["current_gogal"] = (
f"[{agent.name if agent.name else agent.profile}]:"
+ agent.fixed_subgoal
)
now_message["content"] = agent.fixed_subgoal
else:
# Isolate the message delivery mechanism and pass it to the operator
input_value.message["current_gogal"] = (
f"[{agent.name if agent.name else agent.profile}]:"
+ input_value.message["content"]
)

# Isolate the message delivery mechanism and pass it to the operator
input_value.message["current_gogal"] = (
f"[{agent.name if agent.name else agent.profile}]:"
+ input_value.message["content"]
)
now_rely_messages: List[Dict] = []
###What was received was the User message
human_message = input_value.message.copy()
human_message["role"] = ModelMessageRoleType.HUMAN
now_rely_messages.append(human_message)

###Send a message (no reply required) and pass the message content
now_message = input_value.message

if input_value.rely_messages and len(input_value.rely_messages) > 0:
now_message = input_value.rely_messages[-1]
await input_value.sender.a_send(now_message, agent, input_value.reviewer, False)
Expand Down Expand Up @@ -200,9 +208,13 @@ async def get_agent(
llm_config = LLMConfig(llm_client=input_value.llm_client)
else:
llm_config = LLMConfig(llm_client=self.llm_client)

kwargs = {}
if self.awel_agent.role_name:
kwargs["name"] = self.awel_agent.role_name
if self.awel_agent.fixed_subgoal:
kwargs["fixed_subgoal"] = self.awel_agent.fixed_subgoal
agent = (
await agent_cls(name=self.awel_agent.role_name)
await agent_cls(**kwargs)
.bind(input_value.memory)
.bind(llm_config)
.bind(input_value.agent_context)
Expand Down
9 changes: 9 additions & 0 deletions dbgpt/serve/agent/team/layout/agent_operator_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ def pre_fill(cls, values: Dict[str, Any]) -> Dict[str, Any]:
default=None,
description="The agent role name.",
),
Parameter.build_from(
label="Fixed Gogal",
name="fixed_subgoal",
type=str,
optional=True,
default=None,
description="The agent fixed gogal.",
),
Parameter.build_from(
label="Agent Resource",
name="agent_resource",
Expand All @@ -162,6 +170,7 @@ class AwelAgent(BaseModel):
role_name: Optional[str] = None
llm_config: Optional[LLMConfig] = None
resources: List[AgentResource] = Field(default_factory=list)
fixed_subgoal: Optional[str] = None

class Config:
arbitrary_types_allowed = True
Expand Down
8 changes: 6 additions & 2 deletions dbgpt/serve/agent/team/plan/team_auto_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ async def a_act(
reviewer: Optional[ConversableAgent] = None,
) -> Optional[ActionOutput]:
speaker = sender
final_message = message
for i in range(self.max_round):
plans = self.memory.plans_memory.get_by_conv_id(self.agent_context.conv_id)

Expand Down Expand Up @@ -153,7 +154,7 @@ async def a_act(
# complete
return ActionOutput(
is_exe_success=True,
content=f"{plans[-1].result}", # work results message
content=final_message, # work results message
)
else:
try:
Expand Down Expand Up @@ -201,19 +202,21 @@ async def a_act(
)

plan_result = ""
final_message = reply_message["content"]
if is_success:
if reply_message:
action_report = reply_message.get("action_report", None)
if action_report:
plan_result = action_report.get("content", "")
final_message = action_report["view"]

### The current planned Agent generation verification is successful
##Plan executed successfully
self.memory.plans_memory.complete_task(
self.agent_context.conv_id,
now_plan.sub_task_num,
plan_result,
)

else:
plan_result = reply_message["content"]
self.memory.plans_memory.update_task(
Expand All @@ -228,6 +231,7 @@ async def a_act(
return ActionOutput(
is_exe_success=False, content=plan_result
)

except Exception as e:
logger.exception(
f"An exception was encountered during the execution of the current plan step.{str(e)}"
Expand Down
9 changes: 6 additions & 3 deletions dbgpt/vis/tags/vis_dashboard.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import json
import logging
from typing import Optional

from ..base import Vis

logger = logging.getLogger(__name__)


class VisDashboard(Vis):
async def generate_content(self, **kwargs) -> Optional[str]:
async def generate_param(self, **kwargs) -> Optional[str]:
charts = kwargs.get("charts", None)
title = kwargs.get("title", None)
if not charts:
Expand All @@ -24,14 +27,14 @@ async def generate_content(self, **kwargs) -> Optional[str]:
try:
df = chart.get("data", None)
err_msg = chart.get("err_msg", None)
if not df:
if df is None:
param["err_msg"] = err_msg
else:
param["data"] = json.loads(
df.to_json(orient="records", date_format="iso", date_unit="s")
)

except Exception as e:
logger.exception("dashboard chart build faild!")
param["data"] = []
param["err_msg"] = str(e)
chart_items.append(param)
Expand Down

0 comments on commit a50fd1d

Please sign in to comment.