import streamlit as st from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, ToolCallingAgent, ManagedAgent, VisitWebpageTool web_agent = ToolCallingAgent( tools=[DuckDuckGoSearchTool(max_results=10), VisitWebpageTool()], model=HfApiModel(), ) managed_web_agent = ManagedAgent( agent=web_agent, name="search", description="Runs tech web searches. Give it your query as an argument. Also, this agent should link to the sources you are using. If any specific sites are provided, this agent will only those sources.", ) manager_agent = CodeAgent( tools=[], model=HfApiModel(model_id = "Qwen/Qwen2.5-Coder-32B-Instruct"), managed_agents=[managed_web_agent], additional_authorized_imports=['pyparsing', 'matplotlib', 'datetime', 'statistics', 'bs4', 'request', 'unicodedata', 'queue', 'time', 'collections', 're', 'math', 'stat', 'random', 'itertools'], ) # Function to log agent actions def log_agent_action(prompt, result, agent_name): st.write(f"### Agent Activity ({agent_name}):") st.write("**Prompt Sent to Agent:**") st.code(prompt, language="text") st.write("**Agent Output:**") st.code(result, language="text") # Streamlit app title st.title("AI Tech Assistant Agent researching your query and summarizing it") # App description st.write("Generate reports enriched with real-time insights using the AI Tech Report Writing Agent powered by SmolAgents and DuckDuckGo.") # Input blog topic or prompt prompt = st.text_area("Enter the your search query:", placeholder="E.g., What is the optimal specs for my computer? I am running normal desktop programs. I want my computer to be fast and efficient. Storage is not so important. Please, don't let it be too expensive. Also, let me know where I can buy the computer in Sweden.") # Button to generate blog content if st.button("Generate Summary"): if prompt: with st.spinner("Generating content..."): try: # Run the blog agent with the given prompt result = manager_agent.run(prompt) # Display the generated blog content st.subheader("Generated Summary:") st.write(result) # Log backend activity log_agent_action(prompt, result, "Tech Research Agent with DuckDuckGo") except Exception as e: st.error(f"An error occurred: {e}") else: st.warning("Please enter a blog topic or prompt to proceed.") # Footer st.markdown("---") st.caption("Powered by SmolAgents, DuckDuckGo, and Streamlit")