Spaces:
Sleeping
Sleeping
import os | |
import logging | |
import requests | |
from time import perf_counter, sleep | |
from memory_manager import embed_and_store, retrieve_relevant | |
# Agent prompts | |
PROMPTS = { | |
"Initiator": "You are the Discussion Initiator...", | |
"Responder": "You are the Critical Responder...", | |
"Guardian": "You are the Depth Guardian...", | |
"Provocateur": "You are the Cross-Disciplinary Provocateur...", | |
"Cultural": "You are the Cultural Perspective...", | |
"Judge": "You are the Impartial Judge..." | |
} | |
CHAT_MODEL = os.environ.get("CHAT_MODEL", "HuggingFaceH4/zephyr-7b-beta") | |
HF_API_TOKEN = os.environ.get("HF_API_TOKEN", "") | |
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s") | |
chat_history = "\n".join([f"{msg['role'].capitalize()}: {msg['content']}" for msg in history]) | |
full_prompt = f"{system_prompt}\n\n{chat_history}\n\nAssistant:" | |
payload = { | |
"inputs": full_prompt, | |
"parameters": {"max_new_tokens": 300, "temperature": temperature} | |
} | |
def step_turn(conversation: list, turn: int, topic: str, params: dict) -> list: | |
"""Advance one turn of the multi-agent conversation.""" | |
# Choose agent by sequence | |
sequence = ["Initiator", "Responder", "Guardian", "Provocateur", "Cultural"] | |
agent = sequence[turn % len(sequence)] | |
prompt = PROMPTS.get(agent, "") | |
# Prepare history | |
history = [{"role": "user", "content": msg['text']} for msg in conversation[-5:]] | |
response = safe_chat(prompt, history, temperature=params[agent]['creativity']) | |
embed_and_store(response, agent, topic) | |
conversation.append({"agent": agent, "text": response, "turn": turn + 1}) | |
return conversation |