import os from langchain import hub from langchain.agents import initialize_agent, AgentType, Tool from langchain_community.llms import HuggingFaceHub from langchain_community.tools import DuckDuckGoSearchResults from langchain_experimental.tools import PythonREPLTool from huggingface_hub import login # Lade dein Hugging Face Token (falls benötigt) from huggingface_hub import login # login(token="your-huggingface-token-here") # Optional, falls dein Space das braucht # LLM: Mistral-7B-Instruct über Hugging Face Inference API llm = HuggingFaceHub( repo_id="mistralai/Mistral-7B-Instruct-v0.2", model_kwargs={"temperature": 0.2, "max_new_tokens": 512} ) # Tools definieren search_tool = DuckDuckGoSearchResults() python_tool = PythonREPLTool() tools = [ Tool( name="Search", func=search_tool.run, description="Useful for when you need to answer questions about current events or look up information online." ), Tool( name="Python_REPL", func=python_tool.run, description="Useful for math, calculations, or running simple python code." ), ] # Agent initialisieren agent_executor = initialize_agent( tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True, handle_parsing_errors=True, )