A curated collection of practical AI projects implementing OCR systems, RAG, AI agents, and other AI use cases.
fix(multi_agent_research_assistant_ag2): remove unresolved merge conflict markers
Rudy Celekli524eea70ec48
diff --git a/ai_agents/multi_agent_research_assistant_ag2/.env.example b/ai_agents/multi_agent_research_assistant_ag2/.env.exampleindex 31e8faf..48e13ce 100644--- a/ai_agents/multi_agent_research_assistant_ag2/.env.example+++ b/ai_agents/multi_agent_research_assistant_ag2/.env.example@@ -1,10 +1,4 @@-<<<<<<< HEAD-OPENAI_API_KEY=your_openai_api_key_here-OPENAI_BASE_URL=https://api.openai.com/v1 # override for SambaNova, Azure, etc.-LLM_MODEL=gpt-4o-mini-=======# Mistral API key used by the researcher, analyst, and writer agents (Mistral Small 4).# Get one at https://console.mistral.ai/api-keysMISTRAL_API_KEY=your_mistral_api_key_hereLLM_MODEL=mistral-small-latest->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4adiff --git a/ai_agents/multi_agent_research_assistant_ag2/requirements.txt b/ai_agents/multi_agent_research_assistant_ag2/requirements.txtindex 2bedb67..4cf915d 100644--- a/ai_agents/multi_agent_research_assistant_ag2/requirements.txt+++ b/ai_agents/multi_agent_research_assistant_ag2/requirements.txt@@ -1,7 +1,4 @@ag2>=0.11.0-<<<<<<< HEAD-=======mistralai>=2.0.0->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4astreamlit>=1.31.0python-dotenv>=1.0.0diff --git a/ai_agents/multi_agent_research_assistant_ag2/research_assistant.py b/ai_agents/multi_agent_research_assistant_ag2/research_assistant.pyindex 301bbae..f8d9354 100644--- a/ai_agents/multi_agent_research_assistant_ag2/research_assistant.py+++ b/ai_agents/multi_agent_research_assistant_ag2/research_assistant.py@@ -1,9 +1,5 @@-<<<<<<< HEAD-# research_assistant.py-======="""Multi-agent research pipeline using AG2 (AutoGen): researcher, analyst, and writeragents collaborate under GroupChat, powered by Mistral Small 4, with a Streamlit UI."""->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4aimport osimport streamlit as stfrom datetime import datetime@@ -14,18 +10,6 @@ from tools.research_tools import web_search, fetch_page_contentload_dotenv()-<<<<<<< HEAD-# ── AG2 (formerly AutoGen) requires ag2>=0.11 ──────────────────────────────────--def build_llm_config() -> LLMConfig:- api_key = os.getenv("OPENAI_API_KEY", "")- if not api_key:- raise ValueError("OPENAI_API_KEY is not set. Add it to .env or the sidebar.")- return LLMConfig(- {"model": os.getenv("LLM_MODEL", "gpt-4o-mini"),- "api_key": api_key,- "base_url": os.getenv("OPENAI_BASE_URL", "https://api.openai.com/v1")},-=======# ── Patch: normalize Mistral citation chunks before AG2's message parser sees them ──# Mistral's grounding/web-search feature returns AssistantMessage.content as# list[TextChunk | ReferenceChunk] instead of a plain str. AG2's ChatCompletionMessage@@ -67,15 +51,12 @@ def build_llm_config() -> LLMConfig:{"api_type": "mistral","model": os.getenv("LLM_MODEL", "mistral-small-latest"),"api_key": api_key},->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4atemperature=0.3,cache_seed=None, # always fetch fresh data)def run_research(topic: str) -> str:-<<<<<<< HEAD-======="""Runs the researcher, analyst, and writer agents and returns the final report.Tool calls are confined to an isolated researcher/executor exchange, separate from@@ -84,22 +65,14 @@ def run_research(topic: str) -> str:"auto" speaker selection asks the LLM who should speak next while a tool call fromresearcher is still awaiting its response from executor."""->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4allm_config = build_llm_config()# ── Agents ─────────────────────────────────────────────────────────────────researcher = AssistantAgent(name="researcher",-<<<<<<< HEAD- system_message="""You are a research specialist. Your job is to gather-comprehensive information about the given topic using web_search and fetch_page_content.-Perform at least 3 searches and fetch content from 2+ pages.-Summarise all findings clearly. End with: RESEARCH COMPLETE.""",-=======system_message="""You are a research specialist. Search for information about the given topic using web_search.Perform exactly 2 searches, then summarise the findings clearly. End with: RESEARCH COMPLETE.""",->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4allm_config=llm_config,)@@ -128,13 +101,9 @@ End with: REPORT COMPLETE""",name="executor",human_input_mode="NEVER",code_execution_config={"work_dir": "workspace", "use_docker": False},-<<<<<<< HEAD- is_termination_msg=lambda msg: "REPORT COMPLETE" in (msg.get("content") or ""),-=======is_termination_msg=lambda msg: any(phrase in (msg.get("content") or "") for phrase in ("RESEARCH COMPLETE", "REPORT COMPLETE")),->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4adefault_auto_reply="",)@@ -152,14 +121,6 @@ End with: REPORT COMPLETE""",description=(fn.__doc__ or "").strip().split("\n")[0],)-<<<<<<< HEAD- # ── GroupChat orchestration ────────────────────────────────────────────────- groupchat = GroupChat(- agents=[executor, researcher, analyst, writer],- messages=[],- max_round=20,- speaker_selection_method="auto", # LLM selects the next speaker-=======# ── Phase 1: isolated researcher/executor exchange ─────────────────────────# A plain two-agent chat always pairs a tool call with its response in the# same turn, so there is never an orphaned tool call in the history.@@ -185,17 +146,12 @@ End with: REPORT COMPLETE""",messages=[],max_round=6,speaker_selection_method="round_robin", # analyst then writer, no extra LLM call per round->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a)manager = GroupChatManager(groupchat=groupchat, llm_config=llm_config)executor.initiate_chat(manager,-<<<<<<< HEAD- message=f"Research the following topic thoroughly: {topic}",-=======message=f"Research on '{topic}' is complete. Analyst, please critically evaluate the findings below:\n\n{research_notes}",->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4aclear_history=True,)@@ -212,26 +168,10 @@ End with: REPORT COMPLETE""",st.set_page_config(page_title="Multi-Agent Research Assistant (AG2)", layout="wide")st.title("Multi-Agent Research Assistant")-<<<<<<< HEAD-st.caption("Powered by AG2 (formerly AutoGen) — multi-agent research orchestration")--with st.sidebar:- st.header("Configuration")- api_key = st.text_input("OpenAI API Key", type="password",- value=os.getenv("OPENAI_API_KEY", ""))- if api_key:- os.environ["OPENAI_API_KEY"] = api_key- model = st.text_input("Model", value=os.getenv("LLM_MODEL", "gpt-4o-mini"))- if model:- os.environ["LLM_MODEL"] = model- topic = st.text_area("Research Topic", placeholder="e.g. 'Latest advances in quantum computing'")- run_btn = st.button("Start Research", type="primary")-=======st.caption("Powered by AG2 (formerly AutoGen): multi-agent research orchestration")topic = st.text_area("Research Topic", placeholder="e.g. 'Latest advances in quantum computing'")run_btn = st.button("Start Research", type="primary")->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4aif "report" not in st.session_state:st.session_state.report = Nonediff --git a/ai_agents/multi_agent_research_assistant_ag2/tests/test_agent_setup.py b/ai_agents/multi_agent_research_assistant_ag2/tests/test_agent_setup.pyindex 781a90a..a3a2c52 100644--- a/ai_agents/multi_agent_research_assistant_ag2/tests/test_agent_setup.py+++ b/ai_agents/multi_agent_research_assistant_ag2/tests/test_agent_setup.py@@ -1,10 +1,6 @@import osimport pytest-<<<<<<< HEAD-os.environ.setdefault("OPENAI_API_KEY", "test-key-no-llm-calls")-=======os.environ.setdefault("MISTRAL_API_KEY", "test-key-no-llm-calls")->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4adef test_agents_instantiate():"""Verify agent setup does not raise — no LLM calls made."""@@ -38,11 +34,7 @@ def test_tool_registration():from tools.research_tools import web_search, fetch_page_contentfrom autogen import AssistantAgent, UserProxyAgent, LLMConfig, register_function-<<<<<<< HEAD- llm = LLMConfig({"model": "gpt-4o-mini", "api_key": "test"})-=======llm = LLMConfig({"api_type": "mistral", "model": "mistral-small-latest", "api_key": "test"})->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4aresearcher = AssistantAgent(name="r", system_message="test", llm_config=llm)executor = UserProxyAgent(name="e", human_input_mode="NEVER", code_execution_config=False)for fn in (web_search, fetch_page_content):