From 5d4ff87d684c041bec582d956b3ec38b1cd10f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=B4=D0=B5=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A1=D0=B0?= =?UTF-8?q?=D1=82=D1=82=D0=B0=D1=80=D0=BE=D0=B2=D0=B0?= Date: Thu, 4 Jun 2026 13:31:29 +0000 Subject: [PATCH] add main --- src/main.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/main.py diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..9a21fc2 --- /dev/null +++ b/src/main.py @@ -0,0 +1,53 @@ +""" +Deep Agents from Scratch example. +This script demonstrates a simple agent that searches the web and writes results to files. +It uses the `deep-agents-from-scratch` package as required by the assignment. +""" + +from __future__ import annotations + +import os +from pathlib import Path + +# Ensure dependencies are available +try: + from deep_agents_from_scratch.research_tools import tavily_search, think_tool +except Exception as e: # pragma: no cover - defensive + raise RuntimeError("deep-agents-from-scratch not installed") from e + +from langchain.agents import create_agent +from langchain.chat_models import init_chat_model +from deep_agents_from_scratch.state import DeepAgentState +from deep_agents_from_scratch.file_tools import ls, read_file, write_file + +# Simple prompt for the agent +SYSTEM_PROMPT = """ +You are a research assistant. Use web search to gather information and store results in files. +After each search, reflect on what you found. +""" + +model = init_chat_model(model="anthropic:claude-sonnet-4-20250514", temperature=0) + +# Tools available to the agent +TOOLS = [tavily_search, think_tool, ls, read_file, write_file] + +agent = create_agent( + model, + TOOLS, + system_prompt=SYSTEM_PROMPT, + state_schema=DeepAgentState, +) + +def run_query(query: str) -> None: + """Run a single query and print the resulting messages.""" + result = agent.invoke({"messages": [{"role": "user", "content": query}]}) + for msg in result["messages"]: + print(msg.content) + +if __name__ == "__main__": # pragma: no cover - entry point + import argparse + + parser = argparse.ArgumentParser(description="Run deep agent example") + parser.add_argument("query", help="Query to search for") + args = parser.parse_args() + run_query(args.query)