Unable to connect to LLM. Please help!

Hi,
I am tryin to create simple agent for testing out crewai. I tried Together API, local LLM using LMStudio as well. I am getting below error:

Agent: AI Assistant

Task: Answer the following question: Which is bigger, 9 or 10?

:rocket: Crew: crew
โ””โ”€โ”€ :clipboard: Task: 36bd5b41-7b78-47b0-afe3-c4608e68514d
Status: Executing Taskโ€ฆ
โ””โ”€โ”€ :cross_mark: LLM Failed

An unknown error occurred. Please check the details below.

:rocket: Crew: crew
โ””โ”€โ”€ :clipboard: Task: 36bd5b41-7b78-47b0-afe3-c4608e68514d
Assigned to: AI Assistant
Status: :cross_mark: Failed
โ””โ”€โ”€ :cross_mark: LLM Failed
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Task Failure โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ โ”‚
โ”‚ Task Failed โ”‚
โ”‚ Name: 36bd5b41-7b78-47b0-afe3-c4608e68514d โ”‚
โ”‚ Agent: AI Assistant โ”‚
โ”‚ โ”‚
โ”‚ โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Crew Failure โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ โ”‚
โ”‚ Crew Execution Failed โ”‚
โ”‚ Name: crew โ”‚
โ”‚ ID: b891d8b6-2232-464e-b7a0-6099fa709099 โ”‚
โ”‚ โ”‚
โ”‚

The code:
from crewai import Agent, Task, Crew
from langchain_together import Together
import lmstudio as lms
from dotenv import load_dotenv
import os

Load environment variables

load_dotenv()

def create_simple_agent():
โ€œโ€โ€œCreate a simple CrewAI agent using Together AIโ€โ€œโ€

# # Get API key from environment
# api_key = os.getenv("TOGETHER_API_KEY")
# if not api_key:
#     print("โŒ Error: TOGETHER_API_KEY not found in .env file")
#     return None

# print(f"โœ… API key found: {api_key[:20]}...")

# # Initialize Together AI LLM via LangChain
# try:
#     model_name = os.getenv("TOGETHER_MODEL", "meta-llama/Llama-3.1-8B-Instruct")
#     llm = Together(
#         model=model_name,
#         temperature=0.7,
#         api_key=api_key,
#         max_tokens=2048
#     )
#     print(f"โœ… LLM initialized with model: {model_name}")
# except Exception as e:
#     print(f"โŒ Error initializing LLM: {e}")
#     return None


llm = lms.llm("google/gemma-3-12b")

print(f"โœ… LLM initialized with model: {llm}")

# Create a simple assistant agent
assistant = Agent(
    role='AI Assistant',
    goal='Provide helpful, accurate, and informative responses to user questions',
    backstory="""You are a knowledgeable AI assistant with expertise in various fields. 
    You provide clear, well-structured answers and are always helpful and friendly.""",
    verbose=True,
    allow_delegation=False,
    llm=llm
)

print("โœ… Agent created.")
return assistant

def ask_question(agent, question):
โ€œโ€โ€œAsk a question to the agentโ€โ€œโ€

# Create a task for the question
task = Task(
    description=f"Answer the following question: {question}",
    agent=agent,
    expected_output="A clear, helpful, and informative answer to the user's question."
)

# Create a crew with just this agent and task
crew = Crew(
    agents=[agent],
    tasks=[task],
    verbose=True
)

# Execute the crew
print(f"\n๐Ÿค– Agent is thinking about: {question}")
print("=" * 50)

try:
    result = crew.kickoff()
    print(f"โœ… Got Response: {result}")
    return result
except Exception as e:
    print(f"โŒ Error during execution: {e}")
    print("โŒ Didn't get a response from the agent")
    return None

def interactive_chat():
โ€œโ€โ€œInteractive chat with the AI agentโ€โ€œโ€

print("๐Ÿค– Simple CrewAI Agent with Together AI")
print("=" * 50)

# Create the agent
agent = create_simple_agent()
if not agent:
    return

print("\n๐Ÿ’ฌ You can now chat with the AI agent!")
print("Type 'quit' or 'exit' to end the conversation")
print("-" * 50)

while True:
    # Get user input
    question = input("\nโ“ Your question: ").strip()
    
    # Check for exit command
    if question.lower() in ['quit', 'exit', 'bye']:
        print("๐Ÿ‘‹ Goodbye! Thanks for chatting!")
        break
    
    # Skip empty questions
    if not question:
        print("Please enter a question.")
        continue
    
    # Get response from agent
    response = ask_question(agent, question)
    
    if response:
        print(f"\n๐Ÿค– Agent's response:")
        print("-" * 30)
        print(response)
        print("-" * 30)
    else:
        print("โŒ Sorry, I couldn't process your question. Please try again.")

if name == โ€œmainโ€:
interactive_chat()