Files
MultiAgent/agent/plan_reviewer.py
2026-04-12 11:48:37 +05:00

30 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# reviewer.py
from langchain_ollama import ChatOllama
from langchain_core.messages import SystemMessage, HumanMessage
from typing import List, Dict
from config import MODEL_NAME, LLM_HOST
import json
class PlanReviewerAgent:
def __init__(self, llm=None):
self.llm = llm or ChatOllama(
model=MODEL_NAME,
temperature=0.0,
base_url=LLM_HOST
)
def review(self, original_task: str, plan: List[Dict], execution_results: List[Dict]) -> dict:
system_prompt = """Ты - ревьювер. Оцени, достигнута ли цель задачи на основе выполненного плана.
Верни JSON с полями:
- "status": "approved" / "changes_requested" / "rejected"
- "feedback": пояснение
- "suggested_plan_correction": если нужно изменить план - предложи новый план (массив шагов)
"""
user_prompt = f"""
Задача: {original_task}
План: {json.dumps(plan, indent=2)}
Результаты выполнения: {json.dumps(execution_results, indent=2)}
Оцени результат.
"""
response = self.llm.invoke([SystemMessage(content=system_prompt), HumanMessage(content=user_prompt)])
return json.loads(response.content)