Skip to content

Python: AzureAIAgent Thread Creation #11816

Closed
@mjnong

Description

@mjnong

I stumbled upon this issue that the AzureAIAgent is not able to create a thread I do not know why this is the case and I hope to get come help and clarification with why

[2025-04-30 13:38:53 - azure.core.pipeline.policies.http_logging_policy:508 - INFO] Request URL: 
Request method: 'POST'
Request headers:
    'Content-Type': 'application/json'
    'Content-Length': '16'
    'Accept': 'application/json'
    'x-ms-client-request-id': 'b1a18ce2-25b7-11f0-92dc-7601bfc81d6b'
    'User-Agent': 'semantic-kernel-python/1.28.1 azsdk-python-ai-projects/1.0.0b10 Python/3.13.2 (macOS-14.6.1-arm64-arm-64bit-Mach-O)'
    'Authorization': 'REDACTED'
A body is sent with the request
[2025-04-30 13:38:53 - semantic_kernel.functions.kernel_function:48 - ERROR] Function failed. Error: The thread could not be created due to an error response from the service.
[2025-04-30 13:38:53 - semantic_kernel.kernel:427 - ERROR] Error invoking function SeatAgent-SeatAgent: The thread could not be created due to an error response from the service..
Traceback (most recent call last):
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/semantic_kernel/agents/azure_ai/azure_ai_agent.py", line 106, in _create
    response = await self._client.agents.create_thread(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
    )
    ^
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/azure/core/tracing/decorator_async.py", line 119, in wrapper_use_tracer
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/azure/ai/projects/aio/operations/_operations.py", line 981, in create_thread
    pipeline_response: PipelineResponse = await self._client._pipeline.run(  # pylint: disable=protected-access
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        _request, stream=_stream, **kwargs
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/azure/core/pipeline/_base_async.py", line 229, in run
    return await first_node.send(pipeline_request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/azure/core/pipeline/_base_async.py", line 77, in send
    response = await self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/azure/core/pipeline/_base_async.py", line 77, in send
    response = await self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/azure/core/pipeline/_base_async.py", line 77, in send
    response = await self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  [Previous line repeated 2 more times]
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/azure/core/pipeline/policies/_redirect_async.py", line 76, in send
    response = await self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/azure/core/pipeline/policies/_retry_async.py", line 178, in send
    response = await self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/azure/core/pipeline/policies/_authentication_async.py", line 104, in send
    response = await self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/azure/core/pipeline/_base_async.py", line 77, in send
    response = await self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/azure/core/pipeline/_base_async.py", line 77, in send
    response = await self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/azure/core/pipeline/_base_async.py", line 77, in send
    response = await self.next.send(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  [Previous line repeated 2 more times]
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/azure/core/pipeline/_base_async.py", line 111, in send
    await self._sender.send(request.http_request, **request.context.options),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/azure/core/pipeline/transport/_aiohttp.py", line 270, in send
    await self.open()
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/azure/core/pipeline/transport/_aiohttp.py", line 134, in open
    raise ValueError(
    ...<3 lines>...
    )
ValueError: HTTP transport has already been closed. You may check if you're calling a function outside of the `async with` of your client creation, or if you called `await close()` on your client already.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/semantic_kernel/kernel.py", line 423, in _inner_auto_function_invoke_handler
    result = await context.function.invoke(context.kernel, context.arguments)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/semantic_kernel/functions/kernel_function.py", line 258, in invoke
    raise e
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/semantic_kernel/functions/kernel_function.py", line 250, in invoke
    await stack(function_context)
  File "/Users/marcus.jonathan/multi-agent-mcp/cli.py", line 72, in function_invocation_filter
    await next(context)
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/semantic_kernel/functions/kernel_function_from_method.py", line 107, in _invoke_internal
    result = await result
             ^^^^^^^^^^^^
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/semantic_kernel/agents/agent.py", line 226, in _as_kernel_function
    response_item = await self.get_response(
                    ^^^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
    )
    ^
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/semantic_kernel/utils/telemetry/agent_diagnostics/decorators.py", line 69, in wrapper_decorator
    return await get_response_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/semantic_kernel/agents/azure_ai/azure_ai_agent.py", line 320, in get_response
    thread = await self._ensure_thread_exists_with_messages(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
    )
    ^
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/semantic_kernel/agents/agent.py", line 414, in _ensure_thread_exists_with_messages
    await thread.create()
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/semantic_kernel/agents/agent.py", line 63, in create
    self._id = await self._create()
               ^^^^^^^^^^^^^^^^^^^^
  File "/Applications/ServBay/package/python/3.13/3.13.2/Python.framework/Versions/3.13/lib/python3.13/site-packages/semantic_kernel/agents/azure_ai/azure_ai_agent.py", line 112, in _create
    raise AgentThreadOperationException(
        "The thread could not be created due to an error response from the service."
    ) from ex
semantic_kernel.exceptions.agent_exceptions.AgentThreadOperationException: The thread could not be created due to an error response from the service.

Metadata

Metadata

Assignees

Labels

agentspythonPull requests for the Python Semantic Kernel

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions