Skip to content

Commit

Permalink
Merge branch 'fix/chore-fix' into dev/plugin-deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeuoly committed Dec 9, 2024
2 parents 054b59c + 93786f5 commit 6868ee5
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 8 deletions.
1 change: 1 addition & 0 deletions api/controllers/console/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
# Import workspace controllers
from .workspace import (
account,
agent_providers,
endpoint,
load_balancing_config,
members,
Expand Down
36 changes: 36 additions & 0 deletions api/controllers/console/workspace/agent_providers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from flask_login import current_user
from flask_restful import Resource

from controllers.console import api
from controllers.console.wraps import account_initialization_required, setup_required
from core.model_runtime.utils.encoders import jsonable_encoder
from libs.login import login_required
from services.agent_service import AgentService


class AgentProviderListApi(Resource):
@setup_required
@login_required
@account_initialization_required
def get(self):
user = current_user

user_id = user.id
tenant_id = user.current_tenant_id

return jsonable_encoder(AgentService.list_agent_providers(user_id, tenant_id))


class AgentProviderApi(Resource):
@setup_required
@login_required
@account_initialization_required
def get(self, provider_name: str):
user = current_user
user_id = user.id
tenant_id = user.current_tenant_id
return jsonable_encoder(AgentService.get_agent_provider(user_id, tenant_id, provider_name))


api.add_resource(AgentProviderListApi, "/workspaces/current/agent-providers")
api.add_resource(AgentProviderApi, "/workspaces/current/agent-provider/<path:provider_name>")
7 changes: 5 additions & 2 deletions api/core/plugin/manager/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ def fetch_agent_providers(self, tenant_id: str) -> list[PluginAgentProviderEntit
def transformer(json_response: dict[str, Any]) -> dict:
for provider in json_response.get("data", []):
declaration = provider.get("declaration", {}) or {}
declaration["identity"]["name"] = (
f"{provider.get('plugin_id')}/{declaration.get('identity', {}).get('name')}"
)
provider_name = declaration.get("identity", {}).get("name")
for tool in declaration.get("tools", []):
tool["identity"]["provider"] = provider_name
for strategy in declaration.get("strategies", []):
strategy["identity"]["provider"] = provider_name

return json_response

Expand Down
4 changes: 2 additions & 2 deletions api/core/workflow/nodes/agent/agent_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ def _generate_parameters(
Generate parameters based on the given tool parameters, variable pool, and node data.
Args:
tool_parameters (Sequence[ToolParameter]): The list of tool parameters.
agent_parameters (Sequence[AgentParameter]): The list of agent parameters.
variable_pool (VariablePool): The variable pool containing the variables.
node_data (ToolNodeData): The data associated with the tool node.
node_data (AgentNodeData): The data associated with the agent node.
Returns:
Mapping[str, Any]: A dictionary containing the generated parameters.
Expand Down
32 changes: 28 additions & 4 deletions api/services/agent_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import contexts
from core.app.app_config.easy_ui_based_app.agent.manager import AgentConfigManager
from core.plugin.manager.agent import PluginAgentManager
from core.tools.tool_manager import ToolManager
from extensions.ext_database import db
from models.account import Account
Expand Down Expand Up @@ -63,22 +64,29 @@ def get_agent_logs(cls, app_model: App, conversation_id: str, message_id: str) -

timezone = pytz.timezone(current_user.timezone)

app_model_config = app_model.app_model_config
if not app_model_config:
raise ValueError("App model config not found")

result = {
"meta": {
"status": "success",
"executor": executor,
"start_time": message.created_at.astimezone(timezone).isoformat(),
"elapsed_time": message.provider_response_latency,
"total_tokens": message.answer_tokens + message.message_tokens,
"agent_mode": app_model.app_model_config.agent_mode_dict.get("strategy", "react"),
"agent_mode": app_model_config.agent_mode_dict.get("strategy", "react"),
"iterations": len(agent_thoughts),
},
"iterations": [],
"files": message.message_files,
}

agent_config = AgentConfigManager.convert(app_model.app_model_config.to_dict())
agent_tools = agent_config.tools
agent_config = AgentConfigManager.convert(app_model_config.to_dict())
if not agent_config:
raise ValueError("Agent config not found")

agent_tools = agent_config.tools or []

def find_agent_tool(tool_name: str):
for agent_tool in agent_tools:
Expand All @@ -90,7 +98,7 @@ def find_agent_tool(tool_name: str):
tool_labels = agent_thought.tool_labels
tool_meta = agent_thought.tool_meta
tool_inputs = agent_thought.tool_inputs_dict
tool_outputs = agent_thought.tool_outputs_dict
tool_outputs = agent_thought.tool_outputs_dict or {}
tool_calls = []
for tool in tools:
tool_name = tool
Expand Down Expand Up @@ -145,3 +153,19 @@ def find_agent_tool(tool_name: str):
)

return result

@classmethod
def list_agent_providers(cls, user_id: str, tenant_id: str):
"""
List agent providers
"""
manager = PluginAgentManager()
return manager.fetch_agent_providers(tenant_id)

@classmethod
def get_agent_provider(cls, user_id: str, tenant_id: str, provider_name: str):
"""
Get agent provider
"""
manager = PluginAgentManager()
return manager.fetch_agent_provider(tenant_id, provider_name)

0 comments on commit 6868ee5

Please sign in to comment.