From 74109487000b39d1e51cbe171fd8c32d38c7de0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A0=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Fri, 5 Jun 2026 12:37:35 +0000 Subject: [PATCH] Add src/agent.py --- src/agent.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/agent.py diff --git a/src/agent.py b/src/agent.py new file mode 100644 index 0000000..69905b2 --- /dev/null +++ b/src/agent.py @@ -0,0 +1,45 @@ +"""Agent wrapper that uses LangChain's create_agent. + +This module demonstrates how to create an agent that can run the +research brief graph. It imports ``create_agent`` from +``langchain.agents`` as required by the task. +""" + +from langchain.agents import create_agent +from langchain_openai import ChatOpenAI +from langchain_core.tools import BaseTool +from typing import Dict, Any + +# Import the graph builder +from .brief import build_graph + +class RunBriefTool(BaseTool): + """Tool that runs the research brief graph for a given topic.""" + + name: str = "run_brief" + description: str = "Run the research brief graph for a given topic." + + def _run(self, topic: str) -> str: + # Build the graph and run it + graph = build_graph() + state: Dict[str, Any] = { + "topic": topic, + "outline": None, + "step_index": 0, + "notes": [], + "final_brief": None, + } + result = graph.invoke(state) + return result.get("final_brief", "No brief produced.") + +# Create the agent using the required create_agent function +llm = ChatOpenAI() +agent = create_agent(model=llm, tools=[RunBriefTool()]) + +# Expose a simple helper for external use + +def run_agent(topic: str) -> str: + """Invoke the agent with the given topic and return the brief.""" + response = agent.invoke({"messages": [{"role": "user", "content": topic}]}) + # The agent will return the tool output as a string + return response \ No newline at end of file