feat(agent): 增强 Agent 配置,新增结构化字段与聊天功能支持
This commit is contained in:
1 parent
ac4262cd75
commit
c8ce77199e
183 files changed
+11690
-2300
No files matched your search
@@ -992,33 +992,34 @@ def test_file_check_openapi_injects_tool_api_base(app, client):
|
||||
|
||||
|
||||
def test_file_check_dify_chat_inputs(app):
|
||||
from app.services.agent_registry.resolver import is_file_check_runtime_ready
|
||||
from app.services.file_check_tools.dify_inputs import (
|
||||
FILE_CHECK_TASK_ID_INPUT,
|
||||
build_file_check_dify_inputs,
|
||||
)
|
||||
from app.services.file_check_tools.agent_resolver import is_file_check_chat_agent
|
||||
|
||||
class _Agent:
|
||||
def __init__(self, name: str, *, extra_config=None):
|
||||
def __init__(self, name: str, *, agent_code='file_check', capabilities=None, bound_schedule_task_id=None):
|
||||
self.name = name
|
||||
self.extra_config = extra_config or {}
|
||||
self.agent_code = agent_code
|
||||
self.capabilities = capabilities or {'task_progress': True}
|
||||
self.bound_schedule_task_id = bound_schedule_task_id
|
||||
self.extra_config = {}
|
||||
|
||||
assert is_file_check_chat_agent(_Agent(
|
||||
assert is_file_check_runtime_ready(_Agent(
|
||||
'RoHS文件检核助手',
|
||||
extra_config={
|
||||
'capabilities': ['tool_run_progress'],
|
||||
'tool_run_progress': {'schedule_task_id': 12},
|
||||
},
|
||||
bound_schedule_task_id=12,
|
||||
))
|
||||
assert not is_file_check_runtime_ready(_Agent('RoHS文件检核助手'))
|
||||
assert not is_file_check_runtime_ready(_Agent(
|
||||
'货代发货通知 Agent',
|
||||
agent_code='shipping_notice',
|
||||
capabilities={},
|
||||
))
|
||||
assert not is_file_check_chat_agent(_Agent('RoHS文件检核助手'))
|
||||
assert not is_file_check_chat_agent(_Agent('货代发货通知 Agent'))
|
||||
|
||||
agent = _Agent(
|
||||
'RoHS文件检核助手',
|
||||
extra_config={
|
||||
'capabilities': ['tool_run_progress'],
|
||||
'tool_run_progress': {'schedule_task_id': 12},
|
||||
},
|
||||
bound_schedule_task_id=12,
|
||||
)
|
||||
with app.app_context():
|
||||
inputs = build_file_check_dify_inputs(agent)
|
||||
@@ -1052,9 +1053,9 @@ def test_file_check_dify_inputs_raises_when_capability_without_schedule_task_id(
|
||||
import pytest
|
||||
|
||||
from app.core.errors import ValidationError
|
||||
from app.services.file_check_tools.agent_resolver import (
|
||||
agent_declares_file_check_progress,
|
||||
is_file_check_chat_agent,
|
||||
from app.services.agent_registry.resolver import (
|
||||
agent_declares_task_progress,
|
||||
is_file_check_runtime_ready,
|
||||
)
|
||||
from app.services.file_check_tools.dify_inputs import (
|
||||
FILE_CHECK_TASK_ID_MISSING_CODE,
|
||||
@@ -1065,14 +1066,14 @@ def test_file_check_dify_inputs_raises_when_capability_without_schedule_task_id(
|
||||
def __init__(self):
|
||||
self.id = 26
|
||||
self.name = 'RoHS文件检核助手'
|
||||
self.extra_config = {
|
||||
'capabilities': ['tool_run_progress'],
|
||||
'tool_run_progress': {'type': 'file_check'},
|
||||
}
|
||||
self.agent_code = 'file_check'
|
||||
self.capabilities = {'task_progress': True}
|
||||
self.bound_schedule_task_id = None
|
||||
self.extra_config = {}
|
||||
|
||||
agent = _Agent()
|
||||
assert agent_declares_file_check_progress(agent)
|
||||
assert not is_file_check_chat_agent(agent)
|
||||
assert agent_declares_task_progress(agent)
|
||||
assert not is_file_check_runtime_ready(agent)
|
||||
with app.app_context():
|
||||
with pytest.raises(ValidationError) as exc:
|
||||
build_file_check_dify_inputs(agent, required=True)
|
||||
@@ -1092,6 +1093,8 @@ def test_chat_completions_rejects_missing_file_check_task_id(app, client, mocker
|
||||
dify_api_key='app-key',
|
||||
api_base_url='http://dify.example/v1',
|
||||
type='api',
|
||||
agent_code='file_check',
|
||||
capabilities={'task_progress': True},
|
||||
extra_config={
|
||||
'capabilities': ['tool_run_progress'],
|
||||
'tool_run_progress': {'type': 'file_check'},
|
||||
@@ -1123,11 +1126,11 @@ def test_chat_completions_rejects_missing_file_check_task_id(app, client, mocker
|
||||
mock_post.assert_not_called()
|
||||
|
||||
|
||||
def test_chat_agent_proxy_passes_extra_config_for_task_id_injection():
|
||||
"""chat.py agent_proxy 须携带 extra_config,否则 is_file_check_chat_agent / task_id 注入失效。"""
|
||||
def test_chat_agent_proxy_passes_registry_columns_for_task_id_injection():
|
||||
"""chat.py agent_proxy 须携带 Registry 列,否则 task_id 注入失效。"""
|
||||
from types import SimpleNamespace
|
||||
|
||||
from app.services.file_check_tools.agent_resolver import is_file_check_chat_agent
|
||||
from app.services.agent_registry.resolver import is_file_check_runtime_ready
|
||||
from app.services.file_check_tools.dify_inputs import (
|
||||
FILE_CHECK_TASK_ID_INPUT,
|
||||
build_file_check_dify_inputs,
|
||||
@@ -1136,23 +1139,26 @@ def test_chat_agent_proxy_passes_extra_config_for_task_id_injection():
|
||||
agent_proxy = SimpleNamespace(
|
||||
id=26,
|
||||
name='RoHS文件检核助手',
|
||||
agent_code='file_check',
|
||||
capabilities={'task_progress': True},
|
||||
bound_schedule_task_id=12,
|
||||
dify_api_key='app-key',
|
||||
api_base_url='http://dify.example/v1',
|
||||
extra_config={
|
||||
'capabilities': ['tool_run_progress'],
|
||||
'tool_run_progress': {'schedule_task_id': 12},
|
||||
},
|
||||
extra_config={},
|
||||
)
|
||||
assert is_file_check_chat_agent(agent_proxy)
|
||||
assert is_file_check_runtime_ready(agent_proxy)
|
||||
assert build_file_check_dify_inputs(agent_proxy)[FILE_CHECK_TASK_ID_INPUT] == '12'
|
||||
|
||||
bare_proxy = SimpleNamespace(
|
||||
id=26,
|
||||
name='RoHS文件检核助手',
|
||||
agent_code='generic',
|
||||
capabilities={},
|
||||
bound_schedule_task_id=None,
|
||||
dify_api_key='app-key',
|
||||
api_base_url='http://dify.example/v1',
|
||||
)
|
||||
assert not is_file_check_chat_agent(bare_proxy)
|
||||
assert not is_file_check_runtime_ready(bare_proxy)
|
||||
assert build_file_check_dify_inputs(bare_proxy) == {}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user