import asyncio from llama_index.core.agent.workflow import AgentWorkflow from tools import weather_info_tool, hub_stats_tool from llama_index.llms.openai import OpenAI from llama_index.tools.duckduckgo import DuckDuckGoSearchToolSpec from llama_index.core.tools import FunctionTool from llama_index.core.workflow import Context async def main(): llm = OpenAI(model="gpt-4o") # Initialize the web search tool tool_spec = DuckDuckGoSearchToolSpec() search_tool = FunctionTool.from_defaults(tool_spec.duckduckgo_full_search) # Create Alfred, our gala agent, with the guest info tool alfred = AgentWorkflow.from_tools_or_functions( [weather_info_tool, hub_stats_tool, search_tool], llm=llm, ) # Example query Alfred might receive during the gala #response = await alfred.run("What is Facebook and what's their most popular model?") #print("🎩 Alfred's Response:") #print(response) # Example query Alfred might receive during the gala #response = await alfred.run("What happened with prime minister in France today, and how is the weather in Paris?") #print("🎩 Alfred's Response:") #print(response) # Remembering state ctx = Context(alfred) # First interaction response1 = await alfred.run("Tell me about Lady Ada Lovelace.", ctx=ctx) print("🎩 Alfred's First Response:") print(response1) # Second interaction (referencing the first) response2 = await alfred.run("What projects is she currently working on?", ctx=ctx) print("🎩 Alfred's Second Response:") print(response2) if __name__ == "__main__": asyncio.run(main())