Skip to content

Python: [Bug]: agent_framework version: 1.0.0rc1 fails at import #4235

@abhijat01

Description

@abhijat01

Description

agent framework fails at import.

I have included pyproject.toml and a script to create the environment here.

[project]
name = "env-test"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
    "agent-framework>=1.0.0rc1",
]

And a create-env.sh

#!/bin/bash

# Script to create virtual environment and install dependencies for the project

set -e

echo "Creating virtual environment with Python 3.12..."
uv venv --python 3.12

echo "Installing dependencies..."
uv sync --prerelease allow

echo ""
echo "Virtual environment created successfully!"
echo "To activate the environment, run: source .venv/bin/activate"

Code Sample

import agent_framework as af

def main():
    print("Hello from env-test!")
    print(f"agent_framework version: {af.__version__}")
    print("agent_framework imported successfully!")


if __name__ == "__main__":
    main()

Error Messages / Stack Traces

Traceback (most recent call last):
  File "/home/abhijat/tmp/env-test/main.py", line 5, in <module>
    import agent_framework as af
  File "/home/abhijat/tmp/env-test/.venv/lib/python3.12/site-packages/agent_framework/__init__.py", line 20, in <module>
    from ._agents import Agent, BaseAgent, RawAgent, SupportsAgentRun
  File "/home/abhijat/tmp/env-test/.venv/lib/python3.12/site-packages/agent_framework/_agents.py", line 32, in <module>
    from ._clients import BaseChatClient, SupportsChatGetResponse
  File "/home/abhijat/tmp/env-test/.venv/lib/python3.12/site-packages/agent_framework/_clients.py", line 31, in <module>
    from ._tools import (
  File "/home/abhijat/tmp/env-test/.venv/lib/python3.12/site-packages/agent_framework/_tools.py", line 40, in <module>
    from .observability import (
  File "/home/abhijat/tmp/env-test/.venv/lib/python3.12/site-packages/agent_framework/observability.py", line 1542, in <module>
    "system_name": (SpanAttributes.LLM_SYSTEM, None, False, None),
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'SpanAttributes' has no attribute 'LLM_SYSTEM'

Package Versions

agent_framework version: 1.0.0rc1

Python Version

3.12.11

Additional Context

The following code runs

# Import the patch BEFORE importing agent_framework
import patch_agent_framework

# Now import agent_framework
import agent_framework as af


def main():
    print("Hello from env-test!")
    print(f"agent_framework version: {af.__version__}")
    print("agent_framework imported successfully!")


if __name__ == "__main__":
    main()

patch_agent_framework.py

"""Temporary workaround for agent-framework OpenTelemetry compatibility issues.

This patches missing LLM attributes in the OpenTelemetry SpanAttributes class
before agent_framework is imported.
"""

# Import the SpanAttributes from opentelemetry.semconv_ai
from opentelemetry.semconv_ai import SpanAttributes

# Add missing attributes that agent-framework expects
if not hasattr(SpanAttributes, 'LLM_SYSTEM'):
    SpanAttributes.LLM_SYSTEM = "gen_ai.system"

if not hasattr(SpanAttributes, 'LLM_REQUEST_MODEL'):
    SpanAttributes.LLM_REQUEST_MODEL = "gen_ai.request.model"

if not hasattr(SpanAttributes, 'LLM_REQUEST_MAX_TOKENS'):
    SpanAttributes.LLM_REQUEST_MAX_TOKENS = "gen_ai.request.max_tokens"

if not hasattr(SpanAttributes, 'LLM_REQUEST_TEMPERATURE'):
    SpanAttributes.LLM_REQUEST_TEMPERATURE = "gen_ai.request.temperature"

if not hasattr(SpanAttributes, 'LLM_REQUEST_TOP_P'):
    SpanAttributes.LLM_REQUEST_TOP_P = "gen_ai.request.top_p"

if not hasattr(SpanAttributes, 'LLM_RESPONSE_ID'):
    SpanAttributes.LLM_RESPONSE_ID = "gen_ai.response.id"

if not hasattr(SpanAttributes, 'LLM_RESPONSE_MODEL'):
    SpanAttributes.LLM_RESPONSE_MODEL = "gen_ai.response.model"

if not hasattr(SpanAttributes, 'LLM_USAGE_COMPLETION_TOKENS'):
    SpanAttributes.LLM_USAGE_COMPLETION_TOKENS = "gen_ai.usage.completion_tokens"

if not hasattr(SpanAttributes, 'LLM_USAGE_PROMPT_TOKENS'):
    SpanAttributes.LLM_USAGE_PROMPT_TOKENS = "gen_ai.usage.prompt_tokens"

print("Applied agent-framework OpenTelemetry compatibility patch")

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingobservabilityIssues related to observability or telemetrypythonv1.0Features being tracked for the version 1.0 GA

Type

No fields configured for Bug.

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions