Team Ai
Apppublic

mathidot111/First_agent_template

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
app.py90 linesDownload Raw Back to root
1from smolagents import CodeAgent, HfApiModel, load_tool, tool, LiteLLMModel2import os3import datetime4import pytz5import yaml6from dotenv import load_dotenv7from tools.final_answer import FinalAnswerTool8from tools.query_knowledge import QueryKnowledgeTool9from tools.web_search import DuckDuckGoSearchTool10from tools.visit_webpage import VisitWebpageTool11from market_data.tools import (12    calculate_option_greeks,13    query_market_asset,14    query_option_chain,15    query_option_expirations,16    query_price_history,17    query_realized_volatility,18    query_volatility_snapshot,19)20from strategy.tools import build_volatility_strategy21from backtest.tools import analyze_strategy_payoff, backtest_long_straddle_csv, backtest_volatility_signal22from optimizer.tools import optimize_volatility_signal_parameters23from Gradio_UI import GradioUI24 25@tool26def get_current_time_in_timezone(timezone: str) -> str:27    """A tool that fetches the current local time in a specified timezone.28    Args:29        timezone: A string representing a valid timezone (e.g., 'America/New_York').30    """31    try:32        # Create timezone object33        tz = pytz.timezone(timezone)34        # Get current time in that timezone35        local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")36        return f"The current local time in {timezone} is: {local_time}"37    except Exception as e:38        return f"Error fetching time for timezone '{timezone}': {str(e)}"39 40 41if __name__ == "__main__":42    final_answer = FinalAnswerTool()43    query_knowledge = QueryKnowledgeTool()44    web_search = DuckDuckGoSearchTool(max_results=6)45    visit_webpage = VisitWebpageTool()46    load_dotenv()47    hf_token = os.getenv("HF_TOKEN")48    gemini_api_key = os.getenv("GEMINI_API_KEY");49    50    model = LiteLLMModel(51        model_id="gemini/gemini-2.5-flash",52        temperature=0.253    )54    55    with open("prompts.yaml", 'r') as stream:56        prompt_templates = yaml.safe_load(stream)57        58    agent = CodeAgent(59        model=model,60        tools=[61            query_market_asset,62            query_price_history,63            query_realized_volatility,64            query_option_expirations,65            query_option_chain,66            query_volatility_snapshot,67            calculate_option_greeks,68            build_volatility_strategy,69            analyze_strategy_payoff,70            backtest_long_straddle_csv,71            backtest_volatility_signal,72            optimize_volatility_signal_parameters,73            get_current_time_in_timezone,74            query_knowledge,75            web_search,76            visit_webpage,77            final_answer,78        ],79        max_steps=6,80        verbosity_level=1,81        grammar=None,82        planning_interval=None,83        name=None,84        description=None,85        prompt_templates=prompt_templates86    )87    88    89    GradioUI(agent).launch()90