Spaces:
Sleeping
Sleeping
| from llama_index.core.workflow import ( | |
| Event, | |
| StartEvent, | |
| StopEvent, | |
| Workflow, | |
| step, | |
| ) | |
| from llama_index.llms.deepseek import DeepSeek | |
| from llama_index.llms.openai import OpenAI | |
| import sys | |
| from pathlib import Path | |
| project_root = str(Path(__file__).parent) | |
| if project_root not in sys.path: | |
| sys.path.insert(0, project_root) | |
| import os | |
| from tools import web_search, math_tools, file_management_tools | |
| #from memory import set_memory | |
| from llama_index.core.agent.workflow import FunctionAgent, AgentWorkflow, ToolCall, ToolCallResult, ReActAgent | |
| from llama_index.llms.openai import OpenAI | |
| #from llama_index.core.memory import Memory | |
| import asyncio | |
| from datetime import datetime | |
| from llama_index.core.chat_engine.types import ChatMessage | |
| from llama_index.core import Settings | |
| from llama_index.core.callbacks import CallbackManager | |
| llm_gpt4o_mini = OpenAI( | |
| model="gpt-4o-mini", | |
| api_key=os.getenv("OPENAI_API_KEY"), | |
| temperature=0.3, | |
| max_retries=5, | |
| timeout=100 | |
| ) | |
| llm_deepseek_r1 = DeepSeek( | |
| model="deepseek-chat", | |
| api_key=os.getenv("DEEPSEEK_API_KEY"), | |
| temperature=0.2, | |
| max_retries=5, | |
| timeout=100 | |
| ) | |
| yt_transcripts = file_management_tools.read_youtube_video | |
| #test the llm | |
| #answerr = llm_deepseek_r1.complete("What is the capital of France?") | |
| #print(answerr) | |
| gpt_4o = OpenAI( | |
| model="gpt-4o", | |
| api_key=os.getenv("OPENAI_API_KEY"), | |
| temperature=0.2, | |
| max_retries=5, | |
| timeout=100 | |
| ) | |
| # Image and video understanding agent | |
| # TODO: Add tools for video, audio analysis. | |
| media_agent = FunctionAgent( | |
| llm=gpt_4o, | |
| name="Luna", | |
| description="An agent that analyzes videos, audio, and images to provide a summary of the content.", | |
| system_prompt=f"""Luna is an expert at analyzing videos, images, audio. Luna concisely leverages tools to analyze these modalities. | |
| TOOLS: | |
| PLAN: | |
| OUTPUT FORMATTING: """, | |
| tools = [yt_transcripts], | |
| can_handoff_to=["Viktor"], | |
| allow_parallel_tool_calls=True | |
| ) | |
| researcher_agent = FunctionAgent( | |
| llm=llm_deepseek_r1, | |
| name = "Viktor", | |
| description="An agent that researches local documentation and the web, and creates succint reports about a given topic based on the information it found", | |
| system_prompt=f"""Viktor is a multi-step reasoning assistant designed to provide comprehensive answers to user questions through systematic analysis and research. Viktor excels at breaking down complex queries and approaching them methodically. | |
| Available tools for Viktor: | |
| 1. 'web_search' tool - Viktor uses this to search the web for current information, facts, data, and real-time updates on any topic. | |
| 2. Math tools - Viktor can perform mathematical calculations including addition, subtraction, multiplication, division, and modulus operations. | |
| Viktor's Multi-Step Reasoning Workflow: | |
| 1. **Query Analysis**: When given a user query, Viktor first analyzes and understands what information is needed to provide a complete answer. | |
| 2. **Planning Phase**: Viktor develops a structured plan by: | |
| - Breaking complex questions into smaller, specific sub-questions | |
| - Identifying what types of information are needed (facts, recent updates, multiple perspectives, etc.) | |
| - Determining the logical sequence for gathering information | |
| 3. **Information Gathering**: Viktor systematically searches for information by: | |
| - Formulating targeted search queries for each aspect of the question | |
| - Conducting multiple searches to gather comprehensive information | |
| - Seeking current and relevant data to ensure accuracy | |
| 4. **Analysis and Synthesis**: Viktor processes the gathered information by: | |
| - Analyzing different sources and perspectives | |
| - Identifying patterns, connections, and key insights | |
| - Cross-referencing information for consistency and accuracy | |
| 5. **Structured Response**: Viktor provides a well-organized answer that: | |
| - Directly addresses the user's question | |
| - Presents information in a logical, easy-to-follow structure | |
| - Uses clear headings and formatting when appropriate | |
| - Includes relevant details while maintaining focus | |
| Reasoning Approach: | |
| - Viktor approaches each question methodically, thinking through multiple angles | |
| - For complex topics, Viktor gathers information from different perspectives | |
| - Viktor considers both current information and broader context | |
| - Viktor reasons through cause-and-effect relationships and implications | |
| - Viktor provides balanced, well-researched responses | |
| Response Guidelines: | |
| - STRICT!!! Only answer the question directly, concisely. For example, if the question is "What is the capital of France?", the answer should be "Paris". | |
| - No elaboration or explanation, only straight answer to the question. | |
| - Plain text response formatting. | |
| """, | |
| #TODO: Add tools for wikipedia, and document processing (csv, code, pdf, etc.) | |
| tools = [ | |
| web_search, | |
| math_tools.add, | |
| math_tools.subtract, | |
| math_tools.multiply, | |
| math_tools.divide, | |
| math_tools.modulus | |
| ], | |
| allow_parallel_tool_calls=True, | |
| can_handoff_to=["Luna"] | |
| ) | |
| workflow_agent = AgentWorkflow(agents = [researcher_agent, media_agent], root_agent=researcher_agent.name, verbose=True, handoff_prompt="Please handoff to the media agent to analyze videos, audio, images. {agent_info}") | |