Skip to content

mlflow.openai.autolog() raises 'NotGiven' object is not iterable when tracing with Ollama + Agents SDK #680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dauvannam1804 opened this issue May 12, 2025 · 1 comment
Labels
question Question about using the SDK

Comments

@dauvannam1804
Copy link

Please read this first

Question

I'm trying out tracing following the example in the MLflow OpenAI Agent integration guide, using a local Ollama model.

After following the suggestion in this issue, the previous error

Tracing client error 401: {
  "error": {
    "message": "Incorrect API key provided: AIzaSyAe***************************o4jk.",
    ...
}

is gone. However, I now encounter this new warning and error:

2025/05/12 11:39:52 WARNING mlflow.openai._openai_autolog: Encountered unexpected error when ending trace: 'NotGiven' object is not iterable
Traceback (most recent call last):
  File ".../mlflow/openai/_openai_autolog.py", line 352, in _end_span_on_success
    set_span_chat_attributes(span, inputs, result)
  File ".../mlflow/openai/utils/chat_schema.py", line 46, in set_span_chat_attributes
    if tools := _parse_tools(inputs):
  File ".../mlflow/openai/utils/chat_schema.py", line 261, in _parse_tools
    for tool in tools:
TypeError: 'NotGiven' object is not iterable

My setup:

import asyncio

import mlflow
from agents import Agent, OpenAIChatCompletionsModel, Runner
from agents.model_settings import ModelSettings
from openai import AsyncOpenAI
from agents import set_default_openai_client, set_tracing_disabled, set_trace_processors


external_client = AsyncOpenAI(
    base_url="http://localhost:11434/v1",
    api_key="ollama",  # required, but unused
)

# Enable auto tracing for OpenAI Agents SDK
mlflow.openai.autolog()

# Optional: Set a tracking URI and an experiment
mlflow.set_tracking_uri("http://localhost:8080")
mlflow.set_experiment("OpenAI Agent")
set_trace_processors([])

# Define a simple multi-agent workflow
vietnamese_agent = Agent(
    name="Vietnamese agent",
    instructions="You only speak Vietnamese.",
    model=OpenAIChatCompletionsModel(
        model="qwen3:0.6b",
        openai_client=external_client,
    ),
)

english_agent = Agent(
    name="English agent",
    instructions="You only speak English",
    model=OpenAIChatCompletionsModel(
        model="qwen3:0.6b",
        openai_client=external_client,
    ),
)

triage_agent = Agent(
    name="Triage agent",
    instructions="Handoff to the appropriate agent based on the language of the request.",
    handoffs=[vietnamese_agent, english_agent],
    model=OpenAIChatCompletionsModel(
        model="qwen3:0.6b",
        openai_client=external_client,
    ),
)


async def main():
    result = await Runner.run(triage_agent, input="Xin chào, bạn có khỏe không?")
    print(result.final_output)


# If you are running this code in a Jupyter notebook, replace this with `await main()`.
if __name__ == "__main__":
    asyncio.run(main())

Output

python tracing_example.py 
INFO:httpx:HTTP Request: POST http://localhost:11434/v1/chat/completions "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST http://localhost:11434/v1/chat/completions "HTTP/1.1 200 OK"
2025/05/12 11:39:52 WARNING mlflow.openai._openai_autolog: Encountered unexpected error when ending trace: 'NotGiven' object is not iterable
Traceback (most recent call last):
  File "/home/namdv/anaconda3/envs/chatbot/lib/python3.10/site-packages/mlflow/openai/_openai_autolog.py", line 352, in _end_span_on_success
    set_span_chat_attributes(span, inputs, result)
  File "/home/namdv/anaconda3/envs/chatbot/lib/python3.10/site-packages/mlflow/openai/utils/chat_schema.py", line 46, in set_span_chat_attributes
    if tools := _parse_tools(inputs):
  File "/home/namdv/anaconda3/envs/chatbot/lib/python3.10/site-packages/mlflow/openai/utils/chat_schema.py", line 261, in _parse_tools
    for tool in tools:
TypeError: 'NotGiven' object is not iterable
<think>
Okay, the user sent a greeting in Vietnamese. I need to respond in Vietnamese. Let me check the previous messages again. The user asked, "Xin chào, bạn có khỏe không?" which translates to "Hello, are you healthy?" in Vietnamese. My role is to keep Vietnamese. So, I should respond in Vietnamese as well. Make sure the answer is polite and friendly. Maybe say something like "Hello! Are you healthy?" and offer a response. Keep it simple.
</think>

Xin chào! Bạn có khỏe không? 😊

Questions:

  1. How can I avoid this 'NotGiven' object is not iterable error when using mlflow.openai.autolog() with Ollama backend?
  2. Is there a better way to handle tracing (or disable it cleanly) when using non-OpenAI models?
  3. Is there any documentation or example code on implementing and registering custom tracing processors?

Thanks in advance!

@dauvannam1804 dauvannam1804 added the question Question about using the SDK label May 12, 2025
@pakrym-oai
Copy link
Contributor

Hi, mflow GitHub might be better equipped to help you with this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question about using the SDK
Projects
None yet
Development

No branches or pull requests

3 participants