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?
Crew: crew
โโโ Task: 36bd5b41-7b78-47b0-afe3-c4608e68514d
Status: Executing Taskโฆ
โโโ LLM Failed
An unknown error occurred. Please check the details below.
Crew: crew
โโโ Task: 36bd5b41-7b78-47b0-afe3-c4608e68514d
Assigned to: AI Assistant
Status: Failed
โโโ 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()