Skip to content

Conversation

@danuw
Copy link

@danuw danuw commented Jul 16, 2025

Purpose

Fix issue with version in the main branch that results in issues with Pydantic
image

As a result this PR changed the following:

  • Updated semantic-kernel from 0.9.8b1 → 1.35.0
  • Fixed FunctionCallBehavior → FunctionChoiceBehavior
  • Fixed import paths and method signatures
  • Corrected SessionsPythonTool constructor parameters
  • Resolved Pydantic compatibility issues

Does this introduce a breaking change?

Not sure what to say as it acts broken for me, so a "fixing changes" type of update

[ ] Yes
[x] No

Pull Request Type

What kind of change does this Pull Request introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Documentation content changes
[ ] Other... Please describe:

How to Test

To test, follow the tutorial instructions at https://learn.microsoft.com/en-gb/azure/container-apps/sessions-tutorial-semantic-kernel

What to Check

Verify that the following are valid

  • ...

Other Information

I use Python 3.11.9

I ran

fastapi dev main.py

and got the following trace

Details ``` FastAPI Starting development server 🚀
         Searching for package file structure from directories with __init__.py files

ERROR Import error: cannot import name 'Url' from 'pydantic.networks'
(C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi.venv\Lib\site-packages\pydantic\network
s.py)
WARNING Ensure all the package directories have an init.py file

╭────────────────────────────────────────────────────────────────── Traceback (most recent call last) ───────────────────────────────────────────────────────────────────╮
│ C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi.venv\Lib\site-packages\fastapi_cli\cli.py:255 │
│ in dev │
│ │
│ 252 │ ╭──────────────── locals ────────────────╮ │
│ 253 │ Otherwise, it uses the first [bold]FastAPI[/bold] app found in the imported module o │ app = None │ │
│ 254 │ """ │ host = '127.0.0.1' │ │
│ ❱ 255 │ _run( │ path = WindowsPath('main.py') │ │
│ 256 │ │ path=path, │ port = 8000 │ │
│ 257 │ │ host=host, │ proxy_headers = True │ │
│ 258 │ │ port=port, │ reload = True │ │
│ │ root_path = '' │ │
│ ╰────────────────────────────────────────╯ │
│ │
│ C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi.venv\Lib\site-packages\fastapi_cli\cli.py:111 │
│ in run │
│ │
│ 108 │ │ ) │
│ 109 │ │ │
│ 110 │ │ try: │
│ ❱ 111 │ │ │ import_data = get_import_data(path=path, app_name=app) │
│ 112 │ │ except FastAPICLIException as e: │
│ 113 │ │ │ toolkit.print_line() │
│ 114 │ │ │ toolkit.print(f"[error]{e}") │
│ │
│ ╭──────────────────────────────────── locals ─────────────────────────────────────╮ │
│ │ app = None │ │
│ │ command = 'dev' │ │
│ │ host = '127.0.0.1' │ │
│ │ path = WindowsPath('main.py') │ │
│ │ port = 8000 │ │
│ │ proxy_headers = True │ │
│ │ reload = True │ │
│ │ root_path = '' │ │
│ │ server_type = 'development' │ │
│ │ toolkit = <rich_toolkit.toolkit.RichToolkit object at 0x000001FB39585290> │ │
│ │ workers = None │ │
│ ╰─────────────────────────────────────────────────────────────────────────────────╯ │
│ │
│ C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi.venv\Lib\site-packages\fastapi_cli\discover.p │
│ y:126 in get_import_data │
│ │
│ 123 │ │ raise FastAPICLIException(f"Path does not exist {path}") │
│ 124 │ mod_data = get_module_data_from_path(path) │
│ 125 │ sys.path.insert(0, str(mod_data.extra_sys_path)) │
│ ❱ 126 │ use_app_name = get_app_name(mod_data=mod_data, app_name=app_name) │
│ 127 │ │
│ 128 │ import_string = f"{mod_data.module_import_str}:{use_app_name}" │
│ 129 │
│ │
│ ╭────────────────────────────────────────────────────────────────────────────── locals ──────────────────────────────────────────────────────────────────────────────╮ │
│ │ app_name = None │ │
│ │ mod_data = ModuleData( │ │
│ │ │ module_import_str='main', │ │
│ │ │ │ │
│ │ extra_sys_path=WindowsPath('C:/repos/proj/code_interpreter-tests/container-apps-dynamic-sessions-samples/semantic-kernel-python-webapi'), │ │
│ │ │ module_paths=[ │ │
│ │ │ │ WindowsPath('C:/repos/proj/code_interpreter-tests/container-apps-dynamic-sessions-samples/semantic-kernel-python-webapi/main.py') │ │
│ │ │ ] │ │
│ │ ) │ │
│ │ path = WindowsPath('main.py') │ │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ │
│ C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi.venv\Lib\site-packages\fastapi_cli\discover.p │
│ y:70 in get_app_name │
│ │
│ 67 │
│ 68 def get_app_name(*, mod_data: ModuleData, app_name: Union[str, None] = None) -> str: │
│ 69 │ try: │
│ ❱ 70 │ │ mod = importlib.import_module(mod_data.module_import_str) │
│ 71 │ except (ImportError, ValueError) as e: │
│ 72 │ │ logger.error(f"Import error: {e}") │
│ 73 │ │ logger.warning( │
│ │
│ ╭────────────────────────────────────────────────────────────────────────────── locals ──────────────────────────────────────────────────────────────────────────────╮ │
│ │ app_name = None │ │
│ │ mod_data = ModuleData( │ │
│ │ │ module_import_str='main', │ │
│ │ │ │ │
│ │ extra_sys_path=WindowsPath('C:/repos/proj/code_interpreter-tests/container-apps-dynamic-sessions-samples/semantic-kernel-python-webapi'), │ │
│ │ │ module_paths=[ │ │
│ │ │ │ WindowsPath('C:/repos/proj/code_interpreter-tests/container-apps-dynamic-sessions-samples/semantic-kernel-python-webapi/main.py') │ │
│ │ │ ] │ │
│ │ ) │ │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ │
│ C:\Program Files\Python311\Lib\importlib_init
.py:126 in import_module │
│ │
│ 123 │ │ │ if character != '.': ╭───── locals ─────╮ │
│ 124 │ │ │ │ break │ level = 0 │ │
│ 125 │ │ │ level += 1 │ name = 'main' │ │
│ ❱ 126 │ return _bootstrap._gcd_import(name[level:], package, level) │ package = None │ │
│ 127 ╰──────────────────╯ │
│ 128 │
│ 129 _RELOADING = {} │
│ in _gcd_import:1204 │
│ ╭───── locals ─────╮ │
│ │ level = 0 │ │
│ │ name = 'main' │ │
│ │ package = None │ │
│ ╰──────────────────╯ │
│ in _find_and_load:1176 │
│ ╭──────────────────── locals ────────────────────╮ │
│ │ module = <object object at 0x000001FB35684050> │ │
│ │ name = 'main' │ │
│ ╰────────────────────────────────────────────────╯ │
│ in _find_and_load_unlocked:1147 │
│ ╭────────────────────────────────────────────────────────────────────────────── locals ──────────────────────────────────────────────────────────────────────────────╮ │
│ │ name = 'main' │ │
│ │ parent = '' │ │
│ │ parent_spec = None │ │
│ │ path = None │ │
│ │ spec = ModuleSpec(name='main', loader=<_frozen_importlib_external.SourceFileLoader object at 0x000001FB39587110>, │ │
│ │ origin='C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi\main.py') │ │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ in _load_unlocked:690 │
│ ╭────────────────────────────────────────────────────────────────────────────── locals ──────────────────────────────────────────────────────────────────────────────╮ │
│ │ module = <module 'main' from │ │
│ │ 'C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi\main.py'> │ │
│ │ spec = ModuleSpec(name='main', loader=<_frozen_importlib_external.SourceFileLoader object at 0x000001FB39587110>, │ │
│ │ origin='C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi\main.py') │ │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ in exec_module:940 │
│ ╭────────────────────────────────────────────────────────────────────────────── locals ──────────────────────────────────────────────────────────────────────────────╮ │
│ │ code = <code object at 0x000001FB38BCFB40, file │ │
│ │ "C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi\main.py", line 1> │ │
│ │ module = <module 'main' from │ │
│ │ 'C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi\main.py'> │ │
│ │ self = <_frozen_importlib_external.SourceFileLoader object at 0x000001FB39587110> │ │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ in _call_with_frames_removed:241 │
│ ╭────────────────────────────────────────────────────────────────────────────── locals ──────────────────────────────────────────────────────────────────────────────╮ │
│ │ args = ( │ │
│ │ │ <code object at 0x000001FB38BCFB40, file │ │
│ │ "C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi\main.py", line 1>, │ │
│ │ │ { │ │
│ │ │ │ 'name': 'main', │ │
│ │ │ │ 'doc': None, │ │
│ │ │ │ 'package': '', │ │
│ │ │ │ 'loader': <_frozen_importlib_external.SourceFileLoader object at 0x000001FB39587110>, │ │
│ │ │ │ 'spec': ModuleSpec(name='main', loader=<_frozen_importlib_external.SourceFileLoader object at 0x000001FB39587110>, │ │
│ │ origin='C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi\main.py'), │ │
│ │ │ │ 'file': 'C:\repos\proj\code_interpreter-tests\container-apps-dynamic-session'+47, │ │
│ │ │ │ 'cached': 'C:\repos\proj\code_interpreter-tests\container-apps-dynamic-session'+72, │ │
│ │ │ │ 'builtins': { │ │
│ │ │ │ │ 'name': 'builtins', │ │
│ │ │ │ │ 'doc': 'Built-in functions, types, exceptions, and other objects.\n\nThis module provides '+346, │ │
│ │ │ │ │ 'package': '', │ │
│ │ │ │ │ 'loader': <class '_frozen_importlib.BuiltinImporter'>, │ │
│ │ │ │ │ 'spec': ModuleSpec(name='builtins', loader=<class '_frozen_importlib.BuiltinImporter'>, origin='built-in'), │ │
│ │ │ │ │ 'build_class': , │ │
│ │ │ │ │ 'import': , │ │
│ │ │ │ │ 'abs': , │ │
│ │ │ │ │ 'all': , │ │
│ │ │ │ │ 'any': , │ │
│ │ │ │ │ ... +148 │ │
│ │ │ │ }, │ │
│ │ │ │ 'datetime': <module 'datetime' from 'C:\Program Files\Python311\Lib\datetime.py'>, │ │
│ │ │ │ 'os': <module 'os' (frozen)>, │ │
│ │ │ │ ... +5 │ │
│ │ │ } │ │
│ │ ) │ │
│ │ f = │ │
│ │ kwds = {} │ │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ │
│ C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi\main.py:9 in │
│ │
│ 6 from azure.identity import DefaultAzureCredential │
│ 7 from fastapi import FastAPI │
│ 8 from fastapi.responses import RedirectResponse │
│ ❱ 9 from semantic_kernel import Kernel │
│ 10 from semantic_kernel.connectors.ai.function_call_behavior import \ │
│ 11 │ FunctionCallBehavior │
│ 12 from semantic_kernel.connectors.ai.open_ai.prompt_execution_settings.azure_chat_prompt_e │
│ │
│ ╭────────────────────────────────────────────────────────────────────────────── locals ──────────────────────────────────────────────────────────────────────────────╮ │
│ │ datetime = <module 'datetime' from 'C:\Program Files\Python311\Lib\datetime.py'> │ │
│ │ dotenv = <module 'dotenv' from │ │
│ │ 'C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi\.venv\Lib\site-packag… │ │
│ │ os = <module 'os' (frozen)> │ │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ │
│ C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi.venv\Lib\site-packages\semantic_kernel__init │
│ __.py:3 in │
│ │
│ 1 # Copyright (c) Microsoft. All rights reserved. │
│ 2 │
│ ❱ 3 from semantic_kernel.kernel import Kernel │
│ 4 │
│ 5 all = ["Kernel"] │
│ 6 │
│ │
│ ╭────────────────────────────────────────────────────────────────────────────── locals ──────────────────────────────────────────────────────────────────────────────╮ │
│ │ connectors = <module 'semantic_kernel.connectors' from │ │
│ │ 'C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi\.venv\Lib\site-pack… │ │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ │
│ C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi.venv\Lib\site-packages\semantic_kernel\kernel │
│ .py:11 in │
│ │
│ 8 │
│ 9 from pydantic import Field, field_validator │
│ 10 │
│ ❱ 11 from semantic_kernel.connectors.ai.prompt_execution_settings import PromptExecutionSetti │
│ 12 from semantic_kernel.contents.streaming_content_mixin import StreamingContentMixin │
│ 13 from semantic_kernel.events import FunctionInvokedEventArgs, FunctionInvokingEventArgs │
│ 14 from semantic_kernel.exceptions import ( │
│ │
│ ╭────────────────────────────────────────────── locals ──────────────────────────────────────────────╮ │
│ │ annotations = Feature((3, 7, 0, 'beta', 1), None, 16777216) │ │
│ │ AsyncGenerator = typing.AsyncGenerator │ │
│ │ AsyncIterable = typing.AsyncIterable │ │
│ │ Callable = typing.Callable │ │
│ │ Literal = typing.Literal │ │
│ │ logging = <module 'logging' from 'C:\Program Files\Python311\Lib\logging\init.py'> │ │
│ │ Type = typing.Type │ │
│ │ TYPE_CHECKING = False │ │
│ │ Union = typing.Union │ │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ │
│ C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi.venv\Lib\site-packages\semantic_kernel\connec │
│ tors\ai_init
.py:3 in │
│ │
│ 1 # Copyright (c) Microsoft. All rights reserved. │
│ 2 │
│ ❱ 3 from semantic_kernel.connectors.ai.prompt_execution_settings import PromptExecutionSetti │
│ 4 │
│ 5 all = ["PromptExecutionSettings"] │
│ 6 │
│ │
│ C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi.venv\Lib\site-packages\semantic_kernel\connec │
│ tors\ai\prompt_execution_settings.py:8 in │
│ │
│ 5 ╭─────────────────────────── locals ───────────────────────────╮ │
│ 6 from pydantic import Field │ annotations = _Feature((3, 7, 0, 'beta', 1), None, 16777216) │ │
│ 7 ╰──────────────────────────────────────────────────────────────╯ │
│ ❱ 8 from semantic_kernel.kernel_pydantic import KernelBaseModel │
│ 9 │
│ 10 │
│ 11 class PromptExecutionSettings(KernelBaseModel): │
│ │
│ C:\repos\proj\code_interpreter-tests\container-apps-dynamic-sessions-samples\semantic-kernel-python-webapi.venv\Lib\site-packages\semantic_kernel\kernel │
│ _pydantic.py:9 in │
│ │
│ 6 │ from typing_extensions import Annotated ╭──────────── locals ─────────────╮ │
│ 7 │ sys = <module 'sys' (built-in)> │ │
│ 8 from pydantic import BaseModel, ConfigDict, UrlConstraints ╰─────────────────────────────────╯ │
│ ❱ 9 from pydantic.networks import Url │
│ 10 │
│ 11 HttpsUrl = Annotated[Url, UrlConstraints(max_length=2083, allowed_schemes=["https"])] │
│ 12 │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
ImportError: cannot import name 'Url' from 'pydantic.networks'

</details>

danuw added 2 commits July 16, 2025 13:54
Update function choice behaviour and requirements;
Update function choice behaviour and requirements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant