add run.py
This commit is contained in:
+85
@@ -0,0 +1,85 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
"""Run script for Deep Agent with filesystem export."""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
from .agent import create_my_agent, extract_virtual_files, export_files_to_disk
|
||||||
|
|
||||||
|
|
||||||
|
# Load environment variables
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Run Deep Agent with internet search and file export"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"task",
|
||||||
|
type=str,
|
||||||
|
nargs="?",
|
||||||
|
default="Find the latest advancements in AI and save to summary.md",
|
||||||
|
help="Task description for the agent"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--export-dir",
|
||||||
|
type=str,
|
||||||
|
default="./exported_files",
|
||||||
|
help="Directory to export files to"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--thread-id",
|
||||||
|
type=str,
|
||||||
|
default="default",
|
||||||
|
help="Thread ID for state persistence"
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
print("\n" + "=" * 60)
|
||||||
|
print("🤖 DEEP AGENT")
|
||||||
|
print("=" * 60)
|
||||||
|
print(f"\n📋 Task: {args.task}\n")
|
||||||
|
print("-" * 60)
|
||||||
|
|
||||||
|
# Create and run the agent
|
||||||
|
agent = create_my_agent()
|
||||||
|
|
||||||
|
print("\n🔄 Running agent...\n")
|
||||||
|
|
||||||
|
# Invoke the agent
|
||||||
|
result = agent.invoke(
|
||||||
|
{"messages": [{"role": "user", "content": args.task}]},
|
||||||
|
config={"configurable": {"thread_id": args.thread_id}}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Display the agent's response
|
||||||
|
print("\n" + "=" * 60)
|
||||||
|
print("📝 AGENT RESPONSE")
|
||||||
|
print("=" * 60)
|
||||||
|
|
||||||
|
if "messages" in result:
|
||||||
|
last_message = result["messages"][-1]
|
||||||
|
if hasattr(last_message, 'content'):
|
||||||
|
print(f"\n{last_message.content}\n")
|
||||||
|
else:
|
||||||
|
print(f"\n{last_message}\n")
|
||||||
|
|
||||||
|
# Extract and export virtual files
|
||||||
|
print("\n" + "=" * 60)
|
||||||
|
print("💾 EXPORTING VIRTUAL FILES")
|
||||||
|
print("=" * 60)
|
||||||
|
print()
|
||||||
|
|
||||||
|
files = extract_virtual_files(agent, thread_id=args.thread_id)
|
||||||
|
export_files_to_disk(files, export_dir=args.export_dir)
|
||||||
|
|
||||||
|
print("\n" + "=" * 60)
|
||||||
|
print("✅ DONE")
|
||||||
|
print("=" * 60)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user