Skip to content

Commit 249341b

Browse files
authored
Release v2.0.1
Develop
2 parents ff10a48 + 5da43e8 commit 249341b

File tree

116 files changed

+18506
-1915
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+18506
-1915
lines changed

backend/agents/create_agent_info.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
ElasticSearchService,
1515
get_vector_db_core,
1616
get_embedding_model,
17+
get_rerank_model,
1718
)
1819
from services.remote_mcp_service import get_remote_mcp_server_list
1920
from services.memory_config_service import build_memory_context
@@ -296,8 +297,6 @@ async def create_agent_config(
296297
}
297298
system_prompt = Template(prompt_template["system_prompt"], undefined=StrictUndefined).render(render_kwargs)
298299

299-
_print_prompt_with_token_count(system_prompt, agent_id, "BEFORE_INJECTION")
300-
301300
if agent_info.get("model_id") is not None:
302301
model_info = get_model_by_model_id(agent_info.get("model_id"))
303302
model_name = model_info["display_name"] if model_info is not None else "main_model"
@@ -350,11 +349,32 @@ async def create_tool_config_list(agent_id, tenant_id, user_id, version_no: int
350349
tool_config.metadata = langchain_tool
351350
break
352351

353-
# special logic for knowledge base search tool
352+
# special logic for search tools that may use reranking models
354353
if tool_config.class_name == "KnowledgeBaseSearchTool":
355-
tool_config.metadata = {
354+
rerank = param_dict.get("rerank", False)
355+
rerank_model_name = param_dict.get("rerank_model_name", "")
356+
rerank_model = None
357+
if rerank and rerank_model_name:
358+
rerank_model = get_rerank_model(
359+
tenant_id=tenant_id, model_name=rerank_model_name
360+
)
361+
362+
tool_config.metadata = {
356363
"vdb_core": get_vector_db_core(),
357364
"embedding_model": get_embedding_model(tenant_id=tenant_id),
365+
"rerank_model": rerank_model,
366+
}
367+
elif tool_config.class_name in ["DifySearchTool", "DataMateSearchTool"]:
368+
rerank = param_dict.get("rerank", False)
369+
rerank_model_name = param_dict.get("rerank_model_name", "")
370+
rerank_model = None
371+
if rerank and rerank_model_name:
372+
rerank_model = get_rerank_model(
373+
tenant_id=tenant_id, model_name=rerank_model_name
374+
)
375+
376+
tool_config.metadata = {
377+
"rerank_model": rerank_model,
358378
}
359379
elif tool_config.class_name == "AnalyzeTextFileTool":
360380
tool_config.metadata = {
@@ -430,25 +450,9 @@ async def prepare_prompt_templates(
430450
prompt_templates = get_agent_prompt_template(is_manager, language)
431451
prompt_templates["system_prompt"] = system_prompt
432452

433-
# Print final prompt with all injections
434-
_print_prompt_with_token_count(prompt_templates["system_prompt"], agent_id, "FINAL_PROMPT")
435-
436453
return prompt_templates
437454

438455

439-
def _print_prompt_with_token_count(prompt: str, agent_id: int = None, stage: str = "PROMPT"):
440-
"""Print prompt content and estimate token count using tiktoken."""
441-
try:
442-
import tiktoken
443-
encoding = tiktoken.get_encoding("cl100k_base")
444-
token_count = len(encoding.encode(prompt))
445-
logger.info(f"[Skill Debug][{stage}] Agent {agent_id} token count: {token_count}")
446-
logger.info(f"[Skill Debug][{stage}] Agent {agent_id} prompt:\n{prompt}")
447-
except Exception as e:
448-
logger.warning(f"[Skill Debug][{stage}] Failed to count tokens: {e}")
449-
logger.info(f"[Skill Debug][{stage}] Agent {agent_id} prompt:\n{prompt}")
450-
451-
452456
async def join_minio_file_description_to_query(minio_files, query):
453457
final_query = query
454458
if minio_files and isinstance(minio_files, list):
@@ -527,7 +531,7 @@ async def create_agent_run_info(
527531
remote_mcp_list = await get_remote_mcp_server_list(tenant_id=tenant_id, is_need_auth=True)
528532
default_mcp_url = urljoin(LOCAL_MCP_SERVER, "sse")
529533
remote_mcp_list.append({
530-
"remote_mcp_server_name": "nexent",
534+
"remote_mcp_server_name": "outer-apis",
531535
"remote_mcp_server": default_mcp_url,
532536
"status": True,
533537
"authorization_token": None
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
"""Skill creation agent module for interactive skill generation."""
2+
3+
import logging
4+
import threading
5+
from typing import List
6+
7+
from nexent.core.agents.agent_model import AgentConfig, AgentRunInfo, ModelConfig, ToolConfig
8+
from nexent.core.agents.run_agent import agent_run_thread
9+
from nexent.core.utils.observer import MessageObserver
10+
11+
logger = logging.getLogger("skill_creation_agent")
12+
13+
14+
def create_skill_creation_agent_config(
15+
system_prompt: str,
16+
model_config_list: List[ModelConfig],
17+
local_skills_dir: str = ""
18+
) -> AgentConfig:
19+
"""
20+
Create agent config for skill creation with builtin tools.
21+
22+
Args:
23+
system_prompt: Custom system prompt to replace smolagent defaults
24+
model_config_list: List of model configurations
25+
26+
Returns:
27+
AgentConfig configured for skill creation
28+
"""
29+
if not model_config_list:
30+
raise ValueError("model_config_list cannot be empty")
31+
32+
first_model = model_config_list[0]
33+
34+
prompt_templates = {
35+
"system_prompt": system_prompt,
36+
"managed_agent": {
37+
"task": "{task}",
38+
"report": "## {name} Report\n\n{final_answer}"
39+
},
40+
"planning": {
41+
"initial_plan": "",
42+
"update_plan_pre_messages": "",
43+
"update_plan_post_messages": ""
44+
},
45+
"final_answer": {
46+
"pre_messages": "",
47+
"post_messages": ""
48+
}
49+
}
50+
51+
return AgentConfig(
52+
name="__skill_creator__",
53+
description="Internal skill creator agent",
54+
prompt_templates=prompt_templates,
55+
tools=[],
56+
max_steps=5,
57+
model_name=first_model.cite_name
58+
)
59+
60+
61+
def run_skill_creation_agent(
62+
query: str,
63+
agent_config: AgentConfig,
64+
model_config_list: List[ModelConfig],
65+
observer: MessageObserver,
66+
stop_event: threading.Event,
67+
) -> None:
68+
"""
69+
Run the skill creator agent synchronously.
70+
71+
Args:
72+
query: User query for the agent
73+
agent_config: Pre-configured agent config
74+
model_config_list: List of model configurations
75+
observer: Message observer for capturing agent output
76+
stop_event: Threading event for cancellation
77+
"""
78+
agent_run_info = AgentRunInfo(
79+
query=query,
80+
model_config_list=model_config_list,
81+
observer=observer,
82+
agent_config=agent_config,
83+
stop_event=stop_event
84+
)
85+
86+
agent_run_thread(agent_run_info)
87+
88+
89+
def create_simple_skill_from_request(
90+
system_prompt: str,
91+
user_prompt: str,
92+
model_config_list: List[ModelConfig],
93+
observer: MessageObserver,
94+
stop_event: threading.Event,
95+
local_skills_dir: str = ""
96+
) -> None:
97+
"""
98+
Run skill creation agent to create a skill interactively.
99+
100+
The agent will write the skill content to tmp.md in local_skills_dir.
101+
Frontend should read tmp.md after agent completes to get the skill content.
102+
103+
Args:
104+
system_prompt: System prompt with skill creation instructions
105+
user_prompt: User's skill description request
106+
model_config_list: List of model configurations
107+
observer: Message observer for capturing agent output
108+
stop_event: Threading event for cancellation
109+
local_skills_dir: Path to local skills directory for file operations
110+
"""
111+
agent_config = create_skill_creation_agent_config(
112+
system_prompt=system_prompt,
113+
model_config_list=model_config_list,
114+
local_skills_dir=local_skills_dir
115+
)
116+
117+
thread_agent = threading.Thread(
118+
target=run_skill_creation_agent,
119+
args=(user_prompt, agent_config, model_config_list, observer, stop_event)
120+
)
121+
thread_agent.start()
122+
thread_agent.join()

0 commit comments

Comments
 (0)