增加智能体

This commit is contained in:
许海洋 committed 2026-05-20 17:38:04 +08:00
1 parent 39def1c20b
commit 37bd8c6591
10 files changed
+600 -90

No files matched your search

@@ -152,14 +152,19 @@ _CONTEXT_CONFIGURABLE_KEYS: frozenset[str] = frozenset(
"model_name",
"mode",
"thinking_enabled",
"reasoning_effort",
"writing_mode",
"writing_artifact_path",
"is_plan_mode",
"reasoning_effort",
"writing_mode",
"writing_artifact_path",
"is_plan_mode",
"subagent_enabled",
"max_concurrent_subagents",
"agent_name",
"is_bootstrap",
"subagent_mode",
"search_space_id",
"mentioned_document_ids",
"pic_query",
"subagent_model_name",
}
)
@@ -302,12 +307,16 @@ def _collect_requested_agent_ids(body: Any) -> set[str]:
async def _sync_legacy_agent_records(store) -> None:
"""Import existing folder-backed agents as built-in records."""
import sys
from deerflow.config.agents_config import list_custom_agents
print(f"[_sync_legacy_agent_records] store type: {type(store).__name__}, id: {id(store)}", file=sys.stderr)
logger.info("_sync_legacy_agent_records: starting sync")
for agent_cfg in list_custom_agents():
agent_id = agent_cfg.id or agent_cfg.name
if not agent_id:
continue
logger.info(f" Syncing agent: {agent_id}")
await store.ensure_builtin(
{
"id": agent_id,
@@ -316,6 +325,7 @@ async def _sync_legacy_agent_records(store) -> None:
"published": True,
}
)
logger.info("_sync_legacy_agent_records: done")
async def _enforce_agent_access(body: Any, request: Request) -> None:
@@ -324,12 +334,20 @@ async def _enforce_agent_access(body: Any, request: Request) -> None:
return
from app.gateway.deps import get_agent_store
from deerflow.config.agents_config import validate_agent_id
from deerflow.config.agents_config import validate_agent_id, list_custom_agents
from deerflow.runtime.user_context import get_effective_user_id
store = get_agent_store(request)
import sys
print(f"[_enforce_agent_access] store type: {type(store).__name__}, id: {id(store)}", file=sys.stderr)
await _sync_legacy_agent_records(store)
user_id = get_effective_user_id()
logger.info(f"_enforce_agent_access: user_id={user_id}, agent_ids={agent_ids}")
# Debug: list all agents from list_custom_agents
all_agents = list_custom_agents()
logger.info(f" list_custom_agents() returned {len(all_agents)} agents: {[a.id for a in all_agents]}")
for agent_id in agent_ids:
try:
normalized = validate_agent_id(agent_id)
@@ -337,7 +355,13 @@ async def _enforce_agent_access(body: Any, request: Request) -> None:
raise HTTPException(status_code=422, detail=str(exc)) from exc
if normalized is None:
continue
if await store.get_visible(normalized, user_id) is None:
record = await store.get_visible(normalized, user_id)
logger.info(f" get_visible({normalized}, {user_id}) = {record}")
# Also check get_any
any_record = await store.get_any(normalized)
import sys
print(f"[_enforce_agent_access] get_any({normalized}) = {any_record}", file=sys.stderr)
if record is None:
raise HTTPException(status_code=404, detail=f"Agent {normalized} not found")