feat(agent-core): 增加智能编排与模型工具基础
This commit is contained in:
40
agent_core/orchestrator.py
Normal file
40
agent_core/orchestrator.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import time
|
||||
|
||||
from .results import AgentResult
|
||||
from .structured_output import build_mock_structured_output
|
||||
from .tool_registry import run_declared_tools
|
||||
from .rag.retriever import retrieve
|
||||
|
||||
|
||||
def run_agent(scenario_config: dict, user_input: str, options: dict | None = None) -> AgentResult:
|
||||
started_at = time.perf_counter()
|
||||
options = options or {}
|
||||
output_type = scenario_config.get("output", {}).get("type", "general_answer")
|
||||
|
||||
references = []
|
||||
rag_config = scenario_config.get("rag", {})
|
||||
if rag_config.get("enabled"):
|
||||
references = retrieve(
|
||||
scenario_id=scenario_config.get("id", ""),
|
||||
query=user_input,
|
||||
collection=rag_config.get("collection", scenario_config.get("id", "")),
|
||||
top_k=rag_config.get("top_k", 5),
|
||||
document_ids=options.get("document_ids"),
|
||||
store_path=options.get("rag_store_path"),
|
||||
)
|
||||
|
||||
tool_calls = run_declared_tools(scenario_config.get("tools", []), user_input)
|
||||
structured_output = build_mock_structured_output(output_type, user_input, references)
|
||||
answer = f"已根据「{scenario_config.get('name', '当前场景')}」生成模拟回答:{user_input}"
|
||||
latency_ms = int((time.perf_counter() - started_at) * 1000)
|
||||
|
||||
return AgentResult(
|
||||
answer=answer,
|
||||
structured_output=structured_output,
|
||||
references=references,
|
||||
tool_calls=tool_calls,
|
||||
raw_output=answer,
|
||||
model_name=options.get("model_name", "mock-model"),
|
||||
latency_ms=latency_ms,
|
||||
status="success",
|
||||
)
|
||||
Reference in New Issue
Block a user