mirror of
https://github.com/langgenius/dify.git
synced 2026-09-08 02:43:49 +08:00
fix(agent): avoid empty Bedrock schema fields (#40443)
Co-authored-by: Crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
5018f8aa8a
commit
9385e583ff
@ -343,7 +343,8 @@ def _map_model_request_to_prompt_messages(message: ModelRequest) -> list[PromptM
|
||||
|
||||
for part in message.parts:
|
||||
if isinstance(part, SystemPromptPart):
|
||||
prompt_messages.append(SystemPromptMessage(content=part.content))
|
||||
if part.content.strip():
|
||||
prompt_messages.append(SystemPromptMessage(content=part.content))
|
||||
elif isinstance(part, UserPromptPart):
|
||||
prompt_messages.append(UserPromptMessage(content=_map_user_prompt_content(part.content)))
|
||||
elif isinstance(part, ToolReturnPart):
|
||||
|
||||
@ -301,6 +301,8 @@ class DifyShellLayer(PydanticAILayer[DifyShellLayerDeps, object, DifyShellLayerC
|
||||
self._clear_tracked_jobs()
|
||||
|
||||
async def _tool_run(self, script: str, timeout: float = DEFAULT_TIMEOUT_SECONDS) -> ShellRunToolResult:
|
||||
"""Start a shell job in the current workspace and return its output and status."""
|
||||
|
||||
try:
|
||||
env = self._build_shell_command_env(include_agent_stub_env=True)
|
||||
agent_stub_token = env.get(AGENT_STUB_AUTH_JWE_ENV_VAR)
|
||||
@ -337,6 +339,8 @@ class DifyShellLayer(PydanticAILayer[DifyShellLayerDeps, object, DifyShellLayerC
|
||||
return _tool_unexpected_error("shell_run", exc)
|
||||
|
||||
async def _tool_wait(self, job_id: str, timeout: float = DEFAULT_TIMEOUT_SECONDS) -> ShellRunToolResult:
|
||||
"""Wait for more output or completion from an existing shell job."""
|
||||
|
||||
try:
|
||||
offset = self._tracked_offset(job_id)
|
||||
result = await self._require_resource().commands.wait(job_id, offset=offset, timeout=timeout)
|
||||
@ -369,6 +373,8 @@ class DifyShellLayer(PydanticAILayer[DifyShellLayerDeps, object, DifyShellLayerC
|
||||
return _tool_unexpected_error("shell_wait", exc, job_id=job_id)
|
||||
|
||||
async def _tool_input(self, job_id: str, text: str, timeout: float = DEFAULT_TIMEOUT_SECONDS) -> ShellRunToolResult:
|
||||
"""Send text to a running shell job and wait for its next output."""
|
||||
|
||||
try:
|
||||
offset = self._tracked_offset(job_id)
|
||||
result = await self._require_resource().commands.input(job_id, text, offset=offset, timeout=timeout)
|
||||
@ -405,6 +411,8 @@ class DifyShellLayer(PydanticAILayer[DifyShellLayerDeps, object, DifyShellLayerC
|
||||
job_id: str,
|
||||
grace_seconds: float = DEFAULT_TERMINATE_GRACE_SECONDS,
|
||||
) -> ShellInterruptToolResult:
|
||||
"""Interrupt a running shell job and return its final status."""
|
||||
|
||||
try:
|
||||
self._ensure_tracked_job(job_id)
|
||||
result = await self._require_resource().commands.interrupt(job_id, grace_seconds=grace_seconds)
|
||||
|
||||
@ -101,6 +101,7 @@ class DifyLLMAdapterModelTests(unittest.IsolatedAsyncioTestCase):
|
||||
messages = [
|
||||
ModelRequest(
|
||||
parts=[
|
||||
SystemPromptPart(" "),
|
||||
SystemPromptPart("request system"),
|
||||
UserPromptPart("hello"),
|
||||
ToolReturnPart(
|
||||
|
||||
@ -303,6 +303,15 @@ def test_shell_type_id_constant_matches_implementation_class() -> None:
|
||||
assert DIFY_SHELL_LAYER_TYPE_ID == DifyShellLayer.type_id
|
||||
|
||||
|
||||
def test_shell_layer_tools_have_non_empty_descriptions() -> None:
|
||||
layer = DifyShellLayer.from_config_with_settings(DifyShellLayerConfig())
|
||||
|
||||
descriptions = {tool.name: tool.description for tool in layer.tools}
|
||||
|
||||
assert set(descriptions) == {"shell_run", "shell_wait", "shell_input", "shell_interrupt"}
|
||||
assert all(description and description.strip() for description in descriptions.values())
|
||||
|
||||
|
||||
def test_shell_prefix_prompt_describes_workspace_as_temp_space() -> None:
|
||||
prompt = shell_layer_module._SHELL_LAYER_PREFIX_PROMPT
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user