Intent routing failure

Hi all,

I’m failing at my first try, just intent routing, pretty basic code:

import crewai
import textwrap
import os
from langchain_litellm.chat_models import ChatLiteLLM
router_agent = crewai.Agent(
    role='Intent routing specialist',
    goal='Identify whether the user wants to debug code, write code, or configure a system.',
    backstory=textwrap.dedent('''
        You are a master orchestrator responsible for understanding user input
        and selecting the correct workflow. You do not perform the task, you
        only classify the intent.
    '''),
    llm=ChatLiteLLM(model=os.getenv('MODEL')),
    verbose=True,
    memory=False,
)
router_task = crewai.Task(
    description=textwrap.dedent('''
        Analyze the user query and determine which workflow it should trigger.
        If the query involves fixing or analyzing code issues → output 'debug'.
        If it asks for editing code → output 'code'.
        If it involves environment setup, configuration, or credentials → output 'configure'.
        Your final answer MUST be exactly one of these lowercase words: debug, code, configure.
    '''),
    expected_output="A single lowercase word: debug, code, or configure.",
    agent=router_agent,
)
router_crew = crewai.Crew(
    agents=[router_agent],
    tasks=[router_task],
    process=crewai.Process.sequential
)
result = router_crew.kickoff(inputs={'user_query': 'rewrite proc.py so that it also collects stdout and sterr in order into a new output variable'})
assert result == 'code'

No matter what LLM I use, I always get debug as result.
Any clue please?

@jpic have you tried using ChatOpenAI instead of ChatLiteLLM?

from langchain_openai import ChatOpenAI

and then use it in your llm parameters for your agents

llm=ChatOpenAI(model=os.getenv('MODEL', 'gpt-3.5-turbo'))

You may want to use output_json=IntentClassification in your router_task as well to as a more reliable output parsing.

I would also update your import statement at the beginning
from crewai import Agent, Crew, Task, Process

let me know how it goes!