Knowledge configuration throwing error missing 2 required keyword-only arguments: 'response' and 'body' . Using azure openai and azure embedding-ada-2

Hi,
I’m using Azure OpenAI and Azure text-embedding-ada-2 models.
Below is the code

import os;
from crewai import Agent, Task, Crew, Process, LLM
from crewai.knowledge.source.string_knowledge_source import StringKnowledgeSource

Create a knowledge source

string_source = StringKnowledgeSource(
content=“Users name is John. He is 30 years old and lives in San Francisco.”
)

os.environ[‘AZURE_OPENAI_API_KEY’] =“azure_open_ai_key”
os.environ[‘AZURE_OPENAI_ENDPOINT’] =“azure open ai endpoint”
os.environ[‘AZURE_API_VERSION’] = “2024-08-01-preview”

Create an LLM with a temperature of 0 to ensure deterministic outputs

llm = LLM(
model=“azure/gpt-4o-mini”,
api_key=‘azure_open_ai_key’,
base_url=‘aisprdoai.openai.azure.com/’,
api_version=‘2024-08-01-preview’
)

embedder={
“provider”: “azure”,
“config”: {
“api_key”: “azure_open_ai_key”,
“api_base”: “aisprdoai.openai.azure.com”,
“api_version”: “2023-05-15”,
“model_name”: “aisprdoai-embedding-ada-2”
}
}

Create an agent with the knowledge store

agent = Agent(
role=“About User”,
goal=“You know everything about the user and provide the information from source only.”,
backstory=“”“You are a master at understanding people and their preferences.”“”,
verbose=True,
allow_delegation=False,
llm=llm,
knowledge_sources=[string_source],
embedder=embedder
)
task = Task(
description=“Answer the following questions about the user: {question}”,
expected_output=“An answer to the question.”,
agent=agent,
verbose=True
)

crew = Crew(
agents=[agent],
tasks=[task],
verbose=True,
process=Process.sequential,
)

result = crew.kickoff(inputs={“question”: “Who is john and how old is he?”})

when i run this getting below error.
File “C:\Users\xxxxx\latest_ai_development\src\latest_ai_development\knowledge1base.py”, line 54, in
agent = Agent(
File “C:\Users\xxxx\anaconda3\envs\crewai-env\lib\site-packages\pydantic\main.py”, line 214, in init
validated_self = self.pydantic_validator.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for Agent
Value error, Invalid Knowledge Configuration: APIStatusError.init() missing 2 required keyword-only arguments: ‘response’ and ‘body’ [type=value_error, input_value={‘role’: ‘About User’, ‘g…evai-embedding-ada-2’}}}, input_type=dict]
For further information visit errors.pydantic.dev/2.10/v/value_error

I have the same issue. Does anyone have any idea how to address this issue?

I’m facing the same issue. Does anyone have an idea on how to solve this?

crewai tools doesn’t work with third party llms, I’ve tried to get it to work a lot and never succeeded. The workaround is to use ChatOpenAI which acts as a wrapper around your llm to expose it as a open ai llm to the tool, but this also doesnt work well as the tool needs openai models to work.

knowledge is like a tool in crewai which is heavily dependent on open ai llms, so if you can get an api key directly, It will work

As with any problem (whether it’s a cake recipe or building a supersonic jet), let’s start with a small enough example to make understanding and troubleshooting easier, just like this code here in the CrewAI documentation.

But before the code, a few points, @Suneel_Kumar:

  • In your embedder["config"], where it says model_name, I believe it should be model.
  • In your embedder["config"], where it says api_base, I believe it should be base_url.
  • Considering Azure’s documentation, your AZURE_API_BASE env variable should have the full format https://<SOMETHING-HERE>.openai.azure.com/.

For the small example below, I used OpenRouter as the provider, Qwen as the LLM, and Google as the embedder, to evaluate if “crewai is heavily dependent on open ai llms.” I ran it (version 0.105.0) and everything went very well. So, I suggest you first adapt this functional example, ensure it’s not a configuration error, and if the error persists, provide the complete error message so someone can effectively help.

First things first, make sure to have a clean knowledge db:

$ crewai reset-memories --knowledge

Hope the code helps:

from crewai import Agent, Task, Crew, Process, LLM
from crewai.knowledge.source.string_knowledge_source import StringKnowledgeSource
import os

from crewai.utilities.paths import db_storage_path
from pathlib import Path

print(
    '! Knowledge Source location is: '
    f'{str(Path(db_storage_path()) / "knowledge")}'
)

# My env:
os.environ["OPENROUTER_API_KEY"] = ""
os.environ["GEMINI_API_KEY"] = ""
# Your env:
os.environ["AZURE_API_KEY"] = ""  # "your-azure-api-key"
os.environ["AZURE_API_BASE"] = ""  # "https://example-endpoint.openai.azure.com"
os.environ["AZURE_API_VERSION"] = ""  # "2029-01-01"

content = "Users name is John. He is 108 years old and lives in Alabama."
string_source = StringKnowledgeSource(
    content=content,
)

openrouter_llm = LLM(
    model='openrouter/qwen/qwq-32b:free',
    api_key=os.environ["OPENROUTER_API_KEY"],
    temperature=0
)

google_embedder = {
    "provider": "google",
    "config": {
        "model": "models/text-embedding-004",
        "api_key": os.environ["GEMINI_API_KEY"]
    }
}

agent = Agent(
    role="About User",
    goal="You know everything about the user.",
    backstory="You are a master at understanding people and their preferences.",
    verbose=True,
    allow_delegation=False,
    llm=openrouter_llm
)

task = Task(
    description="Answer the following questions about the user: {question}",
    expected_output="An answer to the question.",
    agent=agent,
)

crew = Crew(
    agents=[agent],
    tasks=[task],
    verbose=True,
    process=Process.sequential,
    knowledge_sources=[string_source],
    embedder=google_embedder
)

result = crew.kickoff(
    inputs={
        "question": "Where does John live and how old is he?"
    }
)