Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-2025-04-14· OpenAIHugging Face LMArena Human Preference 140K

I try to use crewAI with a local ollama instance running I manage to run my crew. The…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Amazon Novaamazon.nova-pro-v1:0’s answer.
  1. User

    I try to use crewAI with a local ollama instance running

    I manage to run my crew. The first agent starts, want to read a file, the file is read by the file_reader tool, then the llm fails :

    Traceback (most recent call last): response = base_llm_http_handler.completion( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ data = provider_config.transform_request( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ modified_prompt = ollama_pt(model=model, messages=messages) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tool_calls = messages[msg_i].get("tool_calls") ~~~~~~~~^^^^^^^ IndexError: list index out of range

  2. Assistant

    Great job getting CrewAI running with a local Ollama instance! The error you're seeing:

    IndexError: list index out of range
    tool_calls = messages[msg_i].get("tool_calls")
    

    suggests that the code is trying to access a message in the messages list that doesn't exist—likely because the list is empty or msg_i is out of bounds.

    Why does this happen?

    This is a common issue when integrating LLM frameworks (like CrewAI) with local LLM providers (like Ollama), especially when using tools or function-calling features. The root causes are usually:

    1. Unexpected message format: The messages list passed to Ollama is empty or not structured as expected.
    2. Mismatch in function-calling expectations: CrewAI expects the LLM to return tool calls in a certain way, but Ollama's response format may differ.
    3. Bug in the integration layer: The code that adapts CrewAI's prompt/messages to Ollama's API may have a bug.

    How to Fix

    1. Check the messages list before accessing

    If you have access to the code, add a check before accessing messages[msg_i]:

    if msg_i < len(messages):
        tool_calls = messages[msg_i].get("tool_calls")
    else:
        tool_calls = None
    

    2. Debug the messages content

    Add a print/log statement before the error line to see what messages contains:

    print("MESSAGES:", messages)
    print("MSG_I:", msg_i)
    

    This will help you see if the list is empty or if msg_i is out of range.

    3. Check your CrewAI and Ollama versions

    • Make sure you are using the latest versions of both CrewAI and Ollama.
    • Some earlier versions of CrewAI had issues with function-calling and tool integration with local LLMs.

    4. Check your LLM model

    • Not all Ollama models support function-calling or tool use. Try using llama3, phi3, or another model known to support function-calling.
    • If your model doesn't support function-calling, CrewAI may still try to use it, leading to errors.

    5. Update your CrewAI LLM config

    If you are using a custom LLM integration, make sure your code handles empty or missing tool calls gracefully.


    Example: Patch for CrewAI Ollama Integration

    If you are using a custom provider, you might need to patch the code like this:

    def ollama_pt(model, messages):
        # ... your code ...
        msg_i = ... # however you determine the index
        if msg_i < len(messages):
            tool_calls = messages[msg_i].get("tool_calls")
        else:
            tool_calls = None
        # ... rest of your code ...
    

    TL;DR

    • The error is because messages[msg_i] is out of range.
    • Add a check to ensure msg_i is within the bounds of messages.
    • Make sure your LLM and CrewAI versions are up to date.
    • Ensure your Ollama model supports the features you need.

    If you can share your CrewAI config and the code for your LLM provider, I can give you a more specific fix!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.