mirror of
https://github.com/hoshikawa2/agent_platform_oci.git
synced 2026-11-05 19:04:13 +00:00
new feature: Multi-Intent
This commit is contained in:
@@ -13,16 +13,23 @@ def replace_once(text: str, old: str, new: str, path: Path) -> str:
|
||||
|
||||
def update_state(path: Path) -> None:
|
||||
text = path.read_text(encoding="utf-8")
|
||||
if " pending_topics: list[dict[str, Any]]" in text:
|
||||
return
|
||||
text = replace_once(
|
||||
text,
|
||||
" supervisor_results: list[dict[str, Any]]\n",
|
||||
" supervisor_results: list[dict[str, Any]]\n"
|
||||
" pending_topics: list[dict[str, Any]]\n"
|
||||
" handled_topics: list[dict[str, Any]]\n",
|
||||
path,
|
||||
)
|
||||
if " pending_topics: list[dict[str, Any]]" not in text:
|
||||
text = replace_once(
|
||||
text,
|
||||
" supervisor_results: list[dict[str, Any]]\n",
|
||||
" supervisor_results: list[dict[str, Any]]\n"
|
||||
" pending_topics: list[dict[str, Any]]\n"
|
||||
" handled_topics: list[dict[str, Any]]\n",
|
||||
path,
|
||||
)
|
||||
if " rag_results: list[dict[str, Any]]" not in text:
|
||||
text = replace_once(
|
||||
text,
|
||||
" mcp_results: list[dict[str, Any]]\n",
|
||||
" mcp_results: list[dict[str, Any]]\n"
|
||||
" rag_results: list[dict[str, Any]]\n",
|
||||
path,
|
||||
)
|
||||
path.write_text(text, encoding="utf-8")
|
||||
|
||||
|
||||
@@ -121,17 +128,119 @@ def update_guardrail_evidence_context(path: Path) -> None:
|
||||
path.write_text(text, encoding="utf-8")
|
||||
|
||||
|
||||
def update_rag_propagation(path: Path) -> None:
|
||||
text = path.read_text(encoding="utf-8")
|
||||
mcp_line = ' "mcp_results": drained.mcp_results,\n'
|
||||
rag_line = mcp_line + ' "rag_results": drained.rag_results,\n'
|
||||
if rag_line not in text:
|
||||
if mcp_line not in text:
|
||||
raise RuntimeError(f"Marcador MCP não encontrado em {path}")
|
||||
text = text.replace(mcp_line, rag_line)
|
||||
text = text.replace(
|
||||
' "evidence": drained.mcp_results or (state.get("context") or {}).get("evidence"),\n',
|
||||
' "evidence": (list(drained.mcp_results) + list(drained.rag_results)) or (state.get("context") or {}).get("evidence"),\n',
|
||||
)
|
||||
marker = ' current_evidence = list(state.get("mcp_results", []) or [])\n'
|
||||
addition = marker + ' current_evidence.extend(state.get("rag_results", []) or [])\n'
|
||||
if marker in text and addition not in text:
|
||||
text = text.replace(marker, addition, 1)
|
||||
path.write_text(text, encoding="utf-8")
|
||||
|
||||
|
||||
def update_rag_agents(path: Path) -> None:
|
||||
text = path.read_text(encoding="utf-8")
|
||||
marker = ' "rag": rag_metadata,\n'
|
||||
if marker not in text or ' "rag_results": [{\n' in text:
|
||||
return
|
||||
addition = marker + (
|
||||
' "rag_context": rag_context,\n'
|
||||
' "rag_results": [{\n'
|
||||
' "intent": state.get("intent"),\n'
|
||||
' "agent": self.name,\n'
|
||||
' "source_text": str(state.get("sanitized_input") or state.get("user_text") or ""),\n'
|
||||
' "metadata": rag_metadata,\n'
|
||||
' **({"context": rag_context} if rag_context else {}),\n'
|
||||
' }],\n'
|
||||
)
|
||||
path.write_text(text.replace(marker, addition, 1), encoding="utf-8")
|
||||
|
||||
|
||||
def update_rag_http_response(path: Path) -> None:
|
||||
text = path.read_text(encoding="utf-8")
|
||||
marker = ' "mcp_results": result.get("mcp_results"),\n'
|
||||
addition = marker + ' "rag_results": result.get("rag_results"),\n'
|
||||
if addition not in text:
|
||||
text = replace_once(text, marker, addition, path)
|
||||
path.write_text(text, encoding="utf-8")
|
||||
|
||||
|
||||
def update_rag_telemetry(path: Path) -> None:
|
||||
text = path.read_text(encoding="utf-8")
|
||||
marker = ' "mcp_results": state.get("mcp_results", []),\n'
|
||||
addition = marker + ' "rag_results": state.get("rag_results", []),\n'
|
||||
if addition not in text:
|
||||
text = replace_once(text, marker, addition, path)
|
||||
path.write_text(text, encoding="utf-8")
|
||||
|
||||
|
||||
def update_rag_env(path: Path) -> None:
|
||||
text = path.read_text(encoding="utf-8")
|
||||
if "KBDB_IDENTIFY_DOCUMENT=" in text:
|
||||
return
|
||||
marker = "RAG_FILE_GLOBS=*.md,*.txt,*.yaml,*.yml,*.json\n"
|
||||
settings_block = """
|
||||
# RAG / KBDB
|
||||
# RAG provider: standard (local) ou kbdb (PKG_KB_SERVING.SEARCH_KNOWLEDGE_BASE)
|
||||
RAG_PROVIDER=standard
|
||||
# KBDB usa credenciais próprias; não há fallback para ADB_*.
|
||||
KBDB_DB_USER=
|
||||
KBDB_DB_PASSWORD=
|
||||
KBDB_DB_DSN=
|
||||
KBDB_DB_WALLET_LOCATION=
|
||||
KBDB_DB_WALLET_PASSWORD=
|
||||
KBDB_SEARCH_TYPE=hybrid
|
||||
KBDB_NODE_EXPANSION=true
|
||||
KBDB_NODE_MAX_RELATED=8
|
||||
KBDB_GRAPH_CROSS_REF=false
|
||||
KBDB_MAX_CROSS_REF_HOPS=1
|
||||
KBDB_DOCUMENT_TYPE=customer_safe
|
||||
KBDB_METADATA_JSON=
|
||||
KBDB_MIN_SCORE=
|
||||
KBDB_IDENTIFY_DOCUMENT=true
|
||||
KBDB_STORE_QUERY=true
|
||||
KBDB_IDENTIFY_TOP_N=3
|
||||
RAG_GROUNDED_ONLY=false
|
||||
KBDB_GROUNDED_ONLY=true
|
||||
"""
|
||||
if marker in text:
|
||||
text = text.replace(marker, marker + "\n" + settings_block, 1)
|
||||
else:
|
||||
text = text.rstrip() + "\n\n" + settings_block
|
||||
path.write_text(text, encoding="utf-8")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
tuning = ROOT / "Tuning-Performance"
|
||||
states = sorted(tuning.glob("**/app/state.py"))
|
||||
graphs = sorted(tuning.glob("**/app/workflows/agent_graph.py"))
|
||||
agents = sorted(tuning.glob("**/app/agents/*.py"))
|
||||
mains = sorted(tuning.glob("**/app/main.py"))
|
||||
envs = sorted(tuning.glob("**/.env.example"))
|
||||
for path in states:
|
||||
update_state(path)
|
||||
for path in graphs:
|
||||
update_graph(path)
|
||||
update_evidence_propagation(path)
|
||||
update_guardrail_evidence_context(path)
|
||||
print(f"pending_topics sincronizado: {len(states)} states, {len(graphs)} graphs")
|
||||
update_rag_propagation(path)
|
||||
update_rag_telemetry(path)
|
||||
for path in agents:
|
||||
update_rag_agents(path)
|
||||
for path in mains:
|
||||
update_rag_http_response(path)
|
||||
for path in envs:
|
||||
update_rag_env(path)
|
||||
print(f"pending_topics/RAG sincronizado: {len(states)} states, {len(graphs)} graphs, {len(agents)} agents, {len(mains)} APIs, {len(envs)} envs")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user