sync update from LAN repo (source dhk-1 @ 3b1ec5b4)
This commit is contained in:
1 parent
da6521b6cb
commit
264e2200d6
995 files changed
+148105
-13399
No files matched your search
@@ -35,13 +35,14 @@ from deerflow.agents.lead_agent.prompt import apply_prompt_template
|
||||
from deerflow.agents.thread_state import ThreadState
|
||||
from deerflow.config.agents_config import AGENT_NAME_PATTERN
|
||||
from deerflow.config.app_config import get_app_config, reload_app_config
|
||||
from deerflow.config.extensions_config import (
|
||||
ExtensionsConfig,
|
||||
McpServerConfig,
|
||||
patch_extensions_config,
|
||||
read_extensions_config_document,
|
||||
)
|
||||
from deerflow.config.extensions_config import (
|
||||
ExtensionsConfig,
|
||||
McpServerConfig,
|
||||
patch_extensions_config,
|
||||
read_extensions_config_document,
|
||||
)
|
||||
from deerflow.config.paths import get_paths
|
||||
from deerflow.config.system_settings import get_conversation_context_settings
|
||||
from deerflow.models import create_chat_model
|
||||
from deerflow.runtime.user_context import get_effective_user_id
|
||||
from deerflow.skills.storage import get_or_new_skill_storage
|
||||
@@ -200,6 +201,7 @@ class DeerFlowClient:
|
||||
def _ensure_agent(self, config: RunnableConfig):
|
||||
"""Create (or recreate) the agent when config-dependent params change."""
|
||||
cfg = config.get("configurable", {})
|
||||
recent_turn_window_enabled = get_conversation_context_settings().recent_turn_window_enabled
|
||||
key = (
|
||||
cfg.get("model_name"),
|
||||
cfg.get("thinking_enabled"),
|
||||
@@ -207,6 +209,7 @@ class DeerFlowClient:
|
||||
cfg.get("subagent_enabled"),
|
||||
self._agent_name,
|
||||
frozenset(self._available_skills) if self._available_skills is not None else None,
|
||||
recent_turn_window_enabled,
|
||||
)
|
||||
|
||||
if self._agent is not None and self._agent_config_key == key:
|
||||
@@ -254,35 +257,32 @@ class DeerFlowClient:
|
||||
return [{"name": tc["name"], "args": tc["args"], "id": tc.get("id")} for tc in tool_calls]
|
||||
|
||||
@staticmethod
|
||||
def _ai_text_event(
|
||||
msg_id: str | None,
|
||||
text: str,
|
||||
usage: dict | None,
|
||||
reasoning: str = "",
|
||||
) -> "StreamEvent":
|
||||
"""Build a ``messages-tuple`` AI text event, preserving reasoning deltas."""
|
||||
data: dict[str, Any] = {"type": "ai", "content": text, "id": msg_id}
|
||||
if usage:
|
||||
data["usage_metadata"] = usage
|
||||
# Thinking-enabled OpenAI-compatible providers commonly put their
|
||||
# streaming tokens in ``additional_kwargs.reasoning_content`` while
|
||||
# ``content`` remains empty. Keep it on the wire for consumers that
|
||||
# render a custom stream (such as the multi-agent roundtable).
|
||||
if reasoning:
|
||||
data["additional_kwargs"] = {"reasoning_content": reasoning}
|
||||
return StreamEvent(type="messages-tuple", data=data)
|
||||
|
||||
@staticmethod
|
||||
def _reasoning_text(msg: Any) -> str:
|
||||
"""Return a provider reasoning delta when it is available as text."""
|
||||
additional_kwargs = getattr(msg, "additional_kwargs", None) or {}
|
||||
if not isinstance(additional_kwargs, dict):
|
||||
return ""
|
||||
reasoning = (
|
||||
additional_kwargs.get("reasoning_content")
|
||||
or additional_kwargs.get("reasoning")
|
||||
)
|
||||
return reasoning if isinstance(reasoning, str) else ""
|
||||
def _ai_text_event(
|
||||
msg_id: str | None,
|
||||
text: str,
|
||||
usage: dict | None,
|
||||
reasoning: str = "",
|
||||
) -> "StreamEvent":
|
||||
"""Build a ``messages-tuple`` AI text event, preserving reasoning deltas."""
|
||||
data: dict[str, Any] = {"type": "ai", "content": text, "id": msg_id}
|
||||
if usage:
|
||||
data["usage_metadata"] = usage
|
||||
# Thinking-enabled OpenAI-compatible providers commonly put their
|
||||
# streaming tokens in ``additional_kwargs.reasoning_content`` while
|
||||
# ``content`` remains empty. Keep it on the wire for consumers that
|
||||
# render a custom stream (such as the multi-agent roundtable).
|
||||
if reasoning:
|
||||
data["additional_kwargs"] = {"reasoning_content": reasoning}
|
||||
return StreamEvent(type="messages-tuple", data=data)
|
||||
|
||||
@staticmethod
|
||||
def _reasoning_text(msg: Any) -> str:
|
||||
"""Return a provider reasoning delta when it is available as text."""
|
||||
additional_kwargs = getattr(msg, "additional_kwargs", None) or {}
|
||||
if not isinstance(additional_kwargs, dict):
|
||||
return ""
|
||||
reasoning = additional_kwargs.get("reasoning_content") or additional_kwargs.get("reasoning")
|
||||
return reasoning if isinstance(reasoning, str) else ""
|
||||
|
||||
@staticmethod
|
||||
def _ai_tool_calls_event(msg_id: str | None, tool_calls) -> "StreamEvent":
|
||||
@@ -722,10 +722,10 @@ class DeerFlowClient:
|
||||
if visible_tool_calls:
|
||||
yield self._ai_tool_calls_event(msg_id, visible_tool_calls)
|
||||
|
||||
text = self._extract_text(msg.content)
|
||||
reasoning = self._reasoning_text(msg)
|
||||
if text or reasoning:
|
||||
yield self._ai_text_event(msg_id, text, counted_usage, reasoning)
|
||||
text = self._extract_text(msg.content)
|
||||
reasoning = self._reasoning_text(msg)
|
||||
if text or reasoning:
|
||||
yield self._ai_text_event(msg_id, text, counted_usage, reasoning)
|
||||
|
||||
elif isinstance(msg, ToolMessage):
|
||||
yield self._tool_message_event(msg)
|
||||
@@ -800,7 +800,11 @@ class DeerFlowClient:
|
||||
"display_name": getattr(model, "display_name", None),
|
||||
"description": getattr(model, "description", None),
|
||||
"supports_thinking": getattr(model, "supports_thinking", False),
|
||||
"supports_reasoning_effort": getattr(model, "supports_reasoning_effort", False),
|
||||
# Gateway deployments resolve this administrator-managed
|
||||
# capability from their database. The embedded harness has
|
||||
# no application persistence layer, so legacy YAML must
|
||||
# never advertise it as enabled.
|
||||
"supports_reasoning_effort": False,
|
||||
}
|
||||
for model in self._app_config.models
|
||||
],
|
||||
@@ -866,7 +870,8 @@ class DeerFlowClient:
|
||||
"display_name": getattr(model, "display_name", None),
|
||||
"description": getattr(model, "description", None),
|
||||
"supports_thinking": getattr(model, "supports_thinking", False),
|
||||
"supports_reasoning_effort": getattr(model, "supports_reasoning_effort", False),
|
||||
# See list_models(): this flag is database-owned by the Gateway.
|
||||
"supports_reasoning_effort": False,
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
@@ -880,19 +885,14 @@ class DeerFlowClient:
|
||||
Dict with "mcp_servers" key mapping server name to config,
|
||||
matching the Gateway API ``McpConfigResponse`` schema.
|
||||
"""
|
||||
config_path = ExtensionsConfig.resolve_config_path()
|
||||
if config_path is None:
|
||||
return {"mcp_servers": {}}
|
||||
document = read_extensions_config_document(config_path)
|
||||
raw_servers = document.get("mcpServers", {})
|
||||
if not isinstance(raw_servers, dict):
|
||||
raise ValueError("Extensions config 'mcpServers' must be a JSON object")
|
||||
return {
|
||||
"mcp_servers": {
|
||||
name: McpServerConfig.model_validate(server).model_dump()
|
||||
for name, server in raw_servers.items()
|
||||
}
|
||||
}
|
||||
config_path = ExtensionsConfig.resolve_config_path()
|
||||
if config_path is None:
|
||||
return {"mcp_servers": {}}
|
||||
document = read_extensions_config_document(config_path)
|
||||
raw_servers = document.get("mcpServers", {})
|
||||
if not isinstance(raw_servers, dict):
|
||||
raise ValueError("Extensions config 'mcpServers' must be a JSON object")
|
||||
return {"mcp_servers": {name: McpServerConfig.model_validate(server).model_dump() for name, server in raw_servers.items()}}
|
||||
|
||||
def update_mcp_config(self, mcp_servers: dict[str, dict]) -> dict:
|
||||
"""Update MCP server configurations.
|
||||
@@ -914,19 +914,14 @@ class DeerFlowClient:
|
||||
if config_path is None:
|
||||
raise FileNotFoundError("Cannot locate extensions_config.json. Set DEER_FLOW_EXTENSIONS_CONFIG_PATH or ensure it exists in the project root.")
|
||||
|
||||
def _patch_mcp_servers(config_data: dict[str, Any]) -> None:
|
||||
config_data["mcpServers"] = mcp_servers
|
||||
def _patch_mcp_servers(config_data: dict[str, Any]) -> None:
|
||||
config_data["mcpServers"] = mcp_servers
|
||||
|
||||
patch_extensions_config(config_path, _patch_mcp_servers)
|
||||
patch_extensions_config(config_path, _patch_mcp_servers)
|
||||
|
||||
self._agent = None
|
||||
self._agent_config_key = None
|
||||
return {
|
||||
"mcp_servers": {
|
||||
name: McpServerConfig.model_validate(server).model_dump()
|
||||
for name, server in mcp_servers.items()
|
||||
}
|
||||
}
|
||||
return {"mcp_servers": {name: McpServerConfig.model_validate(server).model_dump() for name, server in mcp_servers.items()}}
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Public API — skills management
|
||||
@@ -979,21 +974,21 @@ class DeerFlowClient:
|
||||
if config_path is None:
|
||||
raise FileNotFoundError("Cannot locate extensions_config.json. Set DEER_FLOW_EXTENSIONS_CONFIG_PATH or ensure it exists in the project root.")
|
||||
|
||||
def _patch_skill_state(config_data: dict[str, Any]) -> None:
|
||||
skill_states = config_data.setdefault("skills", {})
|
||||
if not isinstance(skill_states, dict):
|
||||
raise ValueError("Extensions config 'skills' must be a JSON object")
|
||||
raw_skill_state = skill_states.get(name)
|
||||
if raw_skill_state is None:
|
||||
raw_skill_state = {}
|
||||
elif not isinstance(raw_skill_state, dict):
|
||||
raise ValueError(f"Extensions config state for skill '{name}' must be a JSON object")
|
||||
else:
|
||||
raw_skill_state = dict(raw_skill_state)
|
||||
raw_skill_state["enabled"] = enabled
|
||||
skill_states[name] = raw_skill_state
|
||||
|
||||
patch_extensions_config(config_path, _patch_skill_state)
|
||||
def _patch_skill_state(config_data: dict[str, Any]) -> None:
|
||||
skill_states = config_data.setdefault("skills", {})
|
||||
if not isinstance(skill_states, dict):
|
||||
raise ValueError("Extensions config 'skills' must be a JSON object")
|
||||
raw_skill_state = skill_states.get(name)
|
||||
if raw_skill_state is None:
|
||||
raw_skill_state = {}
|
||||
elif not isinstance(raw_skill_state, dict):
|
||||
raise ValueError(f"Extensions config state for skill '{name}' must be a JSON object")
|
||||
else:
|
||||
raw_skill_state = dict(raw_skill_state)
|
||||
raw_skill_state["enabled"] = enabled
|
||||
skill_states[name] = raw_skill_state
|
||||
|
||||
patch_extensions_config(config_path, _patch_skill_state)
|
||||
|
||||
self._agent = None
|
||||
self._agent_config_key = None
|
||||
|
||||
Reference in new issue
Block a user