new feature: Multi-Intent

This commit is contained in:
2026-09-11 00:35:05 -03:00
parent a9bbad22a5
commit 6c81b21aaa
315 changed files with 855 additions and 35 deletions

View File

@@ -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,80 @@ 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 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"))
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)
print(f"pending_topics/RAG sincronizado: {len(states)} states, {len(graphs)} graphs, {len(agents)} agents, {len(mains)} APIs")
if __name__ == "__main__":