Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev doe #178

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
54 changes: 54 additions & 0 deletions agentuniverse/agent/plan/planner/doe_planner/doe_planner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# !/usr/bin/env python3
# -*- coding:utf-8 -*-

# @Time : 2024/10/18 15:25
# @Author : weizjajj
# @Email : [email protected]
# @FileName: doe_planner.py
"""DOE planner module."""
from agentuniverse.agent.agent_manager import AgentManager
from agentuniverse.agent.agent_model import AgentModel
from agentuniverse.agent.input_object import InputObject
from agentuniverse.agent.plan.planner.planner import Planner
from agentuniverse.base.util.logging.logging_util import LOGGER


class DOEPlanner(Planner):
"""Executing planner class."""

def invoke(self, agent_model: AgentModel, planner_input: dict, input_object: InputObject) -> dict:
"""Invoke the planner.

Args:
agent_model (AgentModel): Agent model object.
planner_input (dict): Planner input object.
input_object (InputObject): The input parameters passed by the user.
Returns:
dict: The planner result.
"""

data_fining_agent = agent_model.plan.get('planner').get('data_fining_agent')
opinion_inject_agent = agent_model.plan.get('planner').get('opinion_inject_agent')
expressing_agent = agent_model.plan.get('planner').get('expressing_agent')

# 数据加工
LOGGER.info("Start data fining...")
data_fining_output = AgentManager().get_instance_obj(data_fining_agent).run(**planner_input)
LOGGER.info(f"Finished data fining, Data fining result: {data_fining_output.to_dict()}")
self.stream_output(input_object, data_fining_output.to_dict())
planner_input.update(data_fining_output.to_dict())

# 观点注入
LOGGER.info("Start opinion inject...")
opinion_inject_output = AgentManager().get_instance_obj(opinion_inject_agent).run(**planner_input)
LOGGER.info(f"Finished opinion inject, Opinion inject result: {opinion_inject_output.to_dict()}")
self.stream_output(input_object, opinion_inject_output.to_dict())
planner_input.update(opinion_inject_output.to_dict())

# 表达
LOGGER.info("Start expressing...")
expressing_agent_result = AgentManager().get_instance_obj(expressing_agent).run(**planner_input)
LOGGER.info(f"Finished expressing,Expressing result: {expressing_agent_result.to_dict()}")
self.stream_output(input_object, expressing_agent_result.to_dict())

return expressing_agent_result.to_dict()
6 changes: 6 additions & 0 deletions agentuniverse/agent/plan/planner/doe_planner/doe_planner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: 'doe_planner'
description: 'doe planner'
metadata:
type: 'PLANNER'
module: 'agentuniverse.agent.plan.planner.doe_planner.doe_planner'
class: 'DOEPlanner'
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

name: 'rag_planner'
description: 'rag planner'
metadata:
Expand Down
Empty file.
103 changes: 103 additions & 0 deletions agentuniverse/agent/plan/planner/serial_planner/serial_planner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# !/usr/bin/env python3
# -*- coding:utf-8 -*-

# @Time : 2024/10/18 15:25
# @Author : weizjajj
# @Email : [email protected]
# @FileName: serial_planner.py

from agentuniverse.agent.action.tool.tool import Tool
from agentuniverse.agent.action.tool.tool_manager import ToolManager
from agentuniverse.agent.agent import Agent
from agentuniverse.agent.agent_manager import AgentManager
from agentuniverse.agent.agent_model import AgentModel
from agentuniverse.agent.input_object import InputObject
from agentuniverse.agent.output_object import OutputObject
from agentuniverse.agent.plan.planner.planner import Planner
from agentuniverse.base.util.logging.logging_util import LOGGER


def execute_tool_or_agent(name: str, manager_class, planner_input: dict,
runtime_params: dict):
instance = manager_class.get_instance_obj(name)
input_params = dict()
input_params.update(runtime_params)

if isinstance(instance, Tool):
input_keys = instance.input_keys
elif isinstance(instance, Agent):
input_keys = instance.input_keys()
else:
raise ValueError(f"Unsupported instance type: {instance}")

for key in input_keys:
if key in input_params:
continue
if key not in planner_input:
raise Exception(f"{key} is not in planner input")
input_params[key] = planner_input.get(key)

try:
result = instance.run(**input_params)
if isinstance(result, dict):
planner_input.update(result)
elif isinstance(result, OutputObject):
planner_input.update(result.to_dict())
else:
planner_input[name] = result
return result
except Exception as e:
raise Exception(f"Error executing {name}: {e}")


class SerialPlanner(Planner):
"""Executing planner class."""

def invoke(self, agent_model: AgentModel, planner_input: dict, input_object: InputObject) -> dict:
"""Invoke the planner.

Args:
agent_model (AgentModel): Agent model object.
planner_input (dict): Planner input object.
input_object (InputObject): The input parameters passed by the user.
Returns:
dict: The planner result.
"""
output_stream = input_object.get_data('output_stream')
if output_stream:
planner_input.update({'output_stream': output_stream})
return self.run_all_actions(agent_model, planner_input, input_object)

def run_all_actions(self, agent_model: AgentModel, planner_input: dict, input_object: InputObject):
if not isinstance(planner_input, dict):
raise TypeError("planner_input must be a dictionary")

serials: dict = agent_model.plan.get('planner')
for key in serials:
if key == 'name':
continue
tool = serials.get(key)
tool_name = tool.get('name')
runtime_params = tool.get('runtime_params') or dict()
tool_type = tool.get('type') or 'tool'
if tool_type == 'tool':
LOGGER.info(f"start Executing tool: {tool_name}")
res = execute_tool_or_agent(tool_name, ToolManager(), planner_input, runtime_params)
self.stream_output(input_object, {
'data': res,
"type": "tool",
"agent_info": agent_model.info
})
LOGGER.info(f"finished execute tool {tool_name},execute result {res}")
elif tool_type == 'agent':
LOGGER.info(f"start Executing Agent: {tool_name}")
res = execute_tool_or_agent(tool_name, AgentManager(), planner_input, runtime_params)
self.stream_output(input_object, {
'data': res.to_dict(),
"type": "agent",
"agent_info": agent_model.info
})
LOGGER.info(f"finished execute agent {tool_name},execute result {res.to_dict()}")
else:
raise ValueError(f"Unsupported tool type: {tool_type}")
return planner_input
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: 'serial_planner'
description: 'serial planner'
metadata:
type: 'PLANNER'
module: 'agentuniverse.agent.plan.planner.serial_planner.serial_planner'
class: 'SerialPlanner'
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pymilvus = { version = "^2.4.3", optional = true}
googleapis-common-protos = "^1.63.0"
myst-parser = "^2.0.0"
qianfan = "^0.3.12"
dashscope = "^1.19.1"
dashscope = "1.19.1"
anthropic = "^0.26.0"
ollama = '^0.2.1'
langchain-anthropic = '^0.1.13'
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# !/usr/bin/env python3
# -*- coding:utf-8 -*-

# @Time : 2024/10/18 15:25
# @Author : weizjajj
# @Email : [email protected]
# @FileName: data_fining_agent.py


from agentuniverse.agent.agent import Agent
from agentuniverse.agent.input_object import InputObject


class DataFiningAgent(Agent):
def input_keys(self) -> list[str]:
return ['input']

def output_keys(self) -> list[str]:
return ['data_fining_result']

def parse_input(self, input_object: InputObject, agent_input: dict) -> dict:
for key in input_object.to_dict():
agent_input[key] = input_object.get_data(key)
return agent_input

def parse_result(self, planner_result: dict) -> dict:
return {
'data_fining_result': planner_result.get('data_processing_result')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
info:
name: 'data_fining_agent'
description: 'data fining agent'
profile:
llm_model:
name: 'deep_seek_llm'
temperature: 0.6
plan:
planner:
name: 'serial_planner'
data_loader:
name: 'load_fund_tool'
type: 'tool'
data_processing:
# name: 'data_processing_agent'
# type: 'agent'
name: 'fund_data_processing_agent'
type: 'agent'
metadata:
type: 'AGENT'
module: 'sample_standard_app.app.core.agent.doe_agent_case.data_fining_agent'
class: 'DataFiningAgent'
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# !/usr/bin/env python3
# -*- coding:utf-8 -*-

# @Time : 2024/10/18 15:25
# @Author : weizjajj
# @Email : [email protected]
# @FileName: data_processing_agent.py

from langchain_core.utils.json import parse_json_markdown

from agentuniverse.agent.agent import Agent
from agentuniverse.agent.input_object import InputObject


class DataProcessingAgent(Agent):
def input_keys(self) -> list[str]:
return ['input','init_data']

def output_keys(self) -> list[str]:
return ['data_processing_result']

def parse_input(self, input_object: InputObject, agent_input: dict) -> dict:
for key in input_object.to_dict():
agent_input[key] = input_object.get_data(key)
return agent_input

def parse_result(self, planner_result: dict) -> dict:
return {
'data_processing_result': parse_json_markdown(planner_result.get('output'))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
info:
name: 'data_processing_agent'
description: 'data processing agent'
profile:
prompt_version: data_processing_agent.cn
llm_model:
name: 'deep_seek_llm'
temperature: 0.6
plan:
planner:
name: 'rag_planner'
metadata:
type: 'AGENT'
module: 'sample_standard_app.app.core.agent.doe_agent_case.data_processing_agent'
class: 'DataProcessingAgent'
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# !/usr/bin/env python3
# -*- coding:utf-8 -*-

# @Time : 2024/10/18 15:25
# @Author : weizjajj
# @Email : [email protected]
# @FileName: doe_agent.py

from agentuniverse.agent.agent import Agent
from agentuniverse.agent.input_object import InputObject


class DOEAgent(Agent):
def input_keys(self) -> list[str]:
return ['input']

def output_keys(self) -> list[str]:
return []

def parse_input(self, input_object: InputObject, agent_input: dict) -> dict:
for key in input_object.to_dict():
agent_input[key] = input_object.get_data(key)
return agent_input

def parse_result(self, planner_result: dict) -> dict:
return planner_result
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
info:
name: 'doe_agent_case'
description: 'DOE agent case'
profile:
action:
plan:
planner:
name: 'doe_planner'
data_fining_agent: 'data_fining_agent'
opinion_inject_agent: 'opinion_inject_agent'
expressing_agent: 'doe_expressing_agent_case'
metadata:
type: 'AGENT'
module: 'sample_standard_app.app.core.agent.doe_agent_case.doe_agent_case'
class: 'DOEAgent'
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# !/usr/bin/env python3
# -*- coding:utf-8 -*-

# @Time : 2024/10/18 15:25
# @Author : weizjajj
# @Email : [email protected]
# @FileName: doe_expressing_agent.py

from agentuniverse.agent.agent import Agent
from agentuniverse.agent.input_object import InputObject


class DOEExpressingAgent(Agent):
def input_keys(self) -> list[str]:
return ['input','data_fining_result','matched_opinions']

def output_keys(self) -> list[str]:
return []

def parse_input(self, input_object: InputObject, agent_input: dict) -> dict:
for key in self.input_keys():
agent_input[key] = input_object.get_data(key)
return agent_input

def parse_result(self, planner_result: dict) -> dict:
return planner_result
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
info:
name: 'doe_expressing_agent_case'
description: 'DOE expressing agent case'
profile:
prompt_version: doe_expressing_agent_case.cn
llm_model:
name: 'deep_seek_llm'
temperature: 0.6
action:
plan:
planner:
name: 'rag_planner'
metadata:
type: 'AGENT'
module: 'sample_standard_app.app.core.agent.doe_agent_case.doe_expressing_agent_case'
class: 'DOEExpressingAgent'
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
info:
name: 'fund_data_processing_agent'
description: 'fund data processing agent'
profile:
prompt_version: fund_data_fining_agent.cn
llm_model:
name: 'deep_seek_llm'
temperature: 0.6
plan:
planner:
name: 'rag_planner'
metadata:
type: 'AGENT'
module: 'sample_standard_app.app.core.agent.doe_agent_case.data_processing_agent'
class: 'DataProcessingAgent'
Loading