CoolFace
Apppublic

polojuan/agentic-workflows

sourceHugging Facemitupdated 11mo agoView on Hugging Face
0likes
planner_agent.py71 linesDownload Raw Back to agents
1import streamlit as st2from openai import OpenAI3from dotenv import find_dotenv, load_dotenv4 5# Load environment variables6load_dotenv(find_dotenv())7 8def agent_prompt(page):9    if page == "researcher":10        agent_prompts = """11        - A research agent who can search the web, Wikipedia, and arXiv.12        - A writer agent who can draft research summaries.13        - An editor agent who can reflect, critique and improve existing drafts. 14        """15    elif page == "medical":16        agent_prompts = """17        - A medical agent who can search the medical publication websites.18        - A writer agent who can draft research summaries.19        - An editor agent who can reflect, critique and improve existing drafts. 20        """21    return agent_prompts22 23def planner_agent(topic: str, model: str = "gpt-5", max_steps: int = 5, page: str = "researcher") -> list[str]:24    """25    Generates a plan as a Python list of steps (strings) for a research workflow.26 27    Args:28        topic (str): Research topic to investigate.29        model (str): Language model to use.30 31    Returns:32        List[str]: A list of executable step strings.33    """34    # Get client from session state35    client = st.session_state.get("client") or OpenAI()36 37    prompt = f"""38You are a planning agent responsible for organizing a research workflow with multiple intelligent agents.39 40๐Ÿง  Available agents:41{agent_prompt(page)}42 43๐ŸŽฏ Your job is to write a clear, step-by-step research plan **as a valid Python list**, where each step is a string.44Each step should be atomic, executable, and must rely only on the capabilities of the above agents.45 46๐Ÿšซ DO NOT include irrelevant tasks like "create CSV", "set up a repo", "install packages", etc.47โœ… DO include real research-related tasks (e.g., search, summarize, draft, revise).48โœ… DO limit the search from few relevant sources.49โœ… DO assume tool use is available.50๐Ÿšซ DO NOT include explanation text โ€” return ONLY the Python list.51โœ… The final step should be to generate a Markdown document containing the complete and concise research report with topic title, introduction, findings, conclusion, references (APA format citation showing full links). 52๐Ÿšซ DO NOT ask any questions on the next steps at the end of the final Markdown document.53 54Topic: "{topic}"55 56Limit planning into {max_steps} steps.57"""58 59    response = client.chat.completions.create(60        model=model,61        messages=[{"role": "user", "content": prompt}],62        temperature=1,63    )64 65    # โš ๏ธ Evaluate only if the environment is safe66    steps = eval(response.choices[0].message.content.strip())67    used_tokens = response.usage.total_tokens68    print("Used Tokens:\n", used_tokens)69    return steps70 71